[erlang-questions] pre-EEP: accurate float printing (replacement for io_lib_format:fwrite_g/1)
Bob Ippolito
bob@REDACTED
Mon Dec 10 22:40:26 CET 2007
If we submit a patch to io_lib_format:fwrite_g/1 to use an accurate
floating point decimal representation, would it be accepted? If not,
is there a less intrusive way that we could override this?
I find it VERY annoying to have the shell print "~.5g", since that
often doesn't have enough precision to see what I need to see in the
floats we work with. I also generally prefer to see "0.1" instead of
"0.10000".
We have a suitable implementation here, which is the same algorithm
that several other programming languages use and there's a paper that
proves its correctness:
http://mochiweb.googlecode.com/svn/trunk/src/mochinum.erl
It could probably be made a little faster if necessary by using a
pre-calculated set of results for int_pow that covers the range that
the algorithm needs, e.g.:
int_pow(10, 0) -> 1;
int_pow(10, 1) -> 10;
...
int_pow(10, 324) -> ...
-bob
More information about the erlang-questions
mailing list