Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php
nan
math
communitycreator

What is is_nan() in PHP?

Harris Amjad

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The is_nan() function in PHP returns true (1) if the value is NaN; otherwise, it returns false. Some of the operations that can return a NaN include: division by zero, calculating the square root of a negative number, trying to pass an invalid value to an inverse trigonometric function, and the arc cosine of a value that does not lie in the range negative one to one.

Figure 1 shows the visual representation of the is_nan() function.

Figure 1: Visual representation of is_nan() function

Syntax

bool is_nan(number)

Parameter

This function requires the number as a parameter.

Return value

This function returns true (1) if the value is NaN; otherwise, it returns false.

Example

The following example shows how to use is_nan() in PHP.

<?php
#number
echo("is_nan(10): ");
echo (is_nan(10));
echo("\n");
echo("is_nan(-5.3): ");
echo (is_nan(5.3));
echo("\n");
?>
<?php
#nan
echo("is_nan(0/0): ");
echo (is_nan(0/0));
echo("\n");
echo("is_nan(acos(2)): ");
echo (is_nan(acos(2)));
?>

RELATED TAGS

php
nan
math
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring