array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'en', ), 'this' => array ( 0 => 'function.is-nan.php', 1 => 'is_nan', 2 => 'Checks whether a float is NAN', ), 'up' => array ( 0 => 'ref.math.php', 1 => 'Math Functions', ), 'prev' => array ( 0 => 'function.is-infinite.php', 1 => 'is_infinite', ), 'next' => array ( 0 => 'function.log.php', 1 => 'log', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/math/functions/is-nan.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>

is_nan

(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

is_nanChecks whether a float is NAN

Description

is_nan(float $num): bool

Returns whether the given num is NAN (Not A Number).

NAN is returned from mathematical operations that are undefined, for example when passing parameters outside of function’s input domain. The square root (sqrt()) is only defined for positive numbers, passing a negative number will result in NAN. Other examples of operations returning NAN are dividing INF by INF and any operation involving an existing NAN value.

Note:

Despite its name of Not A Number, NAN is a valid value of type float.

Caution

NAN does not compare equal to NAN. To check whether a float is NAN, is_nan() must be used. Checking $float === NAN will not work.

Parameters

num

The float to check

Return Values

true if num is NAN, else false.

Examples

Example #1 is_nan() example

<?php
$nan
= sqrt(-1);

var_dump($nan, is_nan($nan));
?>

The above example will output:

float(NAN)
bool(true)

See Also