--- /dev/null
+Bug fix: Multiplying by purely imaginary numbers preserves zero sign.
+
+- (* +i (make-rectangular x y)) = (make-rectangular (* -1 y) x)
+- (* (make-rectangular x y) +i) = (make-rectangular (* -1 y) x)
+- (/ (make-rectangular x y) -i) = (make-rectangular (* -1 y) x)
+- (* -1 (make-rectangular x y)) = (make-rectangular y (* -1 x))
+- (* (make-rectangular x y) -i) = (make-rectangular y (* -1 x))
+- (/ (make-rectangular x y) +i) = (make-rectangular y (* -1 x))
(z2r (rec:real-part z2))
(z2i (rec:imag-part z2)))
(complex:%make-rectangular
- (real:- (real:* z1r z2r) (real:* z1i z2i))
- (real:+ (real:* z1r z2i) (real:* z1i z2r))))
+ (if (or (real:exact0= z1r) (real:exact0= z2r))
+ (real:negate (real:* z1i z2i))
+ (real:- (real:* z1r z2r) (real:* z1i z2i)))
+ (cond ((real:exact0= z1r) (real:* z1i z2r))
+ ((real:exact0= z2r) (real:* z1r z2i))
+ (else (real:+ (real:* z1r z2i) (real:* z1i z2r))))))
(complex:%make-rectangular (real:* (rec:real-part z1) z2)
(real:* (rec:imag-part z1) z2)))
(if (recnum? z2)
(z1i (rec:imag-part z1))
(z2r (rec:real-part z2))
(z2i (rec:imag-part z2)))
- (let ((d (real:+ (real:square z2r) (real:square z2i))))
- (complex:%make-rectangular
- (real:/ (real:+ (real:* z1r z2r) (real:* z1i z2i)) d)
- (real:/ (real:- (real:* z1i z2r) (real:* z1r z2i)) d))))
+ (let ((d (real:+ (real:square z2r) (real:square z2i)))
+ (u
+ (if (or (real:exact0= z1r) (real:exact0= z2r))
+ (real:* z1i z2i)
+ (real:+ (real:* z1r z2r) (real:* z1i z2i))))
+ (v
+ (if (real:exact0= z2r)
+ (real:negate (real:* z1r z2i))
+ (real:- (real:* z1i z2r) (real:* z1r z2i)))))
+ (complex:%make-rectangular (real:/ u d) (real:/ v d))))
(make-recnum (real:/ (rec:real-part z1) z2)
(real:/ (rec:imag-part z1) z2)))
(if (recnum? z2)
(list 3+4i -4+3i)
(list +0. +0.i)
(list -0. -0.i)
- (list +0.i -0. expect-failure)
+ (list +0.i -0.)
(list -0.i +0.)
- (list +0.+0.i -0.+0.i expect-failure)
- (list -0.+0.i -0.-0.i expect-failure)
+ (list +0.+0.i -0.+0.i)
+ (list -0.+0.i -0.-0.i)
(list +0.-0.i +0.+0.i)
- (list -0.-0.i +0.-0.i expect-failure))
+ (list -0.-0.i +0.-0.i))
(lambda (z w #!optional xfail)
(with-expected-failure xfail (lambda () (assert-eqv (* +i z) w)))
(with-expected-failure xfail (lambda () (assert-eqv (* z +i) w)))
(list +0. -0.i)
(list -0. +0.i)
(list +0.i +0.)
- (list -0.i -0. expect-failure)
- (list +0.+0.i +0.-0.i expect-failure)
+ (list -0.i -0.)
+ (list +0.+0.i +0.-0.i)
(list -0.+0.i +0.+0.i)
- (list +0.-0.i -0.-0.i expect-failure)
- (list -0.-0.i -0.+0.i expect-failure))
+ (list +0.-0.i -0.-0.i)
+ (list -0.-0.i -0.+0.i))
(lambda (z w #!optional xfail)
(with-expected-failure xfail (lambda () (assert-eqv (/ z +i) w)))
(with-expected-failure xfail (lambda () (assert-eqv (* -i z) w)))