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