[Python-Dev] Not-a-Number (was PyObject_RichCompareBool identity shortcut)

Stephen J. Turnbull stephen at xemacs.org
Fri Apr 29 09:10:15 CEST 2011


Terry Reedy writes:

 > > Python treats it as if it were a number:
 > 
 > As I said, so did the committee, and that was its mistake that we are 
 > more or less stuck with.

The committee didn't really have a choice.  You could ask that they
call NaNs something else, but some bit pattern is going to appear in
the result register after each computation, and further operations may
(try to) use that bit pattern.  Seems reasonable to me to apply duck-
typing and call those patterns "numbers" for the purpose of IEEE 754,
and to define them in such a way that operating on them produces a
non-NaN only when *all* numbers (including infinity) produce the same
non-NaN.

The alternative is to raise an exception whenever a NaN would be
generated (but something is still going to appear in the register; I
don't know any number that should be put there, do you?)  That is
excessively punishing to Python users and programmers, though, since
Python handles exceptions by terminating the computation.  (Kahan
points out that signaling NaNs are essentially never used for this
reason.)

Other aspects of NaN behavior may be a mistake.  But it's not clear to
me, even after all the discussion in this thread.


More information about the Python-Dev mailing list