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, and a radix of RADIX.
Class
Transformational function
Argument type and attributes
At
least one argument must be present.
- P (optional)
- An INTENT(IN) INTEGER scalar
- R (optional)
- An INTENT(IN) INTEGER scalar
- RADIX (optional)
- An INTENT(IN) INTEGER scalar
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.
- It has a radix, as returned by the RADIX function,
of RADIX.
If no such kind type parameter is available, the result
has different values depending on different conditions as follows:
- If the radix is available, the precision is not available, and the exponent range
is available, the result is -1.
- If the radix is available, the exponent range is not available, and the precision
is available, the result is -2.
- If the radix is available, and neither the precision nor the exponent range is
available, the result is -3.
- If the radix is available, and both the precision and exponent range are available
separately but not together, the result is -4.
- If the radix is not available, the result
is -5.
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.
Currently, the XL Fortran compiler only supports RADIX=2.
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.
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