HP-UX Floating-Point Guide

Chapter 5 147
Manipulating the Floating-Point Status Register
Run-Time Mode Control: The fenv(5) Suite
Sample Program: fe_flush.c
/*************************************************************/
#include <stdio.h>
#include <fenv.h>
typedef union {
double y;
struct {
unsigned int ym, yl;
} i;
} DBL_INT;
int main(void)
{
DBL_INT dix, diy, diz;
int fm, fm_saved;
fm_saved = fegetflushtozero();
printf("underflow mode is %d\n", fm_saved);
dix.y = -4.94066e-324;
printf("denormalized value is %g [%08x%08x]\n", dix.y,
dix.i.ym, dix.i.yl);
fesetflushtozero(1);
fm = fegetflushtozero();
printf("after fesetflushtozero(1), mode is %d\n", fm);
printf("denormalized value is %g [%08x%08x]\n", dix.y,
dix.i.ym, dix.i.yl);
fesetflushtozero(fm_saved);
fm = fegetflushtozero();
printf("after fesetflushtozero(%d), mode is %d\n",
fm_saved, fm);
printf("denormalized value is %g [%08x%08x]\n", dix.y,
dix.i.ym, dix.i.yl);
}
/*************************************************************/
If you run this program on a system that supports flush-to-zero mode, it
produces the following output:
$ cc fe_flush.c -lm
$ ./a.out
underflow mode is 0
denormalized value is -4.94066e-324 [8000000000000001]
after fesetflushtozero(1), mode is 1
denormalized value is -0.00000 [8000000000000001]
after fesetflushtozero(0), mode is 0
denormalized value is -4.94066e-324 [8000000000000001]