HP-UX Floating-Point Guide
164 Chapter 6
Floating-Point Trap Handling
Detecting Exceptions without Enabling Traps
Detecting Exceptions without Enabling
Traps
If you do not enable traps for floating-point exceptions, you can still
determine whether the exceptions have occurred. When an exception
occurs and the corresponding exception trap enable bit is not set, the
system sets the corresponding exception flag. The exception flags are
cumulative; once a flag is set, it remains set for the duration of the
program unless you clear it. (This is why the exception flags are also
called sticky bits.)
At critical points in your program, you can call the fetestexcept
function (described in “Manipulating the Exception Flags:
fegetexceptflag, fesetexceptflag, fetestexcept, feraiseexcept,
feclearexcept” on page 133) to determine whether an exception has
occurred. You can then respond to the exception as you wish. The
program example in that section illustrates the use of this function.
NOTE Be careful if you use these functions at higher optimization levels (2 and
above). See “Run-Time Mode Control: The fenv(5) Suite” on page 127.