HP-UX Floating-Point Guide

Chapter 5 145
Manipulating the Floating-Point Status Register
Run-Time Mode Control: The fenv(5) Suite
If you compile and run this program, it produces results like the
following:
$ cc fe_update.c -lm
$ ./a.out
at start, env is 00000000
Enter x and y: 3 0
x and y are 3 and 0
division by zero occurred
result is inf
again? (y or n) n
setting traps for overflow and underflow
after calculations, env is 44200006
saving environment
inexact result occurred
underflow occurred
sum of squares is 12.667
after more calculations, env is 18180000
clearing underflow & inexact exceptions
after feclearexcept, env is 040c0000
merging env with saved version
after feupdateenv, env is 440c0006
division by zero occurred
Underflow Mode: fegetflushtozero and
fesetflushtozero
The functions fegetflushtozero and fesetflushtozero allow the
programmer to retrieve the current underflow mode or to change the way
the system handles underflows by setting the D bit in the status register
to either 1 or 0.
Flush-to-zero mode, also known as fast underflow mode, sudden
underflow mode, or fastmode, is an alternative to
IEEE-754-compliant underflow mode. On HP 9000 systems, a
floating-point underflow involves a fault into the kernel, where the
IEEE-754-specified conversion of the result into a denormalized value or
zero is accomplished by software emulation. On many HP 9000 systems,
flush-to-zero mode allows the hardware to simply substitute a zero for
the result of an operation, with no fault occurring. (The zero has the sign
of the result for which it is substituted.) This may be a significant
performance optimization for applications that underflow frequently and
that can tolerate the accuracy loss, in denormalized values, that results
from flush-to-zero mode. For many operations, flush-to-zero mode also
causes denormalized floating-point operands to be treated as if they were
true zero operands.