nlcpy.seterr
- nlcpy.seterr(all=None, divide=None, over=None, under=None, invalid=None)[source]
Sets how floating-point errors are handled.
- Parameters
- all{‘ignore’, ‘warn’, ‘raise’, ‘print’}, optional
Sets treatment for all types of floating-point errors at once:
ignore: Take no action when the exception occurs.
warn: Print a RuntimeWarning.
raise: Raise a FloatingPointError.
print: Print a warning directly to stdout.
The default is not to change the current behavior.
- divide{‘ignore’, ‘warn’, ‘raise’, ‘print’}, optional
Treatment for division by zero.
- over{‘ignore’, ‘warn’, ‘raise’, ‘print’}, optional
Treatment for floating-point overflow.
- under{‘ignore’, ‘warn’, ‘raise’, ‘print’}, optional
Treatment for floating-point underflow.
- invalid{‘ignore’, ‘warn’, ‘raise’, ‘print’}, optional
Treatment for invalid floating-point operation.
- Returns
- old_settingsdict
Dictionary containing the old settings.
See also
Note
The floating-point exceptions are defined in the IEEE 754 standard:
Division by zero: infinite result obtained from finite numbers.
Overflow: result too large to be expressed.
Underflow: result so close to zero that some precision was lost.
Invalid operation: result is not an expressible number, typically indicates that a NaN was produced.
Restriction
If the ‘call’ mode or the ‘log’ mode is specified for each parameter, KeyError occurs.
Examples
>>> import nlcpy as vp >>> old_settings = vp.seterr(all='ignore') #seterr to known value >>> vp.seterr(over='raise') {'divide': 'ignore', 'over': 'ignore', 'under': 'ignore', 'invalid': 'ignore'} >>> vp.seterr(**old_settings) # reset to default {'divide': 'ignore', 'over': 'raise', 'under': 'ignore', 'invalid': 'ignore'}