~ chicken-core (master) 2fb2352d3acdc022f44a74e118e99622c5470bc4


commit 2fb2352d3acdc022f44a74e118e99622c5470bc4
Author:     Peter McGoron <code@mcgoron.com>
AuthorDate: Wed Jul 29 16:18:44 2026 -0400
Commit:     Felix Winkelmann <felix.winkelmann@bevuta.com>
CommitDate: Wed Sep 9 13:45:42 2026 +0200

    For all non-exact-zero z, (/ 0 z) => 0
    
    This means that (/ 0 0.0) = (/ 0 +nan.0) = 0 (exact).
    (/ 0 0) is still an error.

diff --git a/library.scm b/library.scm
index 0bcc70ae..4a5fbdfc 100644
--- a/library.scm
+++ b/library.scm
@@ -2509,7 +2509,8 @@ EOF
 (define (##sys#/-2 x y)
   (when (eq? y 0)
     (##sys#error-hook (foreign-value "C_DIVISION_BY_ZERO_ERROR" int) '/ x y))
-  (cond ((and (##core#inline "C_i_exact_integerp" x)
+  (cond ((eq? x 0) 0)
+        ((and (##core#inline "C_i_exact_integerp" x)
               (##core#inline "C_i_exact_integerp" y))
          (let ((g (%integer-gcd x y)))
            (ratnum (%integer-quotient x g) (%integer-quotient y g))))
diff --git a/tests/numbers-test.scm b/tests/numbers-test.scm
index f3c5c305..90809c96 100644
--- a/tests/numbers-test.scm
+++ b/tests/numbers-test.scm
@@ -213,6 +213,9 @@
  (test-equal "/: div fixnum by 0.0" (/ 33 0.0) +inf.0)
  (test-equal "/: div flonum by 0.0" (/ 33.0 0.0) +inf.0)
  (test-equal "/: div by 0 (inexact)" (/ 33 0.0) +inf.0)
+ (test-equal "/: (/ 0 z) => 0 for any z" (/ 0 10.0) 0)
+ (test-equal "/: (/ 0 +inf.0) => 0" (/ 0 +inf.0) 0)
+ (test-equal "/: (/ 0 -inf.0) => 0" (/ 0 -inf.0) 0)
  (test-assert "/: big result" (show (/ b1 2)))
 )
 
Trap