[Issue 2697] New: Cast of float function return to ulong or uint gives bogus value
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Feb 28 15:26:54 PST 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2697
Summary: Cast of float function return to ulong or uint gives
bogus value
Product: D
Version: 1.040
Platform: PC
OS/Version: Windows
Status: NEW
Keywords: wrong-code
Severity: major
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: smjg at iname.com
import std.stdio;
float func() { return 5; }
void main() {
writefln("float: %f", func());
writefln("ulong: %d", cast(ulong) func());
writefln("long: %d", cast(long) func());
writefln("uint: %d", cast(uint) func());
writefln("int: %d", cast(int) func());
writefln("ushort: %d", cast(ushort) func());
writefln("short: %d", cast(short) func());
writefln("ubyte: %d", cast(ubyte) func());
writefln("byte: %d", cast(byte) func());
float result = func();
writefln("float: %f", result);
writefln("ulong: %d", cast(ulong) result);
writefln("long: %d", cast(long) result);
writefln("uint: %d", cast(uint) result);
writefln("int: %d", cast(int) result);
writefln("ushort: %d", cast(ushort) result);
writefln("short: %d", cast(short) result);
writefln("ubyte: %d", cast(ubyte) result);
writefln("byte: %d", cast(byte) result);
}
----------
float: 5.000000
ulong: 2048
long: 5
uint: 0
int: 5
ushort: 5
short: 5
ubyte: 5
byte: 5
float: 5.000000
ulong: 5
long: 5
uint: 5
int: 5
ushort: 5
short: 5
ubyte: 5
byte: 5
----------
If the ulong and long cases are removed, the cast to uint gives 2048.
Seems to be only float that has the problem - it disappears if I change it to
double or real.
--
More information about the Digitalmars-d-bugs
mailing list