http://d.puremagic.com/issues/show_bug.cgi?id=5229

           Summary: Inaccurate parsing of floating-point literals
           Product: D
           Version: D1 & D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: bugzi...@kyllingen.net


--- 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!

Test case:

    void main()
    {
        // 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
        // representation.
        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: -------

Reply via email to