CKTIS / Python
math.nan
Udostępnia specjalną wartość float oznaczającą brak wyniku liczbowego.
Wersja: Python 3.14; repository image, production runtime not attested
Składnia
math.nanUdostępnia specjalną wartość float oznaczającą brak wyniku liczbowego.
Nawet porównanie math.nan z samym sobą przez == daje False.
Przy filtrowaniu pomiarów należy użyć math.isnan, które daje dla NaN True, a dla nieskończoności False.
import math
assert isinstance(math.nan, float) and math.nan != math.nan
assert math.isnan(math.nan) and not math.isinf(math.nan)
Przykłady
import math
print(math.nan == math.nan)
print(math.isnan(math.nan))
Wynik
False True
Przy filtrowaniu pomiarów należy użyć math.isnan, które daje dla NaN True, a dla nieskończoności False.