[Bug 92] New: std.format %x, %o and %b assume 64-bit negative values
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Apr 7 03:35:06 PDT 2006
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 at digitalmars.com
ReportedBy: smjg at 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.
--
More information about the Digitalmars-d-bugs
mailing list