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

Guido van Rossum guido at python.org
Fri Apr 29 19:11:35 CEST 2011


On Fri, Apr 29, 2011 at 12:10 AM, Stephen J. Turnbull
<stephen at xemacs.org> wrote:
> Other aspects of NaN behavior may be a mistake.  But it's not clear to
> me, even after all the discussion in this thread.

ISTM that the current behavior of NaN (never mind the identity issue)
helps numeric experts write better code. For naive users, however, it
causes puzzlement if they ever run into it.

Decimal, for that reason, has a context that lets one specify
different behaviors when a NaN is produced. Would it make sense to add
a float context that also lets one specify what should happen? That
could include returning Inf for 1.0/0.0 (for experts), or raising
exceptions when NaNs are produced (for the numerically naive like
myself).

I could see a downside too, e.g. the correctness of code that
passingly uses floats might be affected by the context settings.
There's also the question of whether the float context should affect
int operations; floats vs. ints is another can of worms since (in
Python 3) we attempt to tie them together through 1/2 == 0.5, but ints
have a much larger range than floats.

-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-Dev mailing list