Fortran Wiki
ieee_arithmetic

The module ieee_arithmetic is an intrinsic module defined in the technical report ISO/IEC TR 15580:1998(E) which provides IEEE arithmetic facilities.

IEEE Datatype Selection

selected_real_kind

integer function selected_real_kind(p,r)
   integer(kind1), optional :: p
   integer(kind2), optional :: r

This function behaves like the selected_real_kind intrinsic, but only returns numbers of of IEEE kinds of reals.

General Inquiry Functions

ieee_support_datatype

logical function ieee_support_datatype(x)
   real(kind), optional :: x

Returns .true. if IEEE arithmetic is supported for the same kind of real as x (or for all real kinds if x is absent).

ieee_support_denormal

logical function ieee_support_denormal(x)
   real(kind), optional :: X

Returns .true. if IEEE denormal values are supported for the same kind of real as x (or for all real kinds if x is absent).

ieee_support_divide

logical function ieee_support_divide(x)
   real(kind), optional :: x

Returns .true. if division up to IEEE-specified accuracy is supported for the same kind of real as x (or for all real kinds if x is absent).

ieee_support_inf

logical function ieee_support_inf(x)
   real(kind), optional :: x

Returns .true. if IEEE infinite values are supported for the same kind of real as x (or for all real kinds if x is absent).

ieee_support_nan

logical function ieee_support_nan(x)
   real(kind), optional :: x

Returns .true. if IEEE NaN (Not-a-Number) values are supported for the same kind of real as x (or for all real kinds if x is absent).

ieee_support_sqrt

logical function ieee_support_sqrt(x)
   real(kind), optional :: x

Returns .true. if sqrt follows the IEEE standard for the same kind of real as x (or for all real kinds if x is absent).

ieee_support_standard

logical function ieee_support_standard(x)
   real(kind), optional :: x

Returns .true. if all the IEEE facilities are supported for the same kind of real as x (or for all real kinds if x is absent).

Rounding Modes

Number Classification

The module also contains the following elemental functions for reals x and y for which ieee_support_datatype is true:

  • ieee_class(x)–ieee class.
  • ieee_value(x,class)–generate a sample IEEE value of the specified class.
  • ieee_is_finite(x)–determine if a value is finite.
  • ieee_is_nan(x)–determine if a value is IEEE NaN.
  • ieee_is_negative(x)–determine if a value is negative.
  • ieee_is_normal(x)–determine if a value is “normal,” neither an Inf, NaN, nor denormalized.
  • ieee_unordered(x,y)–IEEE unordered function. True if either x or y is NaN and false otherwise.

Values of type ieee_class_type indicate the IEEE class of a number which can be one of the following

type(ieee_class_type), parameter :: ieee_negative_denormal
type(ieee_class_type), parameter :: ieee_negative_inf
type(ieee_class_type), parameter :: ieee_negative_normal
type(ieee_class_type), parameter :: ieee_negative_zero
type(ieee_class_type), parameter :: ieee_positive_denormal
type(ieee_class_type), parameter :: ieee_positive_inf
type(ieee_class_type), parameter :: ieee_positive_normal
type(ieee_class_type), parameter :: ieee_positive_zero
type(ieee_class_type), parameter :: ieee_quiet_nan
type(ieee_class_type), parameter :: ieee_signaling_nan 

The module ieee_arithmetic also defines the == and /= operators for the ieee_class_type. These may be used to test the return value of the ieee_class function. For example:

if (ieee_class(x) == ieee_quiet_nan) then
  ! ...
end if

Arithmetic operations

  • ieee_copy_sign(x,y)–IEEE copysign function.
  • ieee_logb(x)–unbiased exponent in the IEEE floating point format.
  • ieee_next_after(x,y)–returns the next representable neighbor of x in the direction toward y.
  • ieee_rem(x,y)–the IEEE rem function, that is x - y*n, where n is the integer nearest to the exact value x/y.
  • ieee_rint(x)–round to an integer value according to the current rounding mode.
  • ieee_scalb(x,i)–Returns x*2i.