File: r2bs.scm

package info (click to toggle)
mit-scheme 12.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208,300 kB
  • sloc: lisp: 781,881; xml: 425,435; ansic: 86,059; sh: 10,135; makefile: 2,501; asm: 2,121; csh: 1,143
file content (17 lines) | stat: -rw-r--r-- 562 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
(define (real->bit-string x)
  ;; Allocate a 64-bit result to hold the double-precision number.
  (let ((result (bit-string-allocate 64)))
    (read-bits!
     ;; Guarantee that the number is floating-point.
     (exact->inexact x)
     ;; Skip over the non-marked vector header (32 bits).
     32
     result)
    result))

(define (bit-string->flonum bs)
  ;; Allocate a flonum that we can clobber.
  ;; The call to `random' prevents the compiler from constant folding.
  (let ((flonum (exact->inexact (random 1))))
    (write-bits! flonum 32 bs)
    flonum))