[Issue 4726] writeln(0.0 / 0.0) prints -nan

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Aug 25 20:35:45 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4726


David Simcha <dsimcha at yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |dsimcha at yahoo.com
         Resolution|                            |INVALID


--- Comment #1 from David Simcha <dsimcha at yahoo.com> 2010-08-25 20:35:37 PDT ---
This is the correct behavior.  For whatever reason x86 CPUs create a NaN with
the sign bit set to 1 when they get a 0.0 / 0.0.  writeln() just displays the
sign bit of the NaN because it gives the programmer more information about how
the NaN was triggered.  The following code demonstrates that the sign bit is
set to 1.

import std.stdio;

void main() {
    double myNan = 0.0 / 0.0;
    ulong asInt = *(cast(ulong*) &myNan); 
    writeln(asInt & (1UL << 63));  // Prints some huge number.
}

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


More information about the Digitalmars-d-bugs mailing list