You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 1778 Reporter: administrator Status: closed Resolution: fixed Priority: normal Severity: minor Category: ~DO NOT USE (was: OCaml general)
Bug description
String_of_float is now %.17g versus the old %.12g. You might want to
note this behavior in the Changelog. (My log file is lots bigger now
that every number is 19 characters wide versus the previous 4 or 5.)
String_of_float is now %.17g versus the old %.12g. You might want to
note this behavior in the Changelog. (My log file is lots bigger now
that every number is 19 characters wide versus the previous 4 or 5.)
Right. That wasn't a great idea.
The problem we tried to address is as follows: the toplevel prints
floats using string_of_float, and several unsophisticated users don't
understand that the printed value of a float may not have as many
digits as the machine representation, so two floats can print the same
and be different. (I guess they never used a pocket calculator...)
Using %.17g in string_of_float doesn't really solve this issue,
because there are many cases where we get too many digits in the
resulting string (fewer digits would result in the same float). This
depends a lot on the C library implementation of printf, but
apparently many get it wrong and don't implement the "print enough
digits so that the float can be read back identically" rule.
A better approximation of this rule is to convert floats to strings
with increasing precision, until the strings read back as the original
floats. This works quite well, but is computationally expensive --
probably too much for string_of_float.
What we'll do is decouple string_of_float and toplevel printing of
floats. The former will revert to %.12g as in 3.06, while the latter
will use the "increasing precision" approach, since toplevel printing
isn't performance-critical.
Original bug ID: 1778
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)
Bug description
String_of_float is now %.17g versus the old %.12g. You might want to
note this behavior in the Changelog. (My log file is lots bigger now
that every number is 19 characters wide versus the previous 4 or 5.)
string_of_float 0.14000000000000001;;
string_of_float 0.1400000000001;;
string_of_float 0.140000000001;;
0.14000000000000001 = 0.14 ;;
: bool = true
string_of_float 0.14000000000000001;;
string_of_float 0.1400000000000000000000000000000001;;
0.14000000000000001 = 0.14 ;;
The text was updated successfully, but these errors were encountered: