Added nan?, infinite?, degrees->radians, radians->degrees, exact-round, exact-floor, exact-ceiling, exact-truncate to racket/math

Altered TR's random arithmetic testing to generate single-flonums and very small flonums; fails now because of erroneous types

Fixes to sgn, sinh, cosh, and tanh:
 * preserve single-flonum-ness
 * correct zero sign (-0.0) for negative return values that are smaller than epsilon
 * correct behavior with NaN and infinite inputs

original commit: a713ca8a8b6c7aed987e80d0621484e68bc3c6f5
This commit is contained in:
Neil Toronto 2012-06-05 22:40:44 -06:00
parent a93d6734ac
commit 2588094087
2 changed files with 29 additions and 3 deletions

View File

@ -3,7 +3,7 @@
;; Random testing of type preservation for floats.
(require redex
racket/flonum racket/unsafe/ops
racket/flonum racket/unsafe/ops unstable/flonum
racket/sandbox)
(require (except-in typed-racket/utils/utils infer)
@ -18,6 +18,8 @@
(b:init) (n:init)
(define-namespace-anchor anch)
todo: exact numbers
(define-language tr-arith ; to stay within floats, removed some numeric ops
[n real]
[E n
@ -99,10 +101,33 @@
(define subtype? (subtype type-after type-before))
subtype?)
(define (random-integer->random-float E)
(define r (random))
(cond
;; probability 1/4: noisify and convert to single flonum
[(r . < . 0.25)
(real->single-flonum (* (random) E))]
;; probability 1/4: noisify and convert to double flonum
[(r . < . 0.5)
(real->double-flonum (* (random) E))]
;; probability 1/4: convert to very small double flonum
[(r . < . 0.75)
(define x (ordinal->flonum E))
(cond [(= x 0.0) (if ((random) . < . 0.5) 0.0 -0.0)]
[else x])]
;; probability 1/20: +nan.0
[(r . < . 0.8)
+nan.0]
;; remaining probability: convert to very large double flonum
[else
(if ((random) . < . 0.5)
(flstep -inf.0 E)
(flstep +inf.0 (- E)))]))
;; Redex can't generate floats, so we convert ints to floats.
(define (exp->float-exp E) ; numbers or symbols or lists
(cond [(number? E)
(exact->inexact (* (random) E))] ; add noise
(random-integer->random-float E)]
[(list? E)
(map exp->float-exp E)]
[else

View File

@ -1808,7 +1808,8 @@
(-NegRat . -> . -NegFixnum) ; -1
(-NonPosRat . -> . -NonPosFixnum) ; 0 or -1
(-Rat . -> . -Fixnum)
(-InexactReal . -> . -Flonum) ; single-flonums give a flonum result
(-Flonum . -> . -Flonum)
(-SingleFlonum . -> . -SingleFlonum)
(-Real . -> . -Real))]
[pi -PosFlonum]