Summary: Inaccurate parsing of floating-point literals
Version: D1 & D2
--- Comment #0 from Lars T. Kyllingstad <bugzi...@kyllingen.net> 2010-11-17
03:29:34 PST ---
80-bit reals give you roughly 19 decimal digits of precision. Thus, for a
given number, 20 digits should usually be enough to ensure that the literal
gets mapped to the closest representable number.
The following program shows that this is not always the case. Here, 23 digits
is needed to get the closest representable number to pi^2, even though the
approximation to pi^2 itself is only accurate to 18 digits!
// Approximations to pi^2, accurate to 18 digits:
real closest = 0x9.de9e64df22ef2d2p+0L;
real next = 0x9.de9e64df22ef2d3p+0L;
// A literal with 23 digits maps to the correct
real dig23 = 9.86960_44010_89358_61883_45L;
assert (dig23 == closest);
// 22 digits should also be (more than) sufficient,
// but no...
real dig22 = 9.86960_44010_89358_61883_5L;
assert (dig22 == closest); // Fails; should pass
assert (dig22 == next); // Passes; should fail
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------