diff --git a/typed-racket-lib/typed-racket/optimizer/float-complex.rkt b/typed-racket-lib/typed-racket/optimizer/float-complex.rkt index 0f4093b9..697e629d 100644 --- a/typed-racket-lib/typed-racket/optimizer/float-complex.rkt +++ b/typed-racket-lib/typed-racket/optimizer/float-complex.rkt @@ -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))))))]))) diff --git a/typed-racket-test/optimizer/known-bugs.rkt b/typed-racket-test/optimizer/known-bugs.rkt index c04bdbf8..3181f49a 100644 --- a/typed-racket-test/optimizer/known-bugs.rkt +++ b/typed-racket-test/optimizer/known-bugs.rkt @@ -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)