HP-UX Floating-Point Guide
Chapter 4 117
HP-UX Math Libraries on HP 9000 Systems
Contents of the HP-UX Math Libraries
The list of classes is exhaustive: all IEEE floating-point values fall into
one of these classes. The fpclassify macro never causes an exception,
regardless of the operand. It is useful, therefore, for classifying an
operand without risking an exception trap.
Use the signbit macro to determine whether a value is negative or
positive.
To use the fpclassify macro, compile your program in any mode
except strict ANSI mode (-Aa). Use either extended ANSI mode (-Ae, the
default), non-ANSI mode (-Ac), or -Aa -D_HPUX_SOURCE.
The following C function shows how you might use fpclassify and
signbit to display the class and value of a double-precision number:
Sample Function: print_class.c
#include <math.h>
#include <stdio.h>
typedef union {
double y;
struct {
unsigned int ym, yl;
} i;
} DBL_INT;
void print_classd(DBL_INT di)
{
int class, sign;
char *posneg[] = {"positive", "negative"};
class = fpclassify(di.y);
sign = signbit(di.y);
if (class == FP_NORMAL)
printf("%19.17g is %s normalized (%08x%08x)\n", di.y,
posneg[sign], di.i.ym, di.i.yl);
else if (class == FP_ZERO)
printf("%19.17g is %s zero (%08x%08x)\n", di.y,
posneg[sign], di.i.ym, di.i.yl);
else if (class == FP_INFINITE)
printf("%19.17g is %s infinity (%08x%08x)\n", di.y,
posneg[sign], di.i.ym, di.i.yl);
else if (class == FP_SUBNORMAL)
printf("%19.17g is %s denormalized (%08x%08x)\n", di.y,
posneg[sign], di.i.ym, di.i.yl);
else if (class == FP_NAN)
printf("%19.17g is NaN (%08x%08x), sign bit is %d\n",
di.y, di.i.ym, di.i.yl, sign);
}