[erlang-questions] : Bug? Pretty-printing floating point values

Pierpaolo Bernardi olopierpa@REDACTED
Thu Nov 22 12:19:29 CET 2007


On Nov 22, 2007 9:05 AM, Raimo Niskanen
<raimo+erlang-questions@REDACTED> wrote:
> I guess float_to_list/1 produces 20 digits because previously the
> external term format for floats was that kind of printout -
> 20 decimal digits with exponent. Nowdays it is the IEEE format.
>
> And I guess it was chosen so you kind of could guarantee to be able to
> recreated exactly the right number after a roundtrip to external format.
> Therefore significantly more than 16 digits was needed.
>
> I do not know if 20 digits can be proved to be always enough, though...

The problem of printing and reading floating point numbers with the
minimal number of digits
to guarantee round trip invariance has been investigated and solved.

See the papers and the public domain code already posted by Doug Currie.

These algorithms are used in all serious common lisp and scheme implementations.

It would be very smart for the Erlang implementors to borrow this
public domain code.

Cheers
P.



More information about the erlang-questions mailing list