diff --git a/typed-racket-lib/typed-racket/optimizer/float-complex.rkt b/typed-racket-lib/typed-racket/optimizer/float-complex.rkt index 74bdd5b5..c5d06437 100644 --- a/typed-racket-lib/typed-racket/optimizer/float-complex.rkt +++ b/typed-racket-lib/typed-racket/optimizer/float-complex.rkt @@ -132,6 +132,21 @@ #,(mark-as-real res-imag)) ; this case implies real (values (/ #,first-non-float #,second-non-float) 0.0)]] + [second-non-float + ;; may be dividing by exact 0, be conservative to preserve error + ;; (res-real can't be non-float, since we've hit a float, so we either + ;; error or coerce) + #`[(#,res-real #,(if both-real? + (mark-as-real res-imag) + res-imag)) + ;; TODO could optimize computation of `res-div` when one or the other is real + (let-values ([(res-div) + (/ (make-rectangular #,a + #,(if first-arg-real? #'0 b)) + (make-rectangular #,second-non-float + #,(if second-arg-real? #'0 d)))]) + (values (real-part res-div) + (imag-part res-div)))]] [both-real? #`[(#,res-real #,(mark-as-real res-imag)) (values (unsafe-fl/ #,a #,c) diff --git a/typed-racket-test/fail/div-0-complex2.rkt b/typed-racket-test/fail/div-0-complex2.rkt new file mode 100644 index 00000000..92bf5bef --- /dev/null +++ b/typed-racket-test/fail/div-0-complex2.rkt @@ -0,0 +1,6 @@ +#; +(exn-pred "division by zero") +#lang typed/racket + +;; float-complex opts should not make div-by-0 errors go away +(* (/ 1.0+1.0i (ann 0 Integer) (ann 0 Integer)) -4.880003479031522e-08)