PHP is_infinite() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Math

Definition

The is_infinite() function checks whether a number is positive or negative infinity.

Infinity appears when a calculation becomes too large or when you divide by zero using fdiv().

Syntax

Call is_infinite() with the values you need. Start with this line.

PHP
You pass a number to is_infinite() and it returns true or false.
CallWhat it does
is_infinite(INF)Returns true.
is_infinite(-INF)Returns true.
is_infinite(5.5)Returns false.

is_infinite() is false for NAN. Use is_nan() to check for not-a-number values.

Library declarations
PHP
is_infinite(float $num): bool

Parameters

ParameterDescription
numRequired. The float value to check.

Return Value

Return ValueDescription
booltrue if num is INF or -INF, otherwise false.

PHP Examples

Example 1 — Detect infinity

Check positive infinity, negative infinity and a normal number.

PHP
<?php
echo var_export(is_infinite(INF), true) . PHP_EOL;
echo var_export(is_infinite(-INF), true) . PHP_EOL;
echo var_export(is_infinite(5.5), true) . PHP_EOL;

How It Works

  1. INF is a built-in PHP constant for positive infinity.
  2. -INF is negative infinity, which also counts as infinite.
  3. 5.5 is a normal number, so the result is false.
  4. var_export(..., true) converts the boolean into printable text.

Example 2 — NAN and the largest float

See what is not counted as infinite.

PHP
<?php
echo var_export(is_infinite(NAN), true) . PHP_EOL;
echo var_export(is_infinite(PHP_FLOAT_MAX), true) . PHP_EOL;
echo var_export(is_infinite(PHP_FLOAT_MAX * 2), true) . PHP_EOL;

How It Works

  1. NAN is not infinity, so is_infinite(NAN) is false.
  2. PHP_FLOAT_MAX is huge but still a real, finite number.
  3. Multiplying it by 2 overflows and the result becomes INF.
  4. That is how overflow turns into infinity in PHP.

Example 3 — Detect overflow in a calculation

Warn the user when a result is too large to use.

PHP
<?php
$values = [exp(2), exp(710)];

foreach ($values as $index => $value) {
    $status = is_infinite($value) ? "overflow" : "ok";
    echo "Value " . ($index + 1) . ": " . $status . PHP_EOL;
}

How It Works

  1. exp(2) is about 7.39, which is a normal number.
  2. exp(710) is too large for a float, so PHP returns INF.
  3. is_infinite() returns false for the first value and true for the second.
  4. The ternary operator turns the result into the text ok or overflow.

Frequently Asked Questions

It returns true if the number is INF or -INF, and false for every other value.
No. NAN is not infinity. Use is_nan() to detect it.
Through overflow, like exp(710), or by dividing by zero with fdiv(1, 0).
Use the INF constant. -INF gives negative infinity.
is_finite() is true only for normal numbers. is_infinite() is true only for INF and -INF.

Next: is_nan()

The is_nan() function checks whether a value is NAN, which stands for Not A Number.

is_nan() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful