Hacker News new | ask | show | jobs
by spyrja 301 days ago
Yep, exactly. NAN's truly are a great example of just how weird an edge case can get too!

  #define isNan(X) ((X) != (X))
1 comments

For anyone else who forgot this or is unfamiliar with why / how it "works":

> #define isNan(X) ((X) != (X))

> Works by exploiting a unique property of NaN (Not a Number) values in the IEEE-754 floating point standard: a NaN is not equal to itself. In other words, if you compare a floating-point variable to itself and the result is false ((X) != (X)(X)!=(X)), then X X is NaN.

Fantastic example, thank you @spyrja!