_finite, _finitel
Go Up to float.h Index
Header File
float.h
Prototype
int _finite(double d);
int _finitel(long double ld);
Description
Determines whether a given double-precision floating point value d is finite.
_finitel is the long double version; it takes a long double argument.
Return Value
Returns non-zero if the argument is finite, and 0 if it is not.
Portability
POSIX | ANSI C | ANSI C++ | Win32 | Win64 | macOS | |
---|---|---|---|---|---|---|
_finite | + | |||||
_finitel | + |
Example
#include <float.h>
#include <stdio.h>
/* Compare a and b if both have finite values */
int compare(double a, double b) {
/* Only if both are finite. Otherwise give an indefinite ordering */
if (_finite(a) && _finite(b)) {
if (a < b)
return -1;
else if (a > b)
return 1;
else
return 0;
}
else
return -1;
}