W3cubDocs

/GNU Fortran 6

9.231 SELECTED_INT_KIND — Choose integer kind

Description:
SELECTED_INT_KIND(R) return the kind value of the smallest integer type that can represent all values ranging from -10^R (exclusive) to 10^R (exclusive). If there is no integer kind that accommodates this range, SELECTED_INT_KIND returns -1.
Standard:
Fortran 95 and later
Class:
Transformational function
Syntax:
RESULT = SELECTED_INT_KIND(R)
Arguments:
R Shall be a scalar and of type INTEGER.
Example:
program large_integers
  integer,parameter :: k5 = selected_int_kind(5)
  integer,parameter :: k15 = selected_int_kind(15)
  integer(kind=k5) :: i5
  integer(kind=k15) :: i15

  print *, huge(i5), huge(i15)

  ! The following inequalities are always true
  print *, huge(i5) >= 10_k5**5-1
  print *, huge(i15) >= 10_k15**15-1
end program large_integers

© Free Software Foundation
Licensed under the GNU Free Documentation License, Version 1.3.
https://gcc.gnu.org/onlinedocs/gcc-6.3.0/gfortran/SELECTED_005fINT_005fKIND.html