On Tue, Jul 8, 2014 at 5:01 PM, Stephen J. Turnbull <step...@xemacs.org> wrote: > I agree with Steven d'A that this rule is not part of the language > definition and shouldn't be, but it's the rule of thumb I find hardest > to imagine *ever* wanting to break in my own code (although I sort of > understand why the IEEE 754 committee found they had to).
The reason NaN isn't equal to itself is because there are X bit patterns representing NaN, but an infinite number of possible non-numbers that could result from a calculation. Is float("inf")-float("inf") equal to float("inf")/float("inf")? There are three ways NaN equality could have been defined: 1) All NaNs are equal, as if NaN is some kind of "special number". 2) NaNs are equal if they have the exact same bit pattern, and unequal else. 3) All NaNs are unequal, even if they have the same bit pattern. The first option is very dangerous, because it'll mean that "NaN pollution" can actually result in unexpected equality. The second looks fine - a NaN is equal to itself, for instance - but it suffers from the pigeonhole problem, in that eventually you'll have two numbers which resulted from different calculations and happen to have the same bit pattern. The third is what IEEE went with. It's the sanest option. ChrisA _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com