Skip to content

Commit 4ba2a36

Browse files
committed
Provide typed version fxpopcount functions
1 parent a01eb21 commit 4ba2a36

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,13 @@
420420
(-> -NonPosInt -Int -NonPosFixnum)
421421
(binop -Int -Fixnum))))
422422

423+
(define fxpopcount-type
424+
(lambda ()
425+
(fx-from-cases
426+
(-Nat . -> . -NonNegFixnum)
427+
(-NonNegFixnum . -> . -NonNegFixnum)
428+
(-Int . -> . -Fixnum))))
429+
423430
;; A bit of machinery to allow floating point operations to be abstracted over double/extended
424431
;; floating point types without repetition.
425432
(define-syntax (define-fl-type-lambda stx)
@@ -1946,6 +1953,10 @@
19461953
[fxlshift (fxlshift-type)]
19471954
[fxrshift (fxrshift-type)]
19481955

1956+
[fxpopcount (fxpopcount-type)]
1957+
[fxpopcount16 (fxpopcount-type)]
1958+
[fxpopcount32 (fxpopcount-type)]
1959+
19491960
[fx= (fx=-type)]
19501961
[fx< (fx<-type)]
19511962
[fx> (fx>-type)]

typed-racket-test/succeed/fixnum.rkt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@
3838
(check equal? (fxmin 3 2) 2)
3939
(check equal? (fxmax 3 4) 4)
4040

41+
(check equal? (fxpopcount #x0fffffffffffffff) 60)
42+
(check equal? (fxpopcount32 #xffffffff) 32)
43+
(check equal? (fxpopcount16 #xffff) 16)

0 commit comments

Comments
 (0)