C++ cmath isinf function


The C++ cmath isinf test if the argument is infinity.

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

Parameters:
x – A +ve or -ve infinity value.

Return type
bool-Return 1 if the parameter is infinity else 0.

The function returns true only if the argument is infinity(+ve or -ve).If the parameter is any other type including ‘nan’ the returned value is 0.If the parameter is string type you get an error.

Link: C++ nan

Code example

/*Passing floating point value */
cout<< isinf( 23 ) << endl;

/*Passing ‘nan’ */
cout<< isinf( NAN ) << endl;

/*Passing ‘INFINITY’ */
cout<< isinf( +INFINITY ) << endl
<< isinf( -INFINITY ) << endl;

cout<< isinf( atanh(-1) ) << endl; //atanh(-1) returns ‘-inf’

/*Passing string value */
cout<< isinf( “NAN” ) << endl; //Error!

Output

0
0
1
1
1