digitalmars.D.bugs - [Issue 18838] New: Formatting the number zero with separator doesn't
- d-bugmail puremagic.com (30/30) May 06 2018 https://issues.dlang.org/show_bug.cgi?id=18838
https://issues.dlang.org/show_bug.cgi?id=18838 Issue ID: 18838 Summary: Formatting the number zero with separator doesn't obey width specifier Product: D Version: D2 Hardware: x86_64 OS: Windows Status: NEW Severity: minor Priority: P1 Component: phobos Assignee: nobody puremagic.com Reporter: tornchi gmail.com The following code shows the problem. The width specifier is obeyed in each case except when printing the number zero. import std.stdio; void main() { "%12d".writefln(1); // Writes " 1" "%12d".writefln(0); // Writes " 0" "%12,d".writefln(1); // Writes " 1" "%12,d".writefln(0); // Writes "0" <-- WRONG "%12,d".writefln(-1); // Writes " -1" } I've tracked the cause to the formatUnsigned function in format.d specifically the spacesToPrint calculation (ln:2351). Here the "digits.length - 1" calculation overflows/underflows resulting in no left padding to occur. --
May 06 2018