When is min(a, b) != min(b, a)?
steve at REMOVE-THIS-cybersource.com.au
Fri Jan 25 01:09:58 CET 2008
On Thu, 24 Jan 2008 16:51:16 +0000, Pete Forman wrote:
> 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.
I question that. The IEEE standard states that comparisons involving NaNs
are unordered and should signal INVALID. What that means at the high
level of x < NAN (etc.) isn't clear.
I'm having a lot of trouble finding the canonical IEEE-754 standard, so
I'm forced to judge by implementations and third party accounts. For
example, this is what IBM says:
The IEEE standard defines several exception conditions that can occur:
Operations are performed on values for which the results are not defined.
Operations on signaling NaN values
Comparisons involving NaN values
Note that *only* sNaNs signal invalid on arithmetic operations, but
*both* types of NaNs signal invalid on comparisons.
The same page also lists a table showing the result of such signals. I
won't reproduce the whole table, but it states that the INVALID signal
results in a NaN if exceptions are disabled, and no result (naturally) if
exceptions are enabled.
SANE (Standard Apple Numerics Environment) and Apple's PowerPC Numerics
also do the same. See for example:
...when x or y is a NaN, x < y being false might tempt you to conclude
that x >= y, so PowerPC Numerics signals invalid to help you avoid the
Regardless of deep philosophical questions about truth, that's a great
example of Practicality Beats Purity. And some of us think that raising
an exception would not only be more practical, but also more pure as well.
More information about the Python-list