Thread overview
[Issue 5800] New: Wrong NAN bit pattern during array initialization
Mar 30, 2011
Ali Cehreli
Mar 30, 2011
kennytm@gmail.com
Mar 31, 2011
Ali Cehreli
March 30, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5800

           Summary: Wrong NAN bit pattern during array initialization
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: acehreli@yahoo.com


--- Comment #0 from Ali Cehreli <acehreli@yahoo.com> 2011-03-30 15:02:28 PDT ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 30, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5800


kennytm@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kennytm@gmail.com


--- Comment #1 from kennytm@gmail.com 2011-03-30 15:20:01 PDT ---
Isn't it expected that 'nan' does not equate to itself?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 31, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5800


Ali Cehreli <acehreli@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


--- Comment #2 from Ali Cehreli <acehreli@yahoo.com> 2011-03-30 18:07:10 PDT ---
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]

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------