numpy
allows one to handle IEEE-754 exceptions originating from floating-point by using np.seterr
appropriately. However seterr
only supports the following keywords each corresponding to a IEEE-754 exception:
divide
– Treatment for division by zero.under
– Treatment for floating-point overflow.over
– Treatment for floating-point overflow.invalid
– Treatment for invalid floating-point operation.
However, there's no keyword for the "inexact" IEEE-754 exception. How can one handle that in Python?
I am not sure, but it may be because most floating point operations raise this exception due to inherent error in representation of floating point numbers using finite precision binary numbers. The rounding is employed to fit the result into limited size and hence the numbers are inexact. This is so natural, and hence probably they expect programmers to be aware of this fact and expect them not to compare two float numbers for equality.