www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5800] New: Wrong NAN bit pattern during array initialization

reply d-bugmail puremagic.com writes:
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



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: -------
Mar 30 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5800


kennytm gmail.com changed:

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



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: -------
Mar 30 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5800


Ali Cehreli <acehreli yahoo.com> changed:

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



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: -------
Mar 30 2011