Previous Page
Next Page

isfinite

Tests whether a given floating-point value is a finite number

#include <math.h>
int isfinite ( float x  );
int isfinite ( double x  );
int isfinite ( long double x  );

The macro isfinite( ) yields a nonzero value (that is, TRue) if its argument is not an infinite number and not a NaN. Otherwise, isfinite( ) yields 0. The argument must be a real floating-point type. The rule that floating-point types are promoted to at least double precision for mathematical calculations does not apply here; the argument's properties are determined based on its representation in its actual semantic type.

Example

double vsum( int n, va_list argptr )
// n is the number of arguments in the list
{
  double sum = 0.0, next = 0.0;
  va_start( argptr, n );
  while ( n- )
  {
    next = va_arg( argptr, double );
    sum += next;
    if ( isfinite( sum ) == 0 )
      break;                        // If sum reaches infinity, stop adding.
  }
  va_end( argptr );
  return sum;
}

See Also

fpclassify( ), isinf( ), isnan( ), isnormal( ), signbit( )


Previous Page
Next Page