HP-UX Floating-Point Guide

Chapter 6 165
Floating-Point Trap Handling
Handling Integer Exceptions
Handling Integer Exceptions
In Fortran and C there are two kinds of integer exceptions, division by
zero and overflow. Default behavior for these exceptions differs.
Handling Integer Division by Zero
Trapping on integer division by zero is enabled by default for both
Fortran and C. The trap generates a SIGFPE error. This error may be
confusing, because the error is really an integer error, and you cannot
disable or enable it by manipulating the floating-point status register
(for example, by using +FP or fesettrapenable).
If for some reason you wish to disable the trap, you can do so in Fortran
by using an ON INTEGER DIV 0 IGNORE statement. You cannot disable
the trap in C.
If you want to establish a handler for an integer division by zero, you can
do so using either of the mechanisms described in “Handling Traps” on
page 157: the C sigaction(2) function or the Fortran ON statement.
Handling Integer Overflow
Trapping on integer overflow is disabled by default for Fortran and C; an
integer overflow does not generate a SIGFPE error. Detecting integer
overflows requires not only that the trap be enabled but also that the
compiler insert special code in the executable file to check for overflows.
To enable integer overflow checking for Fortran, use a !$HP$
CHECK_OVERFLOW INTEGER ON directive (in HP Fortran/9000, use
$CHECK_OVERFLOW INTEGER_4 or INTEGER_2) to obtain the overflow
checking code, and use an ON INTEGER OVERFLOW statement to handle
the trap. (The !$HP$ CHECK_OVERFLOW directive does not enable
checking for operations in libraries. Using the exponentiation operator
involves a library call in HP Fortran, so it is not possible to enable
integer overflow checking for exponentiation operations.)
There is no way to enable integer overflow checking in C. HP C provides
no mechanism to insert overflow checking code into your executable,
because the C language does not define integer overflow as an error.