the IEEE Standard for Floating-Point Arithmetic (IEEE 754) requires the existence of a float
(or two...) that is called nan
(not a number).
there are two ways to get nan
(that i know of)
nan = float("nan")
# or
from math import nan
but is there a mathematical function i can perform on floats
in the standard library that returns nan
?
the obvious ideas like math.sqrt(-1)
(and similar) do not return nan
but raise ValueError: math domain error
.
or are nan
s only meant for data where values are missing and are never supposed to be returned by a function?
(is there also something that returns math.inf
? again, the obvious 1/0
raises a ZeroDivisionError
).