HP-UX Floating-Point Guide
Chapter 6 155
Floating-Point Trap Handling
Enabling Traps
Sample Program: overflow_trap.f
PROGRAM OVERFLOW_TRAP
C F90:
!$HP$ ALIAS FESETTRAPENABLE = 'fesettrapenable' (%val)
C F77:
C $ALIAS FESETTRAPENABLE = 'fesettrapenable' (%val)
PARAMETER (FE_OVERFLOW = Z'20000000')
EXTERNAL FESETTRAPENABLE
DOUBLE PRECISION X, Y, Z
CALL FESETTRAPENABLE(FE_OVERFLOW)
X = 1.79D308
Y = 2.2D-308
Z = X / Y
WRITE(*,*) X, ' divided by', Y, ' = ', Z
END
You do not need to specify any options when you compile this program,
but you need to link in the C math library. The result is similar to that in
the preceding section:
$ f90 overflow_trap.f -lm
overflow_trap.f
program OVERFLOW_TRAP
13 Lines Compiled
$ ./a.out
Floating exception (core dumped)
Using the +fp_exception or +T Compiler
Option (Fortran only)
The +fp_exception option, available with the HP Fortran 90 compiler,
enables traps for four IEEE exceptions: invalid operation, division by
zero, overflow, and underflow. (Few programs need to trap for the inexact
exception, which occurs often and conveys little information.) The HP
FORTRAN/9000 equivalent is +T. For Fortran applications, these options
have the simplicity of +FP. They also provides more information than
either +FP or fesettrapenable. They tell what kind of exception
occurred and the virtual address of the statement that triggered the
exception. Moreover, they do not cause a core dump.