D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21777 - std.format: several issues when formatting integers with precision
Summary: std.format: several issues when formatting integers with precision
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2021-03-28 09:52 UTC by Berni44
Modified: 2021-04-15 07:12 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-03-28 09:52:03 UTC
All of the following tests fail:

unittest
{
    assert(format!"%20.5,d"(cast(short) 120) == "              00,120"); // comma missing
    assert(format!"%20.5,o"(cast(short) 120) == "              00,170"); // comma missing
    assert(format!"%20.5,x"(cast(short) 120) == "              00,078"); // one space too much
    assert(format!"%20.5,2d"(cast(short) 120) == "             0,01,20"); // one space too much
    assert(format!"%20.5,2o"(cast(short) 120) == "             0,01,70"); // one space too much
    assert(format!"%20.5,4d"(cast(short) 120) == "              0,0120"); // comma missing
    assert(format!"%20.5,4o"(cast(short) 120) == "              0,0170"); // comma missing
    assert(format!"%20.5,4x"(cast(short) 120) == "              0,0170"); // comma missing
    assert(format!"%20.5,2x"(3000) == "             0,0b,b8"); // one space too much
    assert(format!"%20.5,4d"(3000) == "              0,3000"); // comma missing
    assert(format!"%20.5,4o"(3000) == "              0,5670"); // comma missing
    assert(format!"%20.5,4x"(3000) == "              0,0bb8"); // comma missing
    assert(format!"%20.5,d"(-400) == "             -0,0400"); // one space too much
    assert(format!"%20.30d"(-400) == "-00000000000000000000000000400"); // one zero too much
}
Comment 1 Berni44 2021-03-28 13:42:34 UTC
One more:

assert(format!"%20.5,4d"(0) == "              0,0000"); // comma is in the wrong place
Comment 2 Berni44 2021-04-11 15:27:16 UTC
Two more:

assert(format!"%0#.8,2s"(12345) == "00,01,23,45");
assert(format!"%0#.9,3x"(55) == "0x000,000,037");
Comment 3 Dlang Bot 2021-04-13 20:05:01 UTC
@berni44 created dlang/phobos pull request #7965 "std.format: New version for formatting integral values using writeAligned" fixing this issue:

- Fix Issue 21777 - std.format: several issues when formatting integers with precision

https://github.com/dlang/phobos/pull/7965
Comment 4 Dlang Bot 2021-04-15 07:12:15 UTC
dlang/phobos pull request #7965 "std.format: New version for formatting integral values using writeAligned" was merged into master:

- 5e180880cb04994b8dc9d88e38e9046f43c5b1d5 by berni44:
  Fix Issue 21777 - std.format: several issues when formatting integers with precision

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