is_nan
Checks whether a value is "not a number" (NAN).
Syntax
is_nan(float $num): boolParameters
| Parameter | Type | Description |
|---|---|---|
| $num | float | The value to check. |
Return value
bool`true` if the value is `NAN`.
Examples
The square root of a negative number:
<?php
$result = sqrt(-1);
var_dump(is_nan($result));
var_dump($result === $result);Output:
bool(true)
bool(false)Notes
NAN equals nothing, not even itself, so a === NAN comparison does not work. Infinity is checked with is_infinite().
See also
- is_numeric — Checks whether a value is a number or a numeric string.
- is_float — Checks whether a value is a float.
- sqrt — Returns the square root of a number.
In the tutorial
- Numbers and maths — PHP's maths functions — rounding, number formatting, random numbers and the precision of fractions.