Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 9/08/2022
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

IEEE_FLAGS

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 ISO/IEC/IEEE 60559:2011 arithmetic in a Fortran program.

Module

USE IFPORT

result = IEEE_FLAGS (action,mode,in,out)

action

(Input) Character*(*). One of the following literal values: 'GET', 'SET', 'CLEAR', or 'CLEARALL'.

mode

(Input) Character*(*). One of the following literal values: 'direction', 'precision', or 'exception'.

in

(Input) Character*(*). One of the following literal values: 'inexact', 'division', 'underflow','overflow', 'invalid', 'all', 'common', 'nearest', 'tozero', 'negative', 'positive','extended', 'double', 'single', or ' ', which represents an unused (null) value.

out

(Output) Must be at least CHARACTER*9. One of the literal values listed for in.

The descriptions for the values allowed for in and out can be summarized as follows:

Value

Description

'nearest'

'tozero'

'negative'

'positive'

Rounding direction flags

'single'

'double'

'extended'

Rounding precision flags

'inexact'

'underflow'

'overflow'

'division'

'invalid'

Math exception flags

'all'

All math exception flags above

'common'

The math exception flags: 'invalid', 'division', 'overflow', and 'underflow'

The values for in and out depend on the action and mode they are used with. The interaction of the parameters can be summarized as follows:

Value of action

Value of mode

Value of in

Value of out

Functionality and return value

GET

'direction'

Null (' ')

One of 'nearest', 'tozero', 'negative', or 'positive'

Tests rounding direction settings.

Returns the current setting, or 'not available'.

'exception'

Null (' ')

One of 'inexact', 'division', 'underflow' , 'overflow', 'invalid', 'all', or 'common'

Tests math exception settings.

Returns the current setting, or 0.

'precision'

Null (' ')

One of 'single ', 'double ', or 'extended'

Tests rounding precision settings.

Returns the current setting, or 'not available'.

SET

'direction'

One of 'nearest', 'tozero', 'negative', or 'positive'

Null (' ')

Sets a rounding direction.

'exception'

One of 'inexact', 'division', 'underflow' , 'overflow', 'invalid', 'all', or 'common'

Null (' ')

Sets a floating-point math exception.

'precision'

One of 'single ', 'double ', or 'extended'

Null (' ')

Sets a rounding precision.

CLEAR

'direction'

Null (' ')

Null (' ')

Clears the mode. Sets rounding to 'nearest'.

Returns 0 if successful.

'exception'

One of 'inexact', 'division', 'underflow','overflow', 'invalid', 'all', or 'common'

Null (' ')

Clears the mode.

Returns 0 if successful.

'precision'

Null (' ')

Null (' ')

Clears the mode. Sets precision to 'double' (W*S) or 'extended' (L*X, M*X).

Returns 0 if successful.

CLEARALL

Null (' ')

Null (' ')

Null (' ')

Clears all flags. Sets rounding to 'nearest', sets precision to 'double' (W*S) or 'extended' (L*X, M*X), and sets all exception flags to 0.

Returns 0 if successful.

Results

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.

Example

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'