tanh: single flonum result for range of arguments

Fix the case for > 1.29f-08 and <= 0.549f0.

Closes #2736
This commit is contained in:
Matthew Flatt 2019-07-17 20:20:31 -06:00
parent cec813fef6
commit 91cdc06c91
2 changed files with 6 additions and 2 deletions

View File

@ -340,7 +340,11 @@
(test 0.0f0 tanh 0.0f0)
(test #t single=? tanh+1 (tanh 1.0f0))
(test 1.0f0 tanh 20.0f0)
(test 1.0f0 tanh +inf.f))
(test 1.0f0 tanh +inf.f)
(test #t single-flonum? (tanh -0.11100646f0))
(test #t single-flonum? (tanh 0.11100646f0))
(test #t single-flonum? (tanh 0.61100646f0))
(test #t single-flonum? (tanh 20.61100646f0)))
(test +nan.0 tanh +nan.0)
(test -1.0 tanh -inf.0)

View File

@ -85,7 +85,7 @@
(define R
(/ (* g (+ (* (+ (* p2 g) p1) g) p0))
(+ (* (+ (* (+ g q2) g) q1) g) q0)))
(+ z (* z R))]
(+ z (* z (if (single-flonum? z) (real->single-flonum R) R)))]
[(z . < . 19.06154746539849600897D+00) (- 1 (/ 2 (+ 1 (exp (* 2 z)))))]
[(z . >= . 19.06154746539849600897D+00) (if (single-flonum? z) (real->single-flonum 1.0) 1.0)]
[else z]))] ; +nan.0 or +nan.f