Developer Guide and Reference

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

IEEE Intrinsic Modules and Procedures

Fortran includes IEEE intrinsic modules that support IEEE arithmetic and exception handling. The modules contain derived data types that include named constants for controlling the level of support, and intrinsic module procedures.

To include an IEEE module in your program, specify the intrinsic module name in a USE statement; for example:

USE,INTRINSIC :: IEEE_ARITHMETIC

You must include the INTRINSIC attribute or the processor will look for a non-intrinsic module. Once you include a module, all related intrinsic procedures are defined.

Determining Availability of IEEE Features

Before using a particular IEEE feature, you can determine whether your processor supports it by using the IEEE inquiry functions (listed in below section Restrictions for IEEE Intrinsic Procedures).

For example:

  • To determine whether IEEE arithmetic is available for a particular kind of real, use intrinsic module function IEEE_SUPPORT_DATATYPE.

  • To determine whether you can change a rounding mode, use intrinsic module function IEEE_SUPPORT_ROUNDING.

  • To determine whether a divide operation will be supported with the accuracy specified by the IEEE standard, use intrinsic module function IEEE_SUPPORT_DIVIDE.

  • To determine whether you can control halting after an exception has occurred, use intrinsic module function IEEE_SUPPORT_HALTING.

  • To determine which exceptions are supported in a scoping unit, use intrinsic module function IEEE_SUPPORT_FLAG.

  • To determine whether all IEEE features are supported, use intrinsic module function IEEE_SUPPORT_STANDARD.

The compiler establishes the initial IEEE floating-point environment. The user can affect this initial environment with several different command-line options. For the IEEE intrinsic module procedures to work as defined by the Fortran Standard, the following command lines options must be set as follows:

  • Option /fpe:3 (Windows*) or -fpe3 (Linux*) must be set to disable all floating-point exceptions.

  • Option /Qftz- (Windows*) or -no-ftz (Linux*) must be set to disable flushing subnormal results to zero (notice that all optimization levels, except O0, set ftz so the user has to explicitly set "no ftz").

  • Option /fp:precise (Windows*) or option -fp-model=precise (Linux*) must be set to disable floating-point exception semantics.

Restrictions for IEEE Intrinsic Procedures

The following intrinsic procedures can only be invoked if IEEE_SUPPORT_DATATYPE is true for their arguments of type REAL:

IEEE_CLASS

IEEE_QUIET_NE

IEEE_COPY_SIGN

IEEE_REAL 2

IEEE_FMA

IEEE_REM

IEEE_IS_FINITE

IEEE_RINT

IEEE_NEGATIVE

IEEE_SCALB

IEEE_INT

IEEE_SET_ROUNDING_MODE 3

IEEE_IS_NORMAL

IEEE_SIGNALING_EQ

IEEE_LOGB

IEEE_SIGNALING_GE

IEEE_MAX

IEEE_SIGNALING_GT

IEEE_MAX_MAG

IEEE_SIGNALING_LE

IEEE_MAX_NUM

IEEE_SIGNALING_LT

IEEE_MAX_NUM_MAG

IEEE_SIGNALING_NE

IEEE_MIN

IEEE_SIGNBIT

IEEE_MIN_MAG

IEEE_SUPPORT_DENORMAL

IEEE_MIN_NUM

IEEE_SUPPORT_DIVIDE

IEEE_MIN_NUM_MAG

IEEE_SUPPORT_INF

IEEE_NEXT_AFTER

IEEE_SUPPORT_IO

IEEE_NEXT_DOWN 1

IEEE_SUPPORT_NAN

IEEE_NEXT_UP 1

IEEE_SUPPORT_ROUNDING

IEEE_QUIET_EQ

IEEE_SUPPORT_SQRT

IEEE_QUIET_GE

IEEE_SUPPORT_SUBNORMAL

IEEE_QUIET_GT

IEEE_SUPPORT_UNORDERED

IEEE_QUIET_LE

IEEE_SUPPORT_VALUE

IEEE_QUIET_LT

IEEE_VALUE

1 IEEE_SUPPORT_INF() must be true if IEEE_NEXT_DOWN is called with the argument -HUGE (X) or if IEEE_NEXT_UP is called with the argument HUGE (X).

2 IEEE_SUPPORT_DATATYPE (IEEE_REAL (A, KIND)) must also be true.

3 IEEE_SUPPORT_ROUNDING(ROUND_VALUE, X) must also be true.

For example, the IEEE_IS_NORMAL(X) function can only be invoked if IEEE_SUPPORT_DATATYPE(X) has the value true. Consider the following:

USE, INTRINSIC :: IEEE_ARITHMETIC
...
  IF IEEE_SUPPORT_DATATYPE(X) THEN
    IF IEEE_IS_NORMAL(X) THEN
      PRINT *, ' X is a "normal" '
    ELSE
      PRINT *, ' X is not "normal" '
    ENDIF
  ELSE
    PRINT *, ' X is not a supported IEEE type '
  ENDIF
...

Certain other IEEE intrinsic module procedures have similar restrictions:

  • IEEE_IS_NAN(X) can only be invoked if IEEE_SUPPORT_NAN(X) has the value true.

  • IEEE_SET_HALTING_MODE(FLAG, HALTING) can only be invoked if IEEE_SUPPORT_HALTING(FLAG) has the value true.

  • IEEE_GET_UNDERFLOW_MODE(GRADUAL) can only be invoked if IEEE_SUPPORT_UNDERFLOW_CONTROL(X) is true for some X.

For intrinsic module function IEEE_CLASS(X), some of the possible return values also have restrictions. These restrictions are also true for argument CLASS in intrinsic module function IEEE_VALUE(X, CLASS):

  • IEEE_POSITIVE_INF and IEEE_NEGATIVE_INF can only be returned if IEEE_SUPPORT_INF(X) has the value true.

  • IEEE_POSITIVE_DENORMAL, IEEE_POSITIVE_SUBNORMAL, IEEE_NEGATIVE_SUBNORMAL, and IEEE_NEGATIVE_DENORMAL can only be returned if IEEE_SUPPORT_DENORMAL(X) and IEEE_SUPPORT_SUBNORMAL(X) have the value true.

  • IEEE_SIGNALING_NAN and IEEE_QUIET_NAN can only be returned if IEEE_SUPPORT_NAN(X) has the value true.