When is min(a, b) != min(b, a)?

Pete Forman pete.forman at westerngeco.com
Thu Jan 24 17:51:16 CET 2008


Christian Heimes <lists at cheimes.de> writes:

 > Antoon Pardon wrote:
>> That doesn't follow. The problem is not that x < nan returns False
>> because that is correct since x isn't smaller than nan. The problem 
>> is cmp(x, nan) returning 1, because that indicates that x is greater
>> than nan and that isn't true.
>
 > Please report the problem. cmp(), min() and max() don't treat NaNs
 > right. I don't think that x < nan == False is the correct answer, too.
 > But I've to check the IEEE 754 specs. IMHO < nan and > nan should raise
 > an exception.

I disagree with your last sentence.  We are dealing with quiet NaNs
which should not raise exceptions.  x < nan is well defined in IEEE,
it is false.

IMHO cmp() should raise an exception if one or more arguments is a
NaN.  Its current definition is to return an integer which may be
negative, zero, or positive for less than, equal, or greater than.
There is no spec for unordered, and the integer returned cannot be
NaN.

I'd be happy if min() and max() behaved as if their comparison
operations were minNum and maxNum from IEEE.  In other words they
never return NaN unless all their arguments are NaN.

int(nan) should raise an exception.  I note that in Python 2.5.1
int(inf) already does.
-- 
Pete Forman                -./\.-  Disclaimer: This post is originated
WesternGeco                  -./\.-   by myself and does not represent
pete.forman at westerngeco.com    -./\.-   the opinion of Schlumberger or
http://petef.port5.com           -./\.-   WesternGeco.



More information about the Python-list mailing list