diff --git a/pkgs/racket-test-core/tests/racket/math.rktl b/pkgs/racket-test-core/tests/racket/math.rktl index 85e1bf459e..b196ac02f3 100644 --- a/pkgs/racket-test-core/tests/racket/math.rktl +++ b/pkgs/racket-test-core/tests/racket/math.rktl @@ -279,10 +279,10 @@ (test -inf.0 sinh -inf.0) (test -inf.0 sinh -max.0) (test #t double=? sinh-1 (sinh -1.0)) -(test -0.0 sinh -min.0) +(test -min.0 sinh -min.0) (test -0.0 sinh -0.0) (test 0.0 sinh 0.0) -(test 0.0 sinh +min.0) +(test +min.0 sinh +min.0) (test #t double=? sinh+1 (sinh 1.0)) (test +inf.0 sinh +max.0) (test +inf.0 sinh +inf.0) diff --git a/racket/collects/racket/math.rkt b/racket/collects/racket/math.rkt index 50a0919ddc..12bfe5b8cd 100644 --- a/racket/collects/racket/math.rkt +++ b/racket/collects/racket/math.rkt @@ -58,6 +58,12 @@ [(real? z) (let loop ([z z]) (cond [(z . < . 0) (- (loop (- z)))] + [(< z 1e-8) (exact->inexact z)] + [(< z .13) + ;; Taylor expansion near 0 to avoid cancellation + ;~ z+z^3/3!+z^5/5!+... + (define z^2 (* z z)) + (+ z (* z z^2 (+ #i1/6 (* z^2 (+ #i1/120 (* z^2 (+ #i1/5040 (* z^2 #i1/362880))))))))] [else (/ (- (exp z) (exp (- z))) 2)]))] [else (/ (- (exp z) (exp (- z))) 2)]))