Hacker News new | past | comments | ask | show | jobs | submit login

I don't understand your point. This is not a number:

    char *p = "abc";
Yet, this yields true:

    p == p
The square root of -1 is easily representable in floating math. You just need two floats to make a complex.



Okay, but while "abc" is not a number, it is also the string "abc". NaN is special in that all it tells you is that the value is not a number -- it doesn't tell you what it is. In order to return a true value from an equality test, it isn't enough to know that both values are not a number, you have to know what they actually are.


If it is not known what is in the p variable, then the variable is indeterminate; it has exactly the same status as a variable that has not been initialized. In this case, the behavior upon accessing the variable should be undefined.

I agree with making accesses of NaN-valued variables undefined behavior, so that not comparing equal is then a possible consequence of undefined behavior.

I don't agree with defining the unequal comparison as the required behavior. To define the behavior is tantamount to the recognition that a NaN is something: an object. A variable can have a defined value which is that something, and that value must obey the Law of Identity.


The point is that you can have very different things that are not a number. It's not safe to say that multiple things that are not a number are equal.


The values of two expressions that evaluate the same variable are not "multiple things".




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: