NaN handling

Robert Kern robert.kern at gmail.com
Sat May 6 18:19:28 EDT 2006


Grant Edwards wrote:
> On 2006-05-06, Robert Kern <robert.kern at gmail.com> wrote:
> 
>>>>>Since numpy seems to be working on a variety of platforms/hardware,
>>>>>how hard would it be to extract this functionality from it to add to  
>>>>>Python proper?
>>>>
>>>>Harder than just enabling fpectl.
>>>
>>>Last thing I heard fpectl was considered to be completely broken -- it's
>>>likely not disabled by default for no reason.
>>
>>Fair enough. If you want to go through numpy's code to rip out its floating
>>point error handling, knock yourself out. It's not going to be trivial, though.
>>It's heavily embedded in the ufunc machinery.
> 
> Does numpy's NaN handling only work within numpy functions, or
> does it enable HW FP signals and then catch them for "normal"
> floating point operations that take place outside of numpy code?

Just in numpy code, it seems.

In [1]: import numpy
i
In [2]: import math

In [3]: numpy.seterr(invalid='raise')
Out[3]: {'over': 'ignore', 'divide': 'ignore', 'invalid': 'ignore', 'under':
'ignore'}

In [4]: numpy.log(-1.0)
---------------------------------------------------------------------------
exceptions.FloatingPointError                        Traceback (most recent call
last)

/Users/kern/<ipython console>

FloatingPointError: invalid encountered in log

In [5]: math.log(-1.0)
Out[5]: nan

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