Why float.NaN != double.NaN ?
while float.PositiveInfinity == double.PositiveInfinity and float.NegativeInfinity == double.NegativeInfinity are equal.
EXAMPLE:
bool PosInfinity = (float.PositiveInfinity == double.PositiveInfinity); //true
bool NegInfinity = (float.NegativeInfinity == double.NegativeInfinity); //true
bool isNanEqual = (float.NaN == double.NaN); //false, WHY?
NaNis never equal toNaN(even within the same type). Hence why the IsNaN function exists:You should also be aware that none of the comparisons you’ve shown are actually occurring “as is”. When you write
floatValue == doubleValue, the floats will actually be implicitly converted to doubles before the comparison occurs.