Skip to content

Commit 75ef5da

Browse files
committed
Faster flonum operations using flbit-field
1 parent 12550f8 commit 75ef5da

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

math-lib/math/private/flonum/flonum-bits.rkt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212

1313
(: flonum->bit-field (Flonum -> Natural))
1414
(define (flonum->bit-field x)
15-
(assert (integer-bytes->integer (real->floating-point-bytes x (ann 8 8)) #f)
16-
exact-nonnegative-integer?))
15+
(flbit-field x 0 64))
1716

1817
(: bit-field->flonum (Integer -> Flonum))
1918
(define (bit-field->flonum i)
@@ -30,10 +29,9 @@
3029

3130
(: flonum->fields (Flonum -> (Values (U 0 1) Index Natural)))
3231
(define (flonum->fields x)
33-
(define n (flonum->bit-field x))
34-
(values (if (zero? (bitwise-bit-field n 63 64)) 0 1)
35-
(assert (bitwise-bit-field n 52 63) index?)
36-
(bitwise-bit-field n 0 52)))
32+
(values (if (zero? (flbit-field n 63 64)) 0 1)
33+
(assert (flbit-field n 52 63) index?)
34+
(flbit-field n 0 52)))
3735

3836
(: fields->flonum (Integer Integer Integer -> Flonum))
3937
(define (fields->flonum s e m)
@@ -66,8 +64,8 @@
6664

6765
(: flonum->ordinal (Flonum -> Integer))
6866
(define (flonum->ordinal x)
69-
(cond [(x . fl< . 0.0) (- (flonum->bit-field (fl- 0.0 x)))]
70-
[else (flonum->bit-field (flabs x))])) ; abs for -0.0
67+
(cond [(x . fl< . 0.0) (- (flbit-field (fl- 0.0 x) 0 64))]
68+
[else (flbit-field (flabs x) 0 64)])) ; abs for -0.0
7169

7270
(: ordinal->flonum (Integer -> Flonum))
7371
(define (ordinal->flonum i)

0 commit comments

Comments
 (0)