SELECTED_REAL_KIND(P, R, RADIX)

Purpose

Returns a value of the kind type parameter of a real data type with decimal precision of at least P digits, a decimal exponent range of at least R, Fortran 2008 beginsand a radix of RADIX.Fortran 2008 ends

Class

Transformational function

Argument type and attributes

At least one argument must be present.
P (optional)
must be scalar and of type integer.
R (optional)
must be scalar and of type integer.
Fortran 2008 beginsRADIX (optional)
must be scalar and of type integer.Fortran 2008 ends

Result type and attributes

Default integer scalar.

Result value

If P or R is not specified, SELECTED_REAL_KIND behaves as if you specified P or R with value 0. If RADIX is not specified, the radix of the selected kind can be any supported value.

The result is the value of the kind type parameter of a real data type that satisfies the following conditions:
  • It has decimal precision, as returned by the PRECISION function, of at least P digits.
  • It has a decimal exponent range, as returned by theRANGE function, of at least R.
  • Fortran 2008 beginsIt has a radix, as returned by the RADIX function, of RADIX.Fortran 2008 ends
If no such kind type parameter is available, the result has different values depending on different conditions as follows:
  • If Fortran 2008 beginsthe radix is availableFortran 2008 ends, the precision is not available, and the exponent range is available, the result is -1.
  • If Fortran 2008 beginsthe radix is availableFortran 2008 ends, the exponent range is not available, and the precision is available, the result is -2.
  • If Fortran 2008 beginsthe radix is availableFortran 2008 ends, and neither the precision nor the exponent range is available, the result is -3.
  • If Fortran 2008 beginsthe radix is availableFortran 2008 ends, and both the precision and exponent range are available separately but not together, the result is -4.
  • Fortran 2008 beginsIf the radix is not available, the result is -5.Fortran 2008 ends

If more than one kind type parameter value meets the criteria, the value returned is the one with the smallest decimal precision. However, if several values have the same smallest decimal precision, the smallest value is returned.

Fortran 2008 beginsCurrently, the XL Fortran compiler only supports RADIX=2.Fortran 2008 ends

Examples

The following example shows the usage of the SELECTED_REAL_KIND intrinsic procedure.
PROGRAM a
  INTEGER :: i

  i = SELECTED_REAL_KIND(6, 70)
  PRINT *, 'SELECTREALKIND(6, 70) = ', i
END PROGRAM a
The output of this program is as follows:
SELECTREALKIND(6, 70) = 8 
SELECTED_REAL_KIND (6, 70) has the value 8.
Fortran 2008 begins
The following example shows the usage of the SELECTED_REAL_KIND intrinsic procedure with the RADIX argument.
PROGRAM a
  INTEGER :: i

  i = SELECTED_REAL_KIND(20, 140, 2)
  PRINT *, 'SELECTREALKIND(20, 140, 2) = ', i
END PROGRAM a
The output of this program is as follows:
SELECTREALKIND(20, 140, 2) = 16
Fortran 2008 ends

Related information