is_nan() function in PHP

The is_nan() function checks for 'not a number' value. It returns TRUE if the value is 'not a number', else FALSE is returned.

Syntax

is_nan(num)

Parameters

  • num − The value to check

Return Value

The is_nan() function returns TRUE if num is 'not a number', else FALSE is returned.

Example 1

Here's a simple example checking if a number is NaN −

<?php
    echo is_nan(10) ? "true" : "false";
?>
false

Example 2

Let us see another example with acos() function −

<?php
    echo is_nan(acos(1)) ? "true" : "false";
?>
false

Example 3

Example showing when is_nan() returns TRUE

<?php
    echo is_nan(acos(2)) ? "true" : "false";  // acos(2) produces NaN
?>
true

Conclusion

The is_nan() function is useful for validating mathematical operations that might produce undefined results. It's commonly used with functions like acos(), sqrt() with negative numbers, or division by zero operations.

Updated on: 2026-03-15T07:28:23+05:30

142 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements