~ chicken-core (chicken-5) 0ef15221362063e049dedbf139b9a40522fc46cb
commit 0ef15221362063e049dedbf139b9a40522fc46cb
Author: Evan Hanson <evhan@foldling.org>
AuthorDate: Thu Jun 27 16:34:36 2019 +1200
Commit: Peter Bex <peter@more-magic.net>
CommitDate: Sun Jun 30 11:03:13 2019 +0200
Emit C99 constants for +nan.0 and [+-]inf.0 `##core#float' nodes
The unboxing pass added in 79cf7427 introduces a `##core#float' type to
the closure-converted language, for which floating point literals are
emitted inline. This also needs to handle NaN and infinite values. For
these, we use the NAN and INFINITY constants defined by C99. We also
adds a cast to "double" for all inline flonums.
Fixes #1626.
Signed-off-by: Peter Bex <peter@more-magic.net>
diff --git a/c-backend.scm b/c-backend.scm
index 2ef2337f..10134fbc 100644
--- a/c-backend.scm
+++ b/c-backend.scm
@@ -127,7 +127,13 @@
(gen "lf[" (first params) #\])) ) )
((##core#float)
- (gen (first params)))
+ (let ((n (first params)))
+ (gen "(double)")
+ (cond ((nan? n) (gen "NAN"))
+ ((infinite? n)
+ (when (negative? n) (gen #\-))
+ (gen "INFINITY"))
+ (else (gen n)))))
((if)
(gen #t "if(C_truep(")
Trap