How to check if floating point is NaN in PHP

1 Answer

0 votes
$value = acos(2); // acos(2) results in NaN because 

if (is_nan($value)) {
    echo "The value is NaN.";
} else {
    echo "The value is a valid number.";
}



/*
run:

The value is NaN.

*/

 



answered Aug 3, 2025 by avibootz
...