~ chicken-core (master) 208901e26646334f26c09818e12cbf1361a0c157


commit 208901e26646334f26c09818e12cbf1361a0c157
Author:     felix <felix@call-with-current-continuation.org>
AuthorDate: Tue Jul 28 13:20:45 2026 +0200
Commit:     Peter Bex <peter@more-magic.net>
CommitDate: Tue Jul 28 15:29:30 2026 +0200

    imag-part on a non-complex number returns exact 0
    
    (suggested by Peter McGoron)
    
    Signed-off-by: Peter Bex <peter@more-magic.net>

diff --git a/NEWS b/NEWS
index 75d41067..88c86cfe 100644
--- a/NEWS
+++ b/NEWS
@@ -96,6 +96,7 @@
     is inexact zero.
   - `string->number' and the reader accept and handle correctly complex 
     numbers with a negative inexact zero as the imaginary part.
+  - `imag-part' returns exact zero when given a on-complex number.
 
 - Syntax expander:
   - `syntax-rules' attempts to better support tail patterns with ellipses
diff --git a/library.scm b/library.scm
index b136c9e2..c91945fa 100644
--- a/library.scm
+++ b/library.scm
@@ -2352,7 +2352,6 @@ EOF
 (set! scheme#imag-part
   (lambda (x)
     (cond ((cplxnum? x) (%cplxnum-imag x))
-	  ((##core#inline "C_i_flonump" x) 0.0)
 	  ((number? x) 0)
 	  (else (##sys#error-bad-number x 'imag-part)) )))
 
diff --git a/tests/numbers-test.scm b/tests/numbers-test.scm
index 5731f06e..29877539 100644
--- a/tests/numbers-test.scm
+++ b/tests/numbers-test.scm
@@ -649,7 +649,7 @@
  (test-equal "real-part of negative ratnum" (real-part -1/2) -1/2)
  (test-equal "real-part of negative bignum" (real-part (- b1)) (- b1))
  (test-equal "imag-part" (imag-part c1) 44)
- (test-equal "imag-part of flonum" (imag-part 1.23) 0.0)
+ (test-equal "imag-part of flonum" (imag-part 1.23) 0)
  (test-equal "imag-part of fixnum" (imag-part 123) 0)
  (test-equal "imag-part of ratnum" (imag-part 1/2) 0)
  (test-equal "imag-part of bignum" (imag-part b1) 0)
diff --git a/types.db b/types.db
index b657e6a5..10993919 100644
--- a/types.db
+++ b/types.db
@@ -801,8 +801,7 @@
 	   ((cplxnum) (##core#inline "C_u_i_cplxnum_real" #(1))))
 
 (scheme#imag-part (#(procedure #:clean #:enforce #:foldable) scheme#imag-part (number) (or integer float ratnum))
-		  (((or fixnum bignum ratnum)) (let ((#(tmp) #(1))) '0))
-		  ((float) (let ((#(tmp) #(1))) '0.0))
+		  (((or fixnum float bignum ratnum)) (let ((#(tmp) #(1))) '0))
 		  ((cplxnum) (##core#inline "C_u_i_cplxnum_imag" #(1))))
 
 (scheme#magnitude (#(procedure #:clean #:enforce #:foldable) scheme#magnitude (number) number)
Trap