From: Taylor R Campbell Date: Tue, 20 Aug 2019 03:03:25 +0000 (+0000) Subject: Fix edge cases in ANGLE. X-Git-Tag: mit-scheme-pucked-10.1.20~11^2~76 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=bc3fdd35061f263b53a43ce5959ff7bcd60c225d;p=mit-scheme.git Fix edge cases in ANGLE. --- diff --git a/src/relnotes/bug-anglezero b/src/relnotes/bug-anglezero new file mode 100644 index 000000000..b92270c03 --- /dev/null +++ b/src/relnotes/bug-anglezero @@ -0,0 +1 @@ +Bug fix: (angle z) now correctly handles edge cases with signed zero. diff --git a/src/runtime/arith.scm b/src/runtime/arith.scm index 42c616a17..2c0fb5187 100644 --- a/src/runtime/arith.scm +++ b/src/runtime/arith.scm @@ -1972,11 +1972,12 @@ USA. (define (complex:angle z) (cond ((recnum? z) - (if (and (real:zero? (rec:real-part z)) + (if (and (complex:exact? z) + (real:zero? (rec:real-part z)) (real:zero? (rec:imag-part z))) - (real:0 (complex:exact? z)) + 0 (real:atan2 (rec:imag-part z) (rec:real-part z)))) - ((real:negative? z) rec:pi) + ((real:sign-negative? z) rec:pi) (else (real:0 (real:exact? z))))) (define (complex:magnitude z) diff --git a/tests/runtime/test-arith.scm b/tests/runtime/test-arith.scm index 2af91e595..61bb26dd0 100644 --- a/tests/runtime/test-arith.scm +++ b/tests/runtime/test-arith.scm @@ -741,9 +741,9 @@ USA. (list 0 0) (list 0. 0.) (list +0.i 0.) - (list -0.i -0. expect-failure) + (list -0.i -0.) (list +0.+0.i 0.) - (list +0.-0.i -0. expect-failure) + (list +0.-0.i -0.) ;; angle(+inf +/- y i) = +/- 0 for finite y (list +inf.0 0.) ;XXX Why not exact, if imag-part is exact 0? (list +inf.0+0.i 0.) @@ -774,9 +774,9 @@ USA. (list -inf.0+i pi) (list -inf.0-i (- pi)) ;; angle(-0 +/- 0i) = +/- pi - (list -0. pi expect-failure) - (list -0.+0.i pi expect-failure) - (list -0.-0.i (- pi) expect-failure)) + (list -0. pi) + (list -0.+0.i pi) + (list -0.-0.i (- pi))) (lambda (z t #!optional xfail) (with-expected-failure xfail (lambda ()