The reason of Double.NaN != Double.NaN
is simple:
Do you expect 0/0
to be the same as Math.Sqrt(-3)
? And same as Math.Sqrt(-7)
?
There is a bug in C# in my opinion where Equals()
is not overridden for NaN.
Assert.IsTrue(Double.NaN != Double.NaN);
Assert.IsTrue(Double.NaN.Equals(Double.NaN));
At the same time
Assert.IsTrue(Double.PositiveInfinity == Double.NegativeInfinity);
Assert.IsTrue(Double.PositiveInfinity.Equals(Double.PositiveInfinity));
// same for Double.NegativeInfinity and Single
Use static functions for Double
and Single
, e.g.
Double.IsNaN(value) && Double.IsInfinity(value);
Or more specific:
Double.IsPositiveInfinity(value);
Double.IsNegativeInfinity(value);
NULL
in SQL – Yeager