Reference · Math
math.isinf
signature
math.isinf(num) -> boolWhat it does
Whether a number is positive or negative infinity, as Python's math.isinf. An int
is never infinite. A float becomes infinite when arithmetic runs past the largest
float, or when it is made so with float("inf").
Examples
print(math.isinf(float("inf")), math.isinf(float("-inf")), math.isinf(1))print(math.isinf(1e308 * 10), 1e308 * 10)output
true true falsetrue infEdge cases
- NaN is not infinite:
math.isinf(nan)is false, asmath.isfinite(nan)is. Test for it with math.isnan. - The largest float,
1.8e308, is not infinite;1e309as a literal already is. - Division by zero does not make infinity: it is a runtime error, so
math.isinfnever sees it.
print(math.isinf(float("nan")), math.isinf(1.8e308), math.isinf(1e309))output
false true trueErrors
An argument that is not a number is a runtime error, not an error value.
this one fails
print(math.isinf("inf"))output
line 1: `math.isinf` expects a number as argument 1, got strChaining
In a pipeline the number comes first:
print(1e308 * 10 | math.isinf)print([1.0, float("inf"), 3.0] | map(math.isinf))output
true[false, true, false]See also
math.isfinite, math.isnan, float
Thread
Thread 0 posts
On math.isinf(): 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