[Issue 3248] New: lossless floating point formatting

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Aug 12 10:31:09 PDT 2009


           Summary: lossless floating point formatting
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: moi667 at hotmail.com

Could an option be added to the formatting to elide trailing zero's for %f ?
That way it is possible to create an optimal lossless formatting for which the
following holds:

float f;
s = format(f);
float f2 = to!(float)(s);

The formatting I'm trying to get can be seen here (decimal):

%g fails to format like this because it uses %f for as small as 10^-5,
thus loosing precision for floats with leading zero's, like 0.00001234567.

Fixing this by using %f for 10^-5..10^-1 fails because it doesn't elide
trailing zero's making it suboptimal space-wise. 

It would be even nicer to have this lossless formatting added to std.format!
I would even suggest making this the default formatting for floating point;
floating point isn't as straight forward as integral and it is easy to think
the current formatting holds all information.

Compared to the hex %a format this new lossless format will be better readable
(less bug-prone) and generally shorter (0.1 will be 0.1).

Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

More information about the Digitalmars-d-bugs mailing list