What is the result of the following operation defined by IEEE754. (NaN == NaN)
Step-by-step Solution:
What is the result of the IEEE-754 comparison:
(NaN == NaN) ?
0/0 or sqrt(-1)).
false. So NaN == NaN is false.
isnan() (C/C++),
Number.isNaN() (JavaScript), or platform-specific functions — not equality.
(NaN == NaN) → false
// C (IEEE-754 floating point)
double x = 0.0/0.0; // NaN
printf("%d\n", x == x); // prints 0 (false)
printf("%d\n", isnan(x)); // prints 1 (true)
// JavaScript
let x = NaN;
console.log(x == x); // false
console.log(Number.isNaN(x));// true
// Python
import math
x = float('nan')
print(x == x) # False
print(math.isnan(x)) # True
Extra note: IEEE-754 also provides signaling and quiet NaNs and treats all NaNs as unordered for comparisons. Many numeric libraries provide utilities to handle NaNs explicitly (propagation, tests, or replacement).