PHP is_finite() Function

PHPServer Side ProgrammingProgramming

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

 Live Demo

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

 Live Demo

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

 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_finite($val));
?>

Output

This will produce following result −

bool(false)

Example

 Live Demo

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
raja
Published on 29-Jun-2020 12:32:19
Advertisements