Reference · Math
math.isfinite
math.isfinite(num) -> boolWhat it does
Whether a number is neither infinite nor NaN, as Python's math.isfinite. Every int
is finite; a float is finite unless arithmetic ran past the largest float or had no
answer. It is the test to run before storing a computed float or sending it as JSON.
Examples
print(math.isfinite(1), math.isfinite(2.5), math.isfinite(1e308))print(math.isfinite(float("inf")), math.isfinite(float("nan")))true true truefalse falseEdge cases
- The largest int is finite; so are
0.0and-0.0. - A float that overflowed is infinite and so not finite:
1e308 * 10isinf. inf - infis NaN, and not finite either.
print(math.isfinite(9223372036854775807), math.isfinite(-0.0))print(math.isfinite(1e308 * 10), math.isfinite(float("inf") - float("inf")))true truefalse falseErrors
An argument that is not a number is a runtime error, not an error value: text, null
and a decimal are refused rather than reported as not finite.
print(math.isfinite("1"))line 1: `math.isfinite` expects a number as argument 1, got strChaining
In a pipeline the number comes first. Dropping the values that cannot be charted:
print(1e308 * 10 | math.isfinite)print([1.5, float("inf"), 2.5, float("nan")] | filter(math.isfinite))false[1.5, 2.5]See also
math.isinf, math.isnan, math.isclose, float
Thread 0 posts
On math.isfinite(): questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.
Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo