Skip to content

Commit

Permalink
Provide typed version fxpopcount functions
Browse files Browse the repository at this point in the history
  • Loading branch information
cocodery committed Jan 4, 2025
1 parent a01eb21 commit 4ba2a36
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions typed-racket-lib/typed-racket/base-env/base-env-numeric.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,13 @@
(-> -NonPosInt -Int -NonPosFixnum)
(binop -Int -Fixnum))))

(define fxpopcount-type
(lambda ()
(fx-from-cases
(-Nat . -> . -NonNegFixnum)
(-NonNegFixnum . -> . -NonNegFixnum)
(-Int . -> . -Fixnum))))

;; A bit of machinery to allow floating point operations to be abstracted over double/extended
;; floating point types without repetition.
(define-syntax (define-fl-type-lambda stx)
Expand Down Expand Up @@ -1946,6 +1953,10 @@
[fxlshift (fxlshift-type)]
[fxrshift (fxrshift-type)]

[fxpopcount (fxpopcount-type)]
[fxpopcount16 (fxpopcount-type)]
[fxpopcount32 (fxpopcount-type)]

[fx= (fx=-type)]
[fx< (fx<-type)]
[fx> (fx>-type)]
Expand Down
3 changes: 3 additions & 0 deletions typed-racket-test/succeed/fixnum.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@
(check equal? (fxmin 3 2) 2)
(check equal? (fxmax 3 4) 4)

(check equal? (fxpopcount #x0fffffffffffffff) 60)
(check equal? (fxpopcount32 #xffffffff) 32)
(check equal? (fxpopcount16 #xffff) 16)

0 comments on commit 4ba2a36

Please sign in to comment.