[Python-ideas] Disallow orderring comparison to NaN
Robert Kern
robert.kern at gmail.com
Sat Apr 30 00:11:54 CEST 2011
On 4/29/11 4:30 PM, Alexander Belopolsky wrote:
> On Fri, Apr 29, 2011 at 4:23 PM, Robert Kern<robert.kern at gmail.com> wrote:
> ..
>> (Section 7. "Exceptions") "The default response to an exception shall be to
>> proceed without a trap."
>
> I cannot find this phrase in my copy of IEEE Std 754-2008. Instead, I
> see the following in section 7.1:
>
> "This clause also specifies default non-stop exception handling for
> exception signals, which is to deliver a default result, continue
> execution, and raise the corresponding status flag."
Ah. I have the 1985 version.
> Overall, it appears that in cases where InvalidOperation was
> anticipated, it was converted to some type of exception in Python.
> Exceptions to this rule seem to be an accident of implementation.
Well, for comparisons at least, it seems to have been anticipated, and returning
a value was intentional. From the comments documenting float_richcompare() in
floatobject.c:
/* Comparison is pretty much a nightmare. When comparing float to float,
* we do it as straightforwardly (and long-windedly) as conceivable, so
* that, e.g., Python x == y delivers the same result as the platform
* C x == y when x and/or y is a NaN.
...
I'm not sure there's any evidence that the other behaviors have not been
anticipated or are accidents of implementation. The ambiguous inf operations are
documented and doctested in Lib/test/ieee754.txt.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-ideas
mailing list