CKTIS / Python
math.nan
Fornece o valor float especial que indica a ausência de resultado numérico.
Versão: Python 3.14; repository image, production runtime not attested
Sintaxe
math.nanFornece o valor float especial que indica a ausência de resultado numérico.
Mesmo comparar math.nan consigo próprio através de == dá False.
Para filtrar medições, math.isnan dá True para NaN e False para o infinito.
import math
assert isinstance(math.nan, float) and math.nan != math.nan
assert math.isnan(math.nan) and not math.isinf(math.nan)
Exemplos
import math
print(math.nan == math.nan)
print(math.isnan(math.nan))
Resultado
False True
Para filtrar medições, math.isnan dá True para NaN e False para o infinito.