Can someone explain this to me? In C# double.NaN is not equal to double.NaN
bool huh = double.NaN == double.NaN; // huh = false bool huh2 = double.NaN >= 0; // huh2 = false bool huh3 = double.NaN <= 0; // huh3 = false
What constant can I compare to a double.NaN and get true?
Yeah, a Not-A-Number is Not equal to itself. But unlike the case with undefined and null where comparing an undefined value to null is true but a hard check(===) of the same will give you a false value, NaN's behavior is because of IEEE spec that all systems need to adhere to.
NaN values are tested for equality by using the == operator, the result is false. So, no matter what value of type double is compared with double. NaN, the result is always false.
The Double. IsNaN() method in C# is used to return a value that indicates whether the specified value is not a number (NaN).
If you are curious, this is what Double.IsNaN
looks like:
public static bool IsNaN(double d) { return (d != d); }
Funky, huh?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With