Hacker News new | ask | show | jobs
by AndriyKunitsyn 94 days ago
>With not-numbers added to the set of FP numbers, the set becomes a partially-ordered set and all relational operators must be interpreted accordingly.

The same not-number, produced by the same computation, occupying the same memory, is still not equal to itself. It is true that I haven't been able to brush up my knowledge on partial ordering, but isn't being identical is the same as being equal in math?

1 comments

If you test if a not-a-number is equal to itself, the result is false.

If you test if a not-a-number is not equal to itself, the result is also false.

The reason is that the result of comparing a not-number with itself is neither "equal" nor "not equal", but "unordered".

This should make perfect intuitive sense, because a NaN encodes the fact that "an undefined operation has happened".

For instance, you have 2 instances of the same NaN, both having been obtained by multiplying zero with infinity.

However it may happen that one was obtained while computing values of a sequence that converges to 10 and the other may have been obtained by computing values of a sequence that converges to 100.

Then there is no doubt that equality is not true for this 2 NaNs.

However, those 2 NaNs may have been generated while computing values of sequences that both converge to 10, which shows that neither non-equality may be trued for these 2 NaNs.

When you have NaNs, that means that it is unknown which value, if any, the invalid operations should have produced.

When comparing 2 unknown values, you cannot know whether they are equal or not equal, so both testing for equality and for non-equality must fail.

Okay, but how could the fact that these elements are in a partially ordered set, or whatever set, trump the basic law of logic, the law of identity, "a = a"?

Or the argument is that NaNs are not actually the values themselves, but the representations of the facts of different failures, and because we can't compare the facts, we shouldn't compare NaNs? Well, I guess one could say that numbers in general are also such incomplete representations; 2 is 2, I could get 2 by adding one crayon to another crayon, or by taking 10 crayons and removing 8 of them. That doesn't stop me from comparing these 2s.