NaN handling

Robert Kern robert.kern at gmail.com
Sat May 6 00:25:58 CEST 2006


Ivan Vinogradov wrote:
>><snip>
>>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.
> 
> Our programming expectations may differ, but an option to catch NaNs as
> an exception is a great idea.

numpy lets the programmer control how NaNs are handled in numpy code. Producing
a NaN can be ignored, create a warning, raise an exception or call a function.
It's not well documented at the moment, but the functions are seterr(),
seterrcall(), seterrobj(), geterr(), geterrcall(), and geterrobj().

Pure Python has a similar, but somewhat less flexible method, on UNIX platforms.

  http://docs.python.org/dev/lib/module-fpectl.html

-- 
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-list mailing list