55 lines
1.8 KiB
Scheme
55 lines
1.8 KiB
Scheme
|
|
(library (tests bignum-to-flonum)
|
|
(export test-bignum-to-flonum)
|
|
(import (ikarus) (tests framework))
|
|
(define (t x s)
|
|
(let ([fl (format "~a" (exact->inexact x))])
|
|
(unless (string=? s fl)
|
|
(error 'bignum->flonum
|
|
"incorrect result for ~s\n expected ~a, \n got ~a" x s fl))))
|
|
(define-syntax test*
|
|
(syntax-rules ()
|
|
[(_ name [num str] ...)
|
|
(define-tests name
|
|
[(lambda (x) (string=? str (number->string x))) (exact->inexact num)]
|
|
...)]))
|
|
(test* test-bignum-to-flonum
|
|
(1000000000 "1e9")
|
|
(2000000000 "2e9")
|
|
(4000000000 "4e9")
|
|
(-1000000000 "-1e9")
|
|
(-2000000000 "-2e9")
|
|
(-4000000000 "-4e9")
|
|
( 6000000000 "6e9")
|
|
(12000000000 "1.2e10")
|
|
(25000000000 "2.5e10")
|
|
(50000000000 "5e10")
|
|
(-6000000000 "-6e9")
|
|
(-12000000000 "-1.2e10")
|
|
(-25000000000 "-2.5e10")
|
|
(-50000000000 "-5e10")
|
|
(100000000000 "1e11")
|
|
(200000000000 "2e11")
|
|
(400000000000 "4e11")
|
|
(800000000000 "8e11")
|
|
(-100000000000 "-1e11")
|
|
(-200000000000 "-2e11")
|
|
(-400000000000 "-4e11")
|
|
(-800000000000 "-8e11")
|
|
(#x1FFFFFFFFFFFFF "9.007199254740991e15")
|
|
(#x3FFFFFFFFFFFFF "1.8014398509481984e16")
|
|
(#x7FFFFFFFFFFFFF "3.602879701896397e16")
|
|
(#xFFFFFFFFFFFFFF "7.205759403792794e16")
|
|
(#x1FFFFFFFFFFFFFF "1.4411518807585587e17")
|
|
(#x3FFFFFFFFFFFFFF "2.8823037615171174e17")
|
|
(#x7FFFFFFFFFFFFFF "5.764607523034235e17")
|
|
(#xFFFFFFFFFFFFFFF "1.152921504606847e18")
|
|
(#xFFFFFFFFFFFFFFFF "1.8446744073709552e19")
|
|
(1000000000000000000000 "1e21")
|
|
(100000000000000000000000000000 "1e29")
|
|
(100000000000000000000000000000000000000000000000 "1e47")
|
|
(-1000000000000000000000 "-1e21")
|
|
(-100000000000000000000000000000 "-1e29")
|
|
(-100000000000000000000000000000000000000000000000 "-1e47")))
|
|
|