C++ cmath isfinite() function


The C++ <cmath> isfinte function main purpose is to determine if the argument is finite or not.

bool isfinite(float x);
bool isfinite(double x);
bool isfinte(long double x);

Parameters:
x – Float or double or long double type.

Return type
bool– 1 if the parameter is finite and 0 if infinity.

The argument is considered as finite for normal,zero and subnormal type.Any infinite value or ‘nan’ is considered infinity.Passing string type as an argument gives an error,since string cannot be represented in floating point format.

Link: C++ nan

Code example

/*Passing floating point value*/
cout<< isfinite(9.23 ) << endl
<< isfinite(‘B’) << endl;

/*Passing zero*/
cout<< isfinite( 0 ) << endl;

/*Passing nan*/
cout<< isfinite( sqrt(-3) ) << endl
<< isfinite(NAN) << endl;

/*Passing ‘infinity’ */
cout<< isfinite( INFINITY ) << endl;

/*Passing string*/
cout<< isfinite( “031.23”) << endl ; //error!

Output

1
1
1
0
0
0