CKTIS / Python
math.isinf
Recognizes positive and negative floating-point infinity.
Version: Python 3.14; repository image, production runtime not attested
Syntax
math.isinf(x, /)Recognizes positive and negative floating-point infinity.
After conversion to float, NaN is also nonfinite but fails the infinity test.
Both signed infinities satisfy this predicate, giving two true results. NaN is nonfinite too but represents a different class, giving false in the second line. A finite number, including zero, also gives false. Classify the converted float. In CPython 3.14 an integer such as 10**400 raises OverflowError during conversion; finite Decimal("1e400") converts to positive infinity.
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)
Examples
import math
print([math.isinf(x) for x in (math.inf, -math.inf)])
print(math.isinf(math.nan))
Result
[True, True] False
Both signed infinities satisfy this predicate, giving two true results. NaN is nonfinite too but represents a different class, giving false in the second line. A finite number, including zero, also gives false. Classify the converted float. In CPython 3.14 an integer such as 10**400 raises OverflowError during conversion; finite Decimal("1e400") converts to positive infinity.