nan or -nan?

Ali Çehreli acehreli at yahoo.com
Tue Nov 15 20:35:32 PST 2011


Some floating point operations produce .nan:

import std.stdio;

void main()
{
     double zero = 0;
     double infinity = double.infinity;

     writeln("any expression with nan: ", double.nan + 1);
     writeln("    zero / zero        : ", zero / zero);
     writeln("    zero x infinity    : ", zero * infinity);
     writeln("infinity / infinity    : ", infinity / infinity);
     writeln("infinity - infinity    : ", infinity - infinity);
}

Last time I checked, I think the program above would produce nan for all 
of those operations. Now some are -nan when compiled with 64-bit dmd 
2.056 on Linux:

any expression with nan: nan
     zero / zero        : -nan
     zero x infinity    : -nan
infinity / infinity    : -nan
infinity - infinity    : -nan

Is that expected? Does it matter?

Ali


More information about the Digitalmars-d mailing list