C++ cmath isnan function


The C++ cmath isnan function check if the argument is NAN.

bool isnan(float x);
bool isnan(double x);
bool isnan(long double x);

Parameters:
x -A floating point value which is to be checked for NAN.

Return type
bool -Returns true if it is NAN else 0.

Only when the parameter is NAN you get true,for all other values you get 0.If string is passed you get an error.

Link: C++ nan

Code example

/*passing floating-point value*/
cout<< isnan(23) << endl ;

/*Passing NAN*/
cout<< isnan(NAN) << endl
<< isnan( atanh(2)) << endl ;

/*Passing string */
cout<< isnan(“NAN”) << endl; //error

Output

0
1
1