digitalmars.D.bugs - [Bug 92] New: std.format %x, %o and %b assume 64-bit negative values
- d-bugmail puremagic.com (69/69) Apr 07 2006 http://d.puremagic.com/bugzilla/show_bug.cgi?id=92
- d-bugmail puremagic.com (9/9) Apr 10 2006 http://d.puremagic.com/bugzilla/show_bug.cgi?id=92
http://d.puremagic.com/bugzilla/show_bug.cgi?id=92 Summary: std.format %x, %o and %b assume 64-bit negative values Product: D Version: 0.152 Platform: PC OS/Version: Windows Status: NEW Severity: normal Priority: P2 Component: Phobos AssignedTo: bugzilla digitalmars.com ReportedBy: smjg iname.com When the %x, %o or %b format is used to format a negative integer, the correct result is produced only in the case of long. Even for byte, short or int, the output is 64 bits long. ---------- import std.stdio; const char[][] fmts = [ "%x", "%o", "%b" ]; void main() { foreach (fmt; fmts) { byte b = byte.max; writefln(fmt, b); writefln(fmt, ++b); writefln(fmt, ++b); short s = short.max; writefln(fmt, s); writefln(fmt, ++s); writefln(fmt, ++s); int i = int.max; writefln(fmt, i); writefln(fmt, ++i); writefln(fmt, ++i); long l = long.max; writefln(fmt, l); writefln(fmt, ++l); writefln(fmt, ++l); writefln(); } } ---------- The %x case should suffice to illustrate. Actual output: 7f ffffffffffffff80 ffffffffffffff81 7fff ffffffffffff8000 ffffffffffff8001 7fffffff ffffffff80000000 ffffffff80000001 7fffffffffffffff 8000000000000000 8000000000000001 Expected output: 7f 80 81 7fff 8000 8001 7fffffff 80000000 80000001 7fffffffffffffff 8000000000000000 8000000000000001 The same happens if I specify e.g. %04x instead of %x. --
Apr 07 2006
http://d.puremagic.com/bugzilla/show_bug.cgi?id=92 bugzilla digitalmars.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED Fixed 0.153 --
Apr 10 2006