D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21641 - std.format: %g produces in rare circumstances inconsistent result
Summary: std.format: %g produces in rare circumstances inconsistent result
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 minor
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2021-02-16 18:01 UTC by Berni44
Modified: 2021-03-13 15:36 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Berni44 2021-02-16 18:01:04 UTC
import std.stdio;

void main()
{
    float a = -999999.8125;
    writefln!"%#.1g"(a);
    writefln!"%#.2g"(a);
    writefln!"%#.3g"(a);
    writefln!"%#.4g"(a);
    writefln!"%#.5g"(a);
    writefln!"%#.6g"(a);
    writefln!"%#.7g"(a);
    writefln!"%#.8g"(a);
    writefln!"%#.9g"(a);
}

produces:

-1.e+06
-1.0e+06
-1.00e+06
-1.000e+06
-1.0000e+06
-1.e+06
-999999.8
-999999.81
-999999.812

The sixth line is inconsistent, should be -1.00000e+06.
Comment 1 Dlang Bot 2021-02-18 17:06:52 UTC
@berni44 created dlang/phobos pull request #7804 "std.format: format floats and doubles with %g / %G / %s" fixing this issue:

- Fix 21641 - std.format: %g produces in rare circumstances inconsistent result

https://github.com/dlang/phobos/pull/7804
Comment 2 Dlang Bot 2021-03-13 07:52:58 UTC
@berni44 created dlang/phobos pull request #7853 "Format add g final step" fixing this issue:

- Fix 21641 - std.format: %g produces in rare circumstances inconsistent result

https://github.com/dlang/phobos/pull/7853
Comment 3 Dlang Bot 2021-03-13 15:36:28 UTC
dlang/phobos pull request #7853 "Format add g final step" was merged into master:

- bfcd65e71efd3737d2383266d719083685ef2939 by berni44:
  Fix 21641 - std.format: %g produces in rare circumstances inconsistent result

https://github.com/dlang/phobos/pull/7853