[erlang-questions] Bug? Pretty-printing floating point values
Wed Nov 21 20:29:11 CET 2007
at least my C++ compiler (MSVC++) has thease 2 defines in #include
#define DBL_DIG 15 /* # of decimal digits of
#define FLT_DIG 6 /* # of decimal digits of
Per Hedeland wrote:
> "Christian S" <chsu79@REDACTED> wrote:
>>Doesn't look like the number of significant digits when read are stored.
> Undoubtedly true, but not necessarily relevant.
>>I wouldn't call it a bug. It is how floating point numbers work.
>>They're very exact with fractions that are a sum of limited numbers of
>>negative powers of two though.
> A reasonable question could be why float_to_list/1 generates 20 digits
> when a 64-bit float (a.k.a. C double), which is what is used internally,
> only can hold 15-16 worth of them - I don't know off-hand what a 128-bit
> float would have, but presumably significantly more than 20, so it's not
> that either. I guess way back in the dark ages, someone thought that 20
> was a nice and even number (I hope it wasn't me:-). The 6.30000 form is
> of course just the ~p/~w formatting.
> --Per Hedeland
> Eshell V5.5.5 (abort with ^G)
> 1> F=6.30000000000000000000000000000.
> 2> float_to_list(F).
> 3> io:format("~p~n",[F]).
> 4> io:format("~.16g~n",[F]).
> 5> io:format("~.17g~n",[F]).
> erlang-questions mailing list
View this message in context: http://www.nabble.com/Bug--Pretty-printing-floating-point-values-tf4850658.html#a13884355
Sent from the Erlang Questions mailing list archive at Nabble.com.
More information about the erlang-questions