php8.5
Home/ Manual/ math / functions/ is_finite

is_finite

PHP function Edit on GitHub ✎

(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

Checks whether a float is finite

Description

is_finite(float $num): bool

Returns whether the given num is a finite float.

A finite float is neither NAN (is_nan()), nor infinite (is_infinite()).

Parameters

num

The Float to check

Return Values

true if num is none of NAN, INF, -INF, else false.

Examples

is_finite() example

php
<?php
$float = 1.2345;
var_dump($float, is_finite($float));

$nan = sqrt(-1);
var_dump($nan, is_finite($nan));

$inf = 1e308 * 2;
var_dump($inf, is_finite($inf));
?>

The above example will output:

output
float(1.2345)
bool(true)
float(NAN)
bool(false)
float(INF)
bool(false)

See Also

Source: reference/math/functions/is-finite.xml · from the official PHP manual (php/doc-en)