adjust sqrt and log on -0.0

original commit: 098fdb7d197bda4cd1ecc9b68407ee72fcce9311
This commit is contained in:
Matthew Flatt 2019-06-21 12:33:20 -06:00
parent e11d9c846e
commit 1116287328
3 changed files with 9 additions and 5 deletions

View File

@ -2690,6 +2690,8 @@
(error? (sqrt 3 4))
(error? (sqrt 'a))
(= (sqrt -1.0) 0.0+1.0i)
(eqv? (sqrt -0.0) -0.0)
(== (sqrt +nan.0) +nan.0)
(eqv? (sqrt -1) +1i)
(= (sqrt 9) 3)
(= (sqrt 1/4) 1/2)
@ -2741,6 +2743,8 @@
(error? (log 0))
(= (log 1) 0)
(fl= (log 1.0) 0.0)
(eqv? (log 0.0) -inf.0)
(eqv? (log -0.0) -inf.0)
(~= (log (exp 7)) 7)
(fl~= (log (exp 10.2)) 10.2)
(cfl~= (log -1) (* pi +1.0i))

View File

@ -413,7 +413,7 @@
(mat sqrt
; from Kahan
(== (sqrt -0.0) +0.0+0.0i)
(== (sqrt -0.0) -0.0) ; the grounds that (negative? -0.0) => #f
(== (sqrt -4.0) +0.0+2.0i)
(== (sqrt -inf.0) +0.0+inf.0i)
(== (sqrt 0.0+inf.0i) +inf.0+inf.0i)
@ -505,7 +505,7 @@
(== (log 1.0) 0.0)
(== (log +inf.0) +inf.0)
(== (log -0.0) (make-rectangular -inf.0 +pi))
(== (log -0.0) -inf.0) ; on the grounds that (negative? -0.0) => #f
(== (log -1.0) (make-rectangular 0.0 +pi))
(== (log -inf.0) (make-rectangular +inf.0 +pi))
@ -528,7 +528,7 @@
(== (log 1.0) 0.0)
(== (log +inf.0) +inf.0)
(== (log -0.0) (make-rectangular -inf.0 +pi))
(== (log -0.0) -inf.0) ; on the grounds that (negative? -0.0) => #f
(== (log -1.0) (make-rectangular 0.0 +pi))
(== (log -inf.0) (make-rectangular +inf.0 +pi))

View File

@ -1324,7 +1324,7 @@
[(x)
(type-case x
[(flonum?)
(if (negated-flonum? x)
(if (fl< x 0.0)
(fl-make-rectangular ($fllog (fl- x)) pi)
($fllog x))]
[($inexactnum?) (cfllog x)]
@ -1527,7 +1527,7 @@
(lambda (x)
(type-case x
[(flonum?)
(if (and (negated-flonum? x) (not ($nan? x)))
(if (fl< x 0.0)
(fl-make-rectangular 0.0 ($flsqrt (flabs x)))
($flsqrt x))]
[($inexactnum?) (cflsqrt x)]