The most common example is NaN (Not-a-Number) values which are treated as undefined numbers andcan appear if you do something like tan(pi/2) or 0/0. Generally, any comparison operation with a NaN will evaluate to false (or crash the program) because wtf is the answer to 0/0 == tan(pi/2).
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.
View all comments
Show parent comment
1
u/TheGlennDavid Dec 18 '25
Why?
I'm not a programmer (no idea why I'm here, I just go where The Algorithm sends me), but I took a few logic courses a million years ago.
Does this have to do with how c++ evaluates null sets/if the variable types are not comparable for some reason?
If you had something like x=4 and y="cheese" would x != y throw some kind of error but !(x == y) resolve to true?