CKTIS / Python
math.isinf
Prepozna natanko pozitivno in negativno neskončnost.
Različica: Python 3.14; repository image, production runtime not attested
Sintaksa
math.isinf(x, /)Prepozna natanko pozitivno in negativno neskončnost.
Preizkus razvrsti vrednost po pretvorbi v float. V CPythonu 3.14 pretvorba 10**400 sproži OverflowError in končni Decimal("1e400") postane pozitivna neskončnost. Obe vrednosti na seznamu dasta True. NaN prav tako ni končen, vendar ni neskončnost in da False.
Končno število, tudi nič, da False.
import math
from decimal import Decimal
assert math.isinf(Decimal("1e400")) is True
assert math.isinf(math.inf) and math.isinf(-math.inf)
assert not math.isinf(math.nan) and not math.isfinite(math.nan)
Primeri
import math
print([math.isinf(x) for x in (math.inf, -math.inf)])
print(math.isinf(math.nan))
Rezultat
[True, True] False
Končno število, tudi nič, da False.