~ chicken-core (chicken-5) 6c39851e1504d01b2de05e014f5542913e3e5c5e
commit 6c39851e1504d01b2de05e014f5542913e3e5c5e Author: Peter Bex <peter.bex@xs4all.nl> AuthorDate: Sat Sep 17 17:41:58 2011 +0200 Commit: Peter Bex <peter.bex@xs4all.nl> CommitDate: Sat Sep 17 17:41:58 2011 +0200 Do not drop precision in flonums when compiling diff --git a/c-backend.scm b/c-backend.scm index 1571edb6..5dbcadda 100644 --- a/c-backend.scm +++ b/c-backend.scm @@ -60,6 +60,8 @@ ;;; Generate target code: (define (generate-code literals lliterals lambdas out source-file dynamic db) + ;; Don't truncate floating-point precision! + (flonum-print-precision (+ flonum-maximum-decimal-exponent 1)) (let () ;; Some helper procedures diff --git a/tests/compiler-tests.scm b/tests/compiler-tests.scm index 73951302..226c440f 100644 --- a/tests/compiler-tests.scm +++ b/tests/compiler-tests.scm @@ -216,3 +216,16 @@ (assert (zero? b)))) (gp-test) + +;; Test that encode-literal doesn't drop digits for extreme flonum values. + +;; This number is 2^971 * (2^53 - 1), and is the positive "all ones" number for +;; 64-bit flonums with precision 53 and significand/mantissa 10. +;; If we want to support 32-bit flonums or flonums with different precision +;; or significand, we need a cond-expand here or something. +;; Technically, even larger decimal numbers can be represented by flonums. +;; This number can correctly be compared exactly. +(assert (= (* (- (expt 2 flonum-precision) 1) + (expt 2 (- flonum-maximum-exponent flonum-precision))) + 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0 + (string->number "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0"))) \ No newline at end of fileTrap