Set how floating-point errors are handled.
Note that operations on integer scalar types (such as int16) are handled like floating point, and are affected by these settings.
Parameters: | all : {‘ignore’, ‘warn’, ‘raise’, ‘call’}, optional
divide : {‘ignore’, ‘warn’, ‘raise’, ‘call’}, optional
over : {‘ignore’, ‘warn’, ‘raise’, ‘call’}, optional
under : {‘ignore’, ‘warn’, ‘raise’, ‘call’}, optional
invalid : {‘ignore’, ‘warn’, ‘raise’, ‘call’}, optional
|
---|---|
Returns: | old_settings : dict
|
Notes
The floating-point exceptions are defined in the IEEE 754 standard [1]:
[102] | http://en.wikipedia.org/wiki/IEEE_754 |
Examples
Set mode:
>>> seterr(over='raise') # doctest: +SKIP
{'over': 'ignore', 'divide': 'ignore', 'invalid': 'ignore',
'under': 'ignore'}
>>> old_settings = seterr(all='warn', over='raise') # doctest: +SKIP
>>> int16(32000) * int16(3) # doctest: +SKIP
Traceback (most recent call last):
File "<stdin>", line 1, in ?
FloatingPointError: overflow encountered in short_scalars
>>> seterr(all='ignore') # doctest: +SKIP
{'over': 'ignore', 'divide': 'ignore', 'invalid': 'ignore',
'under': 'ignore'}