numarray.ieeespecial has support for manipulating IEEE-754 floating
point special values NaN (Not a Number), Inf (infinity), etc. The special
values are denoted using lower case as follows:
Note that the representation of IEEE special values is platform dependent so
your Python might for instance say Infinity rather than inf.
Below, inf is seen to arise as the result of floating point division by 0
and nan is seen to arise from 0 divided by 0:
>>> a = array([0.0, 1.0])
>>> b = a/0.0
Warning: Encountered invalid numeric result(s) in divide
Warning: Encountered divide by zero(s) in divide
>>> b
array([ nan, inf])
A curious property of nan is that it does not compare to itself as
equal:
>>> b == ieee.nan
array([0, 0], type=Bool)
The isnan, isinf, and isfinite functions
return boolean arrays which have the value True where the corresponding
predicate holds. These functions detect bit ranges and are therefore more
robust than simple equality checks.