Previous Page
Next Page


Tests whether a given floating point value is an infinity

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

The macro isinf( ) yields a nonzero value (that is, TRue) if its argument is a positive or negative infinity. Otherwise, isinf( ) 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.


This function takes a short cut if it encounters an infinite addend:

double vsum( int n, va_list argptr )
  double sum = 0.0, next = 0.0;
  va_start( argptr, n );

  for ( int i = 0; i < n; i ++ )
    next = va_arg( argptr, double );
    if ( isinf( next ) )
      return next;
    sum += next;
  va_end( argptr );
  return sum;

See Also

fpclassify( ), isfinite( ), isnan( ), isnormal( ), signbit( )

Previous Page
Next Page