Developer Guide and Reference

ID 767251
Date 10/31/2024
Public
Document Table of Contents

IEEE_HANDLER

Portability Function: Establishes a handler for IEEE exceptions.

Module

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.

Results

The result type is INTEGER(8). 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.

Example

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

See Also