From: Taylor R Campbell Date: Sun, 18 Nov 2018 05:34:23 +0000 (+0000) Subject: Invent complex:log1m to get correct branch cut in atan on exact inputs. X-Git-Tag: mit-scheme-pucked-10.1.2~16^2~28 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=55872cd9d3f57c2a5df9518c34324b9adedb86b9;p=mit-scheme.git Invent complex:log1m to get correct branch cut in atan on exact inputs. Not going to export it for now without further thought, though. --- diff --git a/src/runtime/arith.scm b/src/runtime/arith.scm index ffbf8cb08..b0a0a690a 100644 --- a/src/runtime/arith.scm +++ b/src/runtime/arith.scm @@ -1750,6 +1750,11 @@ USA. (complex:log (complex:+ z 1)) ;XXX ((copy real:log1p) z))) +(define (complex:log1m z) + (if (and (real:real? z) (real:< 1 z)) + (make-recnum (real:log (real:- z 1)) (real:negate rec:pi)) + (complex:log1p (complex:negate z)))) + (define (complex:sin z) (if (recnum? z) (complex:/ (let ((iz (complex:+i* z))) @@ -1839,8 +1844,8 @@ USA. (define (rec:atan z) (complex:/ (let ((iz (complex:+i* z))) - (complex:- (complex:log (complex:1+ iz)) - (complex:log (complex:- 1 iz)))) + (complex:- (complex:log1p iz) + (complex:log1m iz))) +2i)) (define (complex:angle z) diff --git a/tests/runtime/test-arith.scm b/tests/runtime/test-arith.scm index 7ee2b6371..852f95617 100644 --- a/tests/runtime/test-arith.scm +++ b/tests/runtime/test-arith.scm @@ -483,7 +483,7 @@ USA. (vector +2i +1.5707963267948966+.5493061443340549i) (vector +0.+2i +1.5707963267948966+.5493061443340549i) (vector -0.+2i -1.5707963267948966+.5493061443340549i) - (vector -2i +1.5707963267948966-.5493061443340549i 'xfail) + (vector -2i +1.5707963267948966-.5493061443340549i) (vector +0.-2i +1.5707963267948966-.5493061443340549i) (vector -0.-2i -1.5707963267948966-.5493061443340549i)) (lambda (v)