From 1116287328fbcf21b78ffcfc80627213bc68184b Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Fri, 21 Jun 2019 12:33:20 -0600 Subject: [PATCH] adjust sqrt and log on -0.0 original commit: 098fdb7d197bda4cd1ecc9b68407ee72fcce9311 --- mats/5_3.ms | 4 ++++ mats/ieee.ms | 6 +++--- s/5_3.ss | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/mats/5_3.ms b/mats/5_3.ms index ca8d4b7a37..09325a2963 100644 --- a/mats/5_3.ms +++ b/mats/5_3.ms @@ -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)) diff --git a/mats/ieee.ms b/mats/ieee.ms index f623fdd5e0..b85a6f4ec7 100644 --- a/mats/ieee.ms +++ b/mats/ieee.ms @@ -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)) diff --git a/s/5_3.ss b/s/5_3.ss index a57b3f06f8..10a19b0ee5 100644 --- a/s/5_3.ss +++ b/s/5_3.ss @@ -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)]