[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-hackers] [PATCH] Prevent Chicken from truncating large flonums
From: |
Peter Bex |
Subject: |
[Chicken-hackers] [PATCH] Prevent Chicken from truncating large flonums when compiling |
Date: |
Sat, 17 Sep 2011 17:56:52 +0200 |
User-agent: |
Mutt/1.4.2.3i |
Hi all,
This is a patch and bugreport rolled into one ;)
While testing the "numbers" egg I found out that programs
containing flonum literals can behave differently when compiled
or interpreted.
This turns out to be caused by the fact that Chicken just
uses [sf]printf or gcvt to print flonums while emitting C code.
When nothing else is specified, these use the default
"flonum-print-precision" of 15, which means that any number with
more _decimal_ digits than that get printed in exponential notation,
like this:
#;1> 123456789012345.0
123456789012345.0
#;2> 1234567890123456.0
1.23456789012346e+15
So after (read)ing the literal the compiler then later prints it
back again, but with less precision than was present when reading it.
This behavior can be tweaked by calling (flonum-print-precision N),
which is exactly what the compiler should be doing and what my patch
does. You can also merge it from the "sjamaan-pending" branch,
it's changeset 6c39851e1504d01b2de05e014f5542913e3e5c5e.
PS: If someone with access to a Windows system is reading this,
there's a sort-of related bug in #691. I've attached a patch that
needs to be tested to the ticket.
Cheers,
Peter
--
http://sjamaan.ath.cx
--
"The process of preparing programs for a digital computer
is especially attractive, not only because it can be economically
and scientifically rewarding, but also because it can be an aesthetic
experience much like composing poetry or music."
-- Donald Knuth
0001-Do-not-drop-precision-in-flonums-when-compiling.patch
Description: Text document
- [Chicken-hackers] [PATCH] Prevent Chicken from truncating large flonums when compiling,
Peter Bex <=