Definition and Usage
The is_finite() function returns a boolean value. It checks whether given parameter is a legal finite number and if so the function returns TRUE, otherwise FALSE
Syntax
is_finite ( float $val ) : bool
Parameters
Sr.No | Parameter & Description |
---|---|
1 | val The value to be verified if finite or not |
Return Values
PHP is_finite() function returns TRUE if val is within accepted range of float, otherwise it returns FALSE.
PHP Version
This function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.
Example
Following example shows that 100 is a finite number
<?php $val=100; $ret=is_finite($val); if ($ret==TRUE) { echo $val . " is a finite number". "\n"; } else { echo $val . " is a not a finite number". "\n"; } ?>
Output
This will produce following result −
100 is a finite number
Example
Value of log(0) is undefined. Following example verifies if it is a finite number −
<?php $val=log(0); var_dump (is_finite($val)); ?>
Output
This will produce following result −
bool(false)
Example
Since cos(x) is between -1 and 1, acos() for parameter outside this range is NAN. −
<?php $val=acos(5); var_dump (is_finite($val)); ?>
Output
This will produce following result −
bool(false)
Example
Similarly sqrt(-1) produces NAN and hence is_finite() function returns false −
<?php $val=sqrt(-1); $ret=is_finite($val); if ($ret==TRUE) { echo $val . " is a finite number". "\n"; } else { echo $val . " is a not a finite number". "\n"; } ?>
Output
This will produce following result −
NAN is a not a finite number