Intel® Fortran Compiler 17.0 Developer Guide and Reference
Portability Function: Establishes a handler for IEEE exceptions.
USE IFPORT
result = IEEE_HANDLER (action, exception, handler)
action |
(Input) Character*(*). One of the following literal IEEE actions: 'GET', 'SET', or 'CLEAR'. For more details on these actions, see IEEE_FLAGS. |
exception |
(Input) Character*(*). One of the following literal IEEE exception flags: 'inexact', 'underflow', 'overflow', 'division', 'invalid', 'all' (which equals the previous five flags), or 'common' (which equals 'invalid', 'overflow', 'underflow', and 'division'). The flags 'all' or 'common' should only be used for actions SET or CLEAR. |
handler |
(Input) The address of an external signal-handling routine. |
The result type is INTEGER(4) on IA-32 architecture; INTEGER(8) on Intel® 64 architecture. The result is 0 if successful; otherwise, 1.
IEEE_HANDLER calls a signal-handling routine to establish a handler for IEEE exceptions. It also enables an FPU trap corresponding to the required exception.
The state of the FPU is not defined in the handler routine. When the FPU trap occurs, the program invokes the handler routine. After the handler routine is executed, the program terminates.
The handler routine gets the exception code in the SIGINFO argument. SIGNO is the number of the system signal. The meaning of the SIGINFO constants appear in the following table (defined in the IFPORT module):
FPE$INVALID |
Invalid operation |
FPE$ZERODIVIDE |
Divide-by-zero |
FPE$OVERFLOW |
Numeric overflow |
FPE$UNDERFLOW |
Numeric underflow |
FPE$INEXACT |
Inexact result (precision) |
'GET' actions return the location of the current handler routine for exception cast to an INTEGER.
The following example creates a handler routine and sets it to trap divide-by-zero:
PROGRAM TEST_IEEE
REAL :: X, Y, Z
CALL FPE_SETUP
X = 0.
Y = 1.
Z = Y / X
END PROGRAM
SUBROUTINE FPE_SETUP
USE IFPORT
IMPLICIT NONE
INTERFACE
SUBROUTINE FPE_HANDLER(SIGNO, SIGINFO)
INTEGER(4), INTENT(IN) :: SIGNO, SIGINFO
END SUBROUTINE
END INTERFACE
INTEGER IR
IR = IEEE_HANDLER('set','division',FPE_HANDLER)
END SUBROUTINE FPE_SETUP
SUBROUTINE FPE_HANDLER(SIG, CODE)
USE IFPORT
IMPLICIT NONE
INTEGER SIG, CODE
IF(CODE.EQ.FPE$ZERODIVIDE) PRINT *,'Occurred divide by zero.'
CALL ABORT
END SUBROUTINE FPE_HANDLER