D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20536 - std.format: %a on reals is inconsistent with %a on float/double
Summary: std.format: %a on reals is inconsistent with %a on float/double
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 normal
Assignee: berni44
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2020-01-26 17:06 UTC by berni44
Modified: 2021-04-12 07:25 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description berni44 2020-01-26 17:06:00 UTC
On my computer the format command below produces "0x8p-23" which is inconsitent with the results from float/double, where the first digit after "0x" is always a 1 (leaving aside corner cases). The test below should work independent of the type of real used.

void main()
{
    import std.format : format;

    real r = .00000095367431640625L;

    assert(format("%a", r) == "0x1p-20"); // fails
}
Comment 1 Dlang Bot 2021-04-11 10:17:45 UTC
@berni44 created dlang/phobos pull request #7951 "std.format: Replace snprintf for x87-reals" fixing this issue:

- Fix Issue 20536 - std.format: %a on reals is inconsistent with %a on float/double

https://github.com/dlang/phobos/pull/7951
Comment 2 Dlang Bot 2021-04-12 07:25:31 UTC
dlang/phobos pull request #7951 "std.format: Replace snprintf for x87-reals" was merged into master:

- c9121a8c8930b06fca9d8ee6963b630b1cbae59e by berni44:
  Fix Issue 20536 - std.format: %a on reals is inconsistent with %a on float/double

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