CKTIS / Python
math.isinf
Wykrywa dokładnie dodatnią i ujemną nieskończoność.
Wersja: Python 3.14; repository image, production runtime not attested
Składnia
math.isinf(x, /)Wykrywa dokładnie dodatnią i ujemną nieskończoność.
Oceniana jest wartość po konwersji na float. W CPythonie 3.14 konwersja 10**400 zgłasza OverflowError, a skończone Decimal("1e400") zamienia się w dodatnią nieskończoność. Obie wartości z listy dają True. NaN także nie jest liczbą skończoną, ale nie jest nieskończonością i daje False.
Liczba skończona, również zero, daje 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)
Przykłady
import math
print([math.isinf(x) for x in (math.inf, -math.inf)])
print(math.isinf(math.nan))
Wynik
[True, True] False
Liczba skończona, również zero, daje False.