Fix magnitude on numbers with negative components.

Closes PR 15183.
This commit is contained in:
Vincent St-Amour 2015-11-23 14:04:25 -06:00
parent f9825cb250
commit fe4808f96a
2 changed files with 8 additions and 3 deletions

View File

@ -569,8 +569,10 @@
(log-unboxing-opt "unboxed unary float complex")
#`(let*-values (c.bindings ...)
;; reuses the algorithm used by the Racket runtime
(let-values ([(q) (unsafe-fl/ c.real-binding c.imag-binding)])
(unsafe-fl* c.imag-binding
(let*-values ([(r) (unsafe-flabs c.real-binding)]
[(i) (unsafe-flabs c.imag-binding)]
[(q) (unsafe-fl/ r i)])
(unsafe-fl* i
(unsafe-flsqrt (unsafe-fl+ 1.0
(unsafe-fl* q q))))))])))

View File

@ -95,7 +95,10 @@
(good-opt (- 0+0i 0.0+0.0i))
;; Conjugate should correctly compute sign of 0.0
(good-opt (conjugate 0.0+0.0i))))
(good-opt (conjugate 0.0+0.0i))
;; Magnitude should always return positive results
(good-opt (magnitude -1.0-2i))))
(module+ main
(require rackunit/text-ui)