PHP is_infinite() Function


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.NoParameter & Description
1val
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

 Live Demo

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". "
";    } else {       echo $val . " is a not an infinite number". "
";    } ?>

Output

This will produce following result −

100 is not an infinite number

Example

 Live Demo

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

 Live Demo

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

 Live Demo

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". "
";    } else {       echo $val . " is not an infinite number". "
";    } ?>

Output

This will produce following result −

NAN is not an infinite number

Updated on: 29-Jun-2020

183 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements