Portability Function: Gets, sets or clears IEEE flags for rounding direction and precision as well as queries or controls exception status. This function provides easy access to the modes and status required to use the features of IEEE Standard 754-1985 arithmetic in a Fortran program.
USE IFPORT
result = IEEE_FLAGS (action,mode,in,out)
IEEE_FLAGS is an elemental, integer-valued function that sets IEEE flags for GET, SET, CLEAR, or CLEARALL procedures. It lets you control rounding direction and rounding precision, query exception status, and control exception enabling or disabling by using the SET or CLEAR procedures, respectively.
The flags information is returned as a set of 1-bit flags.
The following example gets the highest priority exception that has a flag raised. It passes the input argument in as a null string:
USE IFPORT
INTEGER*4 iflag
CHARACTER*9 out
iflag = ieee_flags('get', 'exception', '', out)
PRINT *, out, ' flag raised'
The following example sets the rounding direction to round toward zero, unless the hardware does not support directed rounding modes:
USE IFPORT
INTEGER*4 iflag
CHARACTER*10 mode, out, in
iflag = ieee_flags('set', 'direction', 'tozero', out)
The following example sets the rounding direction to the default ('nearest'):
USE IFPORT
INTEGER*4 iflag
CHARACTER*10 out, in
iflag = ieee_flags('clear','direction', '', '' )
The following example clears all exceptions:
USE IFPORT
INTEGER*4 iflag
CHARACTER*10 out
iflag = ieee_flags('clear','exception', 'all', '' )
The following example restores default direction and precision settings, and sets all exception flags to 0:
USE IFPORT
INTEGER*4 iflag
CHARACTER*10 mode, out, in
iflag = ieee_flags('clearall', '', '', '')
The following example detects an underflow exception:
USE IFPORT
CHARACTER*20 out, in
excep_detect = ieee_flags('get', 'exception', 'underflow', out)
if (out .eq.'underflow') stop 'underflow'