[Issue 20535] New: std.format: %b, %o, %x and %X on negative integers gives wrong result
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jan 26 13:29:58 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=20535
Issue ID: 20535
Summary: std.format: %b, %o, %x and %X on negative integers
gives wrong result
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: bugzilla at d-ecke.de
Currently format casts the value to it's unsigned version and prints that. This
is inconsistent with %d. Additionally, if this behaviour is wished, it can
easily be accomplished by the user casting himself before formatting.
void main()
{
import std.format : format;
assert(format("%b",-17) == "-10001"); // fails
assert(format("%o",-17) == "-21"); // fails
assert(format("%x",-17) == "-11"); // fails
assert(format("%X",-17) == "-11"); // fails
}
--
More information about the Digitalmars-d-bugs
mailing list