Use flo:hypot to compute inexact magnitudes with edge caess.
authorTaylor R Campbell <campbell@mumble.net>
Tue, 20 Nov 2018 09:18:03 +0000 (09:18 +0000)
committerTaylor R Campbell <campbell@mumble.net>
Tue, 20 Nov 2018 09:18:03 +0000 (09:18 +0000)
Maybe not the best way but it'll do for now.

src/runtime/arith.scm
tests/runtime/test-arith.scm

index 9e0071659664981e31fcd294dad5bb214f79775b..ae39d37e1baae9e70f5fa1f51f23145689c63951 100644 (file)
@@ -1934,11 +1934,15 @@ USA.
   (if (recnum? z)
       (let ((ar (real:abs (rec:real-part z)))
            (ai (real:abs (rec:imag-part z))))
-       (let ((v (real:max ar ai))
-             (w (real:min ar ai)))
-         (if (real:zero? v)
-             v
-             (real:* v (real:sqrt (real:1+ (real:square (real:/ w v))))))))
+       (if (and (real:exact? ar)
+                (real:exact? ai))
+           (let ((v (real:max ar ai))
+                 (w (real:min ar ai)))
+             (if (real:zero? v)
+                 v
+                 (real:* v
+                         (real:sqrt (real:1+ (real:square (real:/ w v)))))))
+           (flo:hypot (real:->inexact ar) (real:->inexact ai))))
       (real:abs z)))
 
 (define (complex:sqrt z)
index d18e254f011ef2c46daeddc47a3f7cb94b9d67fe..0bce9039e6b48b3e6bf5e960e54232414cdb3f3c 100644 (file)
@@ -764,12 +764,7 @@ USA.
    -inf.0-inf.0i
    -inf.0+inf.0i)
   (lambda (z)
-    (with-expected-failure
-        (and (infinite? (real-part z))
-             (infinite? (imag-part z))
-             'xfail)
-      (lambda ()
-        (assert-inf+ (magnitude z))))))
+    (assert-inf+ (magnitude z))))
 
 (define-enumerated-test 'infinite-angle
   (vector