In C programming the <math.h> isinf() function determine if the argument is infinity.The infinity can either be positive or negative.
|bool isinf(float x);|
|bool isinf(double x);|
|bool isinf(long double x);|
x -A floating point type value.
bool -non zero value or true(1) if the argument is infinite.
All the three functions given above are same.The only difference is in their parameter type.
printf( “\n%i” , isfinite( 123.45 ) );
printf( “\n%i” , isfinite( INFINITE ) );
The return value is 1 only in the case of INFINITE as argument.Note the ‘INFINITE’ macro represent the infinite value.
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.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 ) );
printf( “\n%i” , isfinite( -INFINITE ) );
printf( “\n%i” , isfinite( “INFINITE” ) ); //error, cannot accept string argument
Output in Code::Blocks,
Note -INFINITE is still an infinite value.