thin-provisioning-tools/functional-tests/fmt/mantissa.scm
Joe Thornber 3e5de399a7 [functional tests] Remove dependency on the ThunderChez library.
I've just moved the relevant code into the functional-tests dir.
2020-04-30 12:07:42 +01:00

21 lines
634 B
Scheme

;; Break a positive real number down to a normalized mantissa and
;; exponent. Default base=2, mant-size=52, exp-size=11 for IEEE doubles.
(define mantissa+exponent
(case-lambda
[(num) (mantissa+exponent num 2)]
[(num base) (mantissa+exponent num base 52)]
[(num base mant-size) (mantissa+exponent num base mant-size 11)]
[(num base mant-size exp-size)
(if (zero? num)
(list 0 0)
(let* ((bot (expt base mant-size))
(top (* base bot)))
(let lp ((n num) (e 0))
(cond
((>= n top) (lp (quotient n base) (+ e 1)))
((< n bot) (lp (* n base) (- e 1)))
(else (list n e))))))]))