In C programming the <math.h> isfinite() function compute if the argument is finite or not.If we say finite argument it can be zero,normal,subnormal and not ‘infinite’ or ‘NaN'(not a number).The declaration of the function is given below.
|bool isfinite(float x);|
|bool isfinite(double x);|
|bool isfinte(long double x);|
x -A floating point type value.
bool -true(1) if the argument is finite.
All the three functions given above are same.The only difference is in their parameter type.
printf( “%i” , isfinite( nan ) );
printf( “\n%i” , isfinite( f ) );
Since ‘nan’ variable is initialized to ‘NaN’ the function return 0 and for ‘f’ the returned value is 1.
Some points to note
i)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.To understand what this means consider that we are passing a very large number -not representable by any floating point type-in this case the argument type cannot represent the value so here the argument is treated as ‘infinite’ value and the function returns false signifying that the argument is not finite.A code example is given below.
printf( “\n%i” , isfinite( 2e350 ) );
Output in Code::Blocks,
The first output is 1 because the the double type can represent the value 2e200 but the value 2e350 cannot be represented by double type.Hence this value is interpreted as infinite value and we get false as returned value.
ii) Since the function accept only floating point value if we pass a string as an argument you will get an error.
printf( “\n%i” , isfinite( “2e350” ) ); //error
Char type is acceptable as an argument by the isfinite function.