NaN handling

Grant Edwards grante at visi.com
Fri May 5 16:55:56 EDT 2006


On 2006-05-05, Ivan Vinogradov <vinogri at mcmaster.ca> wrote:
>
>> <snip>
>> NaNs are handled.
>
> Throwing an exception would be nice in regular Python (non-scipy).

That would break most of my Python programs (at least most of
the ones in which I do floating point).  My main problem with
NaNs (and Infs) is that there isn't a string represention that
is consistent across platforms.

> This works to catch NaN on OSX and Linux:
>
> # assuming x is a number
> if x+1==x or x!=x:
> 	#x is NaN
>
> But is expensive as a precautionary measure. Assert can be
> used for testing, if production code can be run with -0 or
> -OO.

There are those of us that need NaNs in production code, so it
would have to be something that could be configured.  I find
that in my programs the places where I need to do something
"exceptional" with a NaN are very limited.  The vast majority
of the time, I need them to propagate quietly.

-- 
Grant Edwards                   grante             Yow!  Thousands of days of
                                  at               civilians... have produced
                               visi.com            a... feeling for the
                                                   aesthetic modules --



More information about the Python-list mailing list