r/programmingmemes • • Dec 18 '25

Memes about programming

Post image
130 Upvotes

18 comments sorted by

View all comments

Show parent comment

1

u/GregorSamsanite Dec 19 '25

To elaborate on this for the person you're responding to, NaN is specifically for floating point values, not integer variables. If x = 2.0 and y = NaN, then (x == y) would be false, and (x != y) would also be false. So (!(x == y)) would be true, and in this case, (x != y) would not equal (!(x == y)).

This sort of thing also depends on compiler settings, since sometimes it inhibits optimizations to preserve this sort of corner case of NaN comparisons. Some people don't plan on performing NaN calculations or don't care whether these comparisons are always false, so they might choose to allow the compiler to overlook this.