C programming math.h isnan


In C programming the <math.h> isnan() function determine if the argument is NaN(Not a Number).

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

Parameters:
x -A floating point value.

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

All the three functions given above are same.The only difference is in their parameter type.

Link :C and C++ nan :myths and conception

Code example

printf( “%i” , isfinite( NAN ) );
printf( “\n%i” , isfinite( 123.45 ) );

Output,

1
0

In C the ‘NAN’ macro represent the ‘NaN’ value.Hence the first output is 1 and the second output obviously is 0.






Some points to note

The function will determine the argument base on the specific semantic types.This means if the argument passed is wider than it’s semantic type than it is converted to it’s semantic type and the determination is based on that type.

Code example

printf( “%i” , isfinite( -NAN ) );

printf( “\n%i” , isfinite( 2e350 ) );

printf( “\n%i” , isfinite( “NAN” ) ); //error,a string type pass as argument

Output,

1
0