Are there any python library functions that discriminate between regular floating point numbers, and all of the atypical ones, NaN, +/-Inf, denormal etc.?
Essentially, I'm asking the Python version of this question: check if floating point variable has 'normal' values
To check if a float x is finite, just use math.isfinite(x).
To check if a float x is denormal (subnormal), here is a possible snippet:
import numpy
x = 1.0e-320
fmin_normalized = numpy.finfo(type(x)).tiny
x_is_subnormal = numpy.isfinite(x) and x!= 0 and abs(x) < fmin_normalized
print(x_is_subnormal)
I let you finish the work (write the appropriate lambda and filter the collection)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With