Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> any two objects which are equal in identity are necessarily equal in all other possible ways

Two NaNs are equal in identity but not in value, according to the IEEE spec.



I wasn't aware that IEEE floating point provided for two different kinds of equality checking? How would you invoke one or the other?

A NaN value does not compare equal to itself, because NaN is not thought of as a value at all but rather an error signal ("Not a Number"). You can check whether something is NaN, but that's not a distinction between comparing by identity and comparing by value -- it's a distinction between comparing values and checking for the presence of errors. The analogous operations to (1) comparing NaN to itself (unequal) and (2) checking whether NaN is NaN (yes), for another value such as -0, are (1b) comparing -0 to itself (equal) and (2b) checking whether -0 is NaN (no). They aren't (1c) comparing -0 to itself and (2c) checking whether -0 has the same "identity" as -0.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: