PHP is_finite() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Math

Definition

The is_finite() function checks whether a number is a normal, finite number.

It returns false for INF, -INF and NAN, so it is a quick way to make sure a calculation did not break.

Syntax

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

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

Whole numbers are accepted too, because PHP converts an int to a float for you.

Library declarations
PHP
is_finite(float $num): bool

Parameters

ParameterDescription
numRequired. The float value to check.

Return Value

Return ValueDescription
booltrue if num is a valid finite number, false if it is INF, -INF or NAN.

PHP Examples

Example 1 — Check simple values

See which values count as finite.

PHP
<?php
echo var_export(is_finite(5.5), true) . PHP_EOL;
echo var_export(is_finite(0), true) . PHP_EOL;
echo var_export(is_finite(INF), true) . PHP_EOL;

How It Works

  1. 5.5 is a normal number, so is_finite() returns true.
  2. 0 is also finite, and the int is converted to a float automatically.
  3. INF is infinity, so the answer is false.
  4. var_export(..., true) turns the boolean into the text true or false so echo can print it.

Example 2 — NAN, negative infinity and the biggest float

Check the tricky values at the edges.

PHP
<?php
echo var_export(is_finite(NAN), true) . PHP_EOL;
echo var_export(is_finite(-INF), true) . PHP_EOL;
echo var_export(is_finite(exp(710)), true) . PHP_EOL;
echo var_export(is_finite(PHP_FLOAT_MAX), true) . PHP_EOL;

How It Works

  1. NAN means not a number, so it is not finite.
  2. -INF is negative infinity, which is also not finite.
  3. exp(710) overflows to INF, so the result is false.
  4. PHP_FLOAT_MAX is the largest float PHP can store, and it is still finite.

Example 3 — Check results of calculations

Loop over several calculations and report which ones are safe to use.

PHP
<?php
$results = [
    "10 / 4" => fdiv(10, 4),
    "1 / 0" => fdiv(1, 0),
    "0 / 0" => fdiv(0, 0),
    "sqrt(-1)" => sqrt(-1),
];

foreach ($results as $label => $value) {
    echo $label . ": " . (is_finite($value) ? "finite" : "not finite") . PHP_EOL;
}

How It Works

  1. fdiv() and sqrt() return special values instead of throwing errors.
  2. 10 / 4 gives 2.5, which is finite.
  3. 1 / 0 gives INF, and 0 / 0 and sqrt(-1) give NAN.
  4. is_finite() lets you detect all of these with a single check.

Frequently Asked Questions

It returns true when a number is a normal finite value and false when it is INF, -INF or NAN.
No. is_finite(NAN) returns false.
is_infinite() is true only for INF and -INF. is_finite() is false for INF, -INF and also NAN.
It expects a float. Numeric strings are converted, but non-numeric strings throw a TypeError in PHP 8, so check with is_numeric() first.
Use it after calculations that might overflow or divide by zero, such as exp(), fdiv() or sqrt() on user input.

Next: is_infinite()

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

is_infinite() 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