I came across a definition of .NET double.NaN in code:
public const double NaN = (double)0.0 / (double)0.0;
This is done similarly in PositiveInfinity and NegativeInfinity .
double.IsNaN (with the removal of several #pragmas and comments) is defined as:
[Pure] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] public static bool IsNaN(double d) { if (d != d) { return true; } else { return false; } }
This is very controversial for me.
Why is NaN defined as division by zero? How is 0.0 / 0.0 presented behind the scenes? How can division by 0 be possible in double , and why NaN != NaN ?
GeReV source share