Name
isfinite
Synopsis
Tests whether a given floating-point value is a finite number
#include <math.h> intisfinite
( floatx
); intisfinite
( doublex
); intisfinite
( long doublex
);
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, ... )
// n is the number of arguments in the list
{
va_list argptr;
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
Get C in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.