_fpclass, _fpclassl
Go Up to float.h Index
Header File
float.h
Prototype
int _fpclass(double d);
int _fpclassl(long double ld);
Description
Returns an integer value representing the type (class) of an IEEE real for doubles. This value contains information on the floating-point class of the argument.
_fpclassl is the long double version; it takes a long double argument and returns the type (class) of an IEEE real for long doubles.
Return Value
Returns an integer value that indicates the floating-point class of its argument. The possible values, which are listed in the table below, are defined in FLOAT.H.
_FPCLASS_UNSUP | Unsupported IEEE format |
_FPCLASS_SNAN | Signaling NaN |
_FPCLASS_QNAN | Quiet NaN |
_FPCLASS_NINF | Negative infinity |
_FPCLASS_NN | Negative normalized non-zero |
_FPCLASS_ND | Negative denormal |
_FPCLASS_NZ | Negative zero (-0.0) |
_FPCLASS_PZ | Positive zero (+0.0) |
_FPCLASS_PD | Positive denormal |
_FPCLASS_PN | Positive normalized non-zero |
_FPCLASS_PINF | Positive infinity |
Portability
POSIX | ANSI C | ANSI C++ | Win32 | Win64 | OS X | |
---|---|---|---|---|---|---|
_fpclass | + | |||||
_fpclassl | + |
Example
#include <float.h>
#include <stdio.h>
/* Compare a and b */
int compare(double a, double b) {
/* Only if both are finite. */
if (_finite(a) && _finite(b)) {
if (a < b)
return -1;
else if (a > b)
return 1;
else
return 0;
}
else {
/* For infinite values check the class of the numbers */
int class_a = _fpclass(a);
int class_b = _fpclass(b);
/* No check the infinities and compare them */
if (class_a == _FPCLASS_NINF) {
if (class_b == _FPCLASS_NINF)
return 0;
else
return -1;
}
else if (class_a == _FPCLASS_PINF) {
if (class_b == _FPCLASS_PINF)
return 0;
else
return 1;
}
}
/* Cannot find a relationship! */
return -1;
}