Comparisons of incompatible types
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Wed Dec 8 22:30:39 EST 2010
On Wed, 08 Dec 2010 13:01:28 -0800, John Nagle wrote:
> On 12/7/2010 3:59 PM, Mark Wooding wrote:
>>> Exactly one of
>>> >
>>> > a> b
>>> > a = b
>>> > a< b
>>> >
>>> > is true, or an type exception must be raised.
>> This will get the numerical people screaming. Non-signalling NaNs are
>> useful, and they don't obey these axioms.
>
> As a sometime numerical person, I've been screaming at this from
> the other side. The problem with comparing non-signalling NaNs is that
> eventually, the program has to make a control flow decision, and it may
> not make it correctly.
Then use signalling NANs. Nobody is suggesting that quiet NANs should be
compulsory, or are the solution for all problems. But they're a solution
for some problems, which is why people use them.
[...]
> I personally think that comparing NaN with numbers or other
> NaNs should raise an exception. There's no valid result for such
> comparisons.
If NAN and 1 are unordered, then NAN is not less or equal to 1, nor is it
larger than 1. Hence both NAN <= 1 and NAN >= 1 are false. The problem
only comes when the caller mistakenly thinks that floats are real
numbers, and tries to reason about floats like they would reason about
real numbers.
--
Steven
More information about the Python-list
mailing list