Improve (sinh x) : x around 0 (#3473)
* sinh - Taylor expansion near 0 * fast path for |z| < 1e-8 in this case the second term is already to small to matter
This commit is contained in:
parent
07148a22a0
commit
8137798937
|
@ -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)
|
||||
|
|
|
@ -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)]))
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user