HP-UX Floating-Point Guide
154 Chapter 6
Floating-Point Trap Handling
Enabling Traps
If you compile this program with traps disabled (the default), it produces
the following output:
1.7900+308 divided by 2.2000-308 = +INF
If you compile it with the +FP option, however, you get a core dump. (The
O flag of the +FP option enables traps for overflow exceptions.)
$ f90 +FPO overflow.f
overflow.f
program OVERFLOW
11 Lines Compiled
$ ./a.out
Floating exception (core dumped)
Using the fesettrapenable Function
The fesettrapenable function is part of the fenv(5) suite and is
described in detail in “Exception Bits” on page 132. It is provided in the
C math library.
The fesettrapenable routine can enable one or more traps in any
combination.
Using fesettrapenable to enable traps has the same disadvantages as
the +FP option. You get a core dump, and you cannot determine the
exception type.
NOTE Do not use this function at an optimization level greater than 0. See
“Run-Time Mode Control: The fenv(5) Suite” on page 127. (You may
instead use the FLOAT_TRAPS_ON pragma to suppress optimization.)
Here is the program from “Using the +FP Compiler Option” on page 153,
modified to enable a trap for the overflow exception using
fesettrapenable. It does this by using an !$HP$ ALIAS or $ALIAS
directive to tell the Fortran compiler that the function’s arguments are
passed by value.