PHP is_nan() Function


Definition and Usage

NAN stands for "Not A Number". The is_nan() function checks whether its argument is not a number.

Syntax

is_nan ( float $val ) : bool

Parameters

Sr.NoParameter & Description
1val
The value to be verified if infinite or not

Return Values

PHP is_nan() function returns TRUE if val is "not a number", 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 qualifies as NAN

<?php
   $val=100;
   $ret=is_nan($val);
   var_dump($val, $ret)
?>

Output

This will produce following result −

int(100)
bool(false)

Example

 Live Demo

Value of log(0) is infinity. Following example verifies if it is NAN −

<?php
   $val=log(0);
   $ret=is_nan($val);
   var_dump($val, $ret);
?>

Output

This will produce following result −

float(-INF)
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);
   $ret=is_nan($val);
   var_dump($val, $ret);
?>

Output

This will produce following result −

float(NAN)
bool(true)

Example

 Live Demo

Similarly sqrt(-1) produces NAN and hence is_nan() function returns true −

<?php
   $val=sqrt(-1);
   $ret=is_nan($val);
   var_dump($val, $ret);
?>

Output

This will produce following result −

float(NAN)
bool(true)

Updated on: 29-Jun-2020

681 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements