Bug 5800 – Wrong NAN bit pattern during array initialization
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2011-03-30T15:02:00Z
Last change time
2011-03-30T18:07:10Z
Assigned to
nobody
Creator
acehreli
Comments
Comment #0 by acehreli — 2011-03-30T15:02:28Z
Environment: dmd 2.052, 64-bit Ubuntu.
The following program passes the two asserts, showing that the array elements are not initialized as NANs. The dumpBytes() function shows that the bit pattern is different than a local variable's:
import std.stdio;
void main()
{
double[1] a;
auto myNaN = double.nan;
assert (a[0] != myNaN); // <-- passes; BUG
assert (a[0] != double.nan); // <-- passes; BUG
dumpBytes(a[0]);
dumpBytes(myNaN);
}
void dumpBytes(T)(ref T var)
{
const ubyte * beg = cast(ubyte*)&var;
foreach (bayt; beg .. beg + T.sizeof) {
writef("%02x ", *bayt);
}
writeln();
}
The bug manifests itself for float and real as well and the bit pattern changes depending on whether -m32 or -m64 is used. Here is one output of the program with -m64:
00 00 00 00 00 00 fc 7f
00 00 00 00 00 00 f8 7f
Ali
Comment #1 by kennytm — 2011-03-30T15:20:01Z
Isn't it expected that 'nan' does not equate to itself?
Comment #2 by acehreli — 2011-03-30T18:07:10Z
My mistake: "Equality Expressions" at http://digitalmars.com/d/2.0/expression.html says "If either or both operands are NAN, then both the == returns false and != returns true." [sic]