~ chicken-core (master) dfa57604046206605d8e3585a55a312f40f62942
commit dfa57604046206605d8e3585a55a312f40f62942
Author: felix <felix@call-with-current-continuation.org>
AuthorDate: Mon Sep 7 22:43:45 2026 +0200
Commit: Felix Winkelmann <felix.winkelmann@bevuta.com>
CommitDate: Wed Sep 9 13:45:43 2026 +0200
special case for complex/non-complex division
diff --git a/library.scm b/library.scm
index 9647b27f..09caa72b 100644
--- a/library.scm
+++ b/library.scm
@@ -2515,13 +2515,18 @@ EOF
(let ((g (%integer-gcd x y)))
(ratnum (%integer-quotient x g) (%integer-quotient y g))))
;; Compnum *must* be checked first
+ ((and (cplxnum? x) (not (cplxnum? y)))
+ (let* ((a (real-part x)) (b (imag-part x))
+ (xu (##sys#/-2 a y))
+ (yu (##sys#/-2 b y)))
+ (make-complex xu yu)))
((or (cplxnum? x) (cplxnum? y))
- (let* ((a (real-part x)) (b (imag-part x))
- (c (real-part y)) (d (imag-part y))
- (r (+ (* c c) (* d d)))
- (x (##sys#/-2 (+ (* a c) (* b d)) r))
- (y (##sys#/-2 (- (* b c) (* a d)) r)) )
- (make-complex x y) ))
+ (let* ((a (real-part x)) (b (imag-part x))
+ (c (real-part y)) (d (imag-part y))
+ (r (+ (* c c) (* d d)))
+ (x (##sys#/-2 (+ (* a c) (* b d)) r))
+ (y (##sys#/-2 (- (* b c) (* a d)) r)) )
+ (make-complex x y) ))
((or (##core#inline "C_i_flonump" x) (##core#inline "C_i_flonump" y))
;; This may be incorrect when one is a ratnum consisting of bignums
(fp/ (exact->inexact x) (exact->inexact y)))
diff --git a/tests/numbers-test.scm b/tests/numbers-test.scm
index 0652203e..ec6ff494 100644
--- a/tests/numbers-test.scm
+++ b/tests/numbers-test.scm
@@ -206,6 +206,7 @@
(test-equal "/: rat/complex (negative im)" (/ 1/2 1-2i) 1/10+1/5i)
(test-equal "/: rat/complex (negative real)" (/ 1/2 -1+2i) -1/10-1/5i)
(test-equal "/: rat/complex (negative real&im)" (/ 1/2 -1-2i) -1/10+1/5i)
+ (test-equal "/: complex/noncomplex" (/ +inf.0+i 1) +inf.0+i)
(test-assert "/: multiarg" (show (/ 66 2 44)))
(test-error "/: div fixnum by 0" (/ 33 0))
Trap