Well, log(-1)
gives NaN
, and acos(2)
also gives NaN
. Does that mean that log(-1) == acos(2)
? Clearly not. Hence it makes perfect sense that NaN
is not equal to itself.
Revisiting this almost two years later, here's a "NaN-safe" comparison function:
function compare(a,b) {
return a == b || (isNaN(a) && isNaN(b));
}