Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

math.isfinite

Tests whether the converted floating-point value is neither infinite nor NaN.

Version: Python 3.14; repository image, production runtime not attested

Syntax

math.isfinite(x, /)

Tests whether the converted floating-point value is neither infinite nor NaN.

Signed zero is finite. Both kinds of infinity and all NaNs fail the test.

Zero passes the finite-number test. Positive infinity and NaN each fail, producing the three Booleans in the first line. Negative zero is a finite float and passes the second test. Negative infinity is excluded just like positive infinity. 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.isfinite(Decimal("1e400")) is False
assert all(math.isfinite(x) for x in (0, -0.0, 1.5))
assert not any(math.isfinite(x) for x in (math.inf, -math.inf, math.nan))

Examples

import math
print([math.isfinite(x) for x in (0, math.inf, math.nan)])
print(math.isfinite(-0.0))

Result

[True, False, False]
True

Zero passes the finite-number test. Positive infinity and NaN each fail, producing the three Booleans in the first line. Negative zero is a finite float and passes the second test. Negative infinity is excluded just like positive infinity. 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.

Sources