Bug 92 – std.format %x, %o and %b assume 64-bit negative values

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2006-04-07T05:35:00Z
Last change time
2014-02-15T02:13:16Z
Assigned to
bugzilla
Creator
smjg

Comments

Comment #0 by smjg — 2006-04-07T05:35:06Z
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.
Comment #1 by bugzilla — 2006-04-11T01:34:16Z
Fixed 0.153