How many integer kinds does standard require compilers to support?

I remember reading somewhere that the standard only requires default and one double default kind precision for real type (but today after reading a page from Metcalf’s book, I am not even sure if this is correct). Assuming this is the case for real type, is there also a requirement for supporting an integer of default kind and at least an integer of a higher kind than the default?

If so, what would be the easiest way to infer the kind value for the one higher than the default kind (e.g., int64 given default int32)?

1 Like

The decimal precision of the double precision real approximation
method shall be greater than that of the default real method.

So there must be at least two real kinds, one integer kind, and one character kind. It is not specified in any way how the default kinds relate to the kinds defined in iso_fortran_env.

2 Likes

Please note the standard requires a conforming processor to at least support one integer representation with a decimal exponent of 18 or higher. Thus if one is employing a conformant processor, one can expect selected_int_kind( r=18 ) to yield a legit KIND value.

Now, on modern processors, as you know, the default integer tends to be the one with a decimal exponent of 9 i.e., 32-bit integer.

Thus you can expect, from a practical consideration, the integer_kinds array named constant from iso_fortran_env to have a size of at least two, one for 32-bit and the other for a decimal exponent of 18 or better which is usually the 64-bit integer. However to ascertain the KIND of the latter, as stated above, the safe method per the standard is selected_int_kind intrinsic.

Such deduced info is about the best one can infer from the combo of the standard and conforming processors.

2 Likes

Is that a fact or a proposition? It seems at odds with what FortranFan suggested on the requirement for supporting at least an integer of a kind with 18 digits, which corroborates Metcalf’s opinion in his book. That does not necessarily mean at least two integer kinds, but given a default 32-bit, at least two kinds int64 and int32 appear to be required by the standard.

An anonymous reader communicated the following solution to me (privately) which I share for the sake of others who may have a similar question,

! Next larger kind
integer, parameter :: ik1 = selected_int_kind(range(0) + 1)
! Kind twice as large
integer, parameter :: ik2 = selected_int_kind(2 * range(0))
1 Like

As I hinted in my earlier comment, “required by the standard” will be overstating it because the standard only requires a conforming processor to support an integer representation of a certain decimal exponent. The possibility of 2 integer kinds with modern processors is only a practical reality.

1 Like

Not answering your question about the standard, but running the kindfinder program on Windows 10 for Intel Fortran, gfortran, and g95 gave me the following results, lightly edited:

Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, 
Version 2021.1 Build 20201112_000000

 !---------------------------------------------------------!
 !                                                         !
 !                    KINDFINDER                           !
 !                                                         !
 !            KIND Search & Evaluation for                 !
 !          FloatingPoint and Integer Types                !
 !           of the local Fortran Compiler                 !
 !                                                         !
 ! Author: Werner W Schulz (C) 1998                        !
 !                                                         !
 !                                                         !
 ! FloatingPoint Model Parameters:                         !
 ! Kind   Precision       Range          Name              !
 !    4           6          37          Single            !
 !    8          15         307          Double            !
 !   16          33        4931          Extnd1            !
 !                                                         !
 !                                                         !
 ! Integer Model Parameters:                               !
 ! Kind   Range                          Name              !
 !    1       2                          Int_01            !
 !    2       4                          Int_02            !
 !    4       9                         Int_Def            !
 !    8      18                          Int_08            !
 !                                                         !
 !                                                         !
 !                                                         !
 ! NOTE:                                                   !
 ! KindFinder has generated a Programme and a Module in    !
 !                                                         !
 !     NumericModel.f90                                    !
 !     Fortran_Kind_Module.f90                             !
 !                                                         !
 ! that will compute and display the Numerical Parameters  !
 ! of the various INTEGER & FLOATING POINT Types           !
 ! as specified by Fortran and the local Compiler.         !
 ! The ModuleFile is can be used elsewhere.                !
 !                                                         !
 ! All Code is compatible with the Fortran Subsets and     !
 ! should be able to run on any Fortran90-conforming       !
 ! Compiler including F and Elf90.                         !
 !                                                         !
 ! NOTE:                                                   !
 ! Possible KIND Values for LOGICAL or CHARACTER Types     !
 ! must be obtained in the local Fortran Reference Manual  !
 !                                                         !
 !---------------------------------------------------------!



GNU Fortran (GCC) 12.0.0 20210718 (experimental)


 !---------------------------------------------------------!
 ! FloatingPoint Model Parameters:                         !
 ! Kind   Precision       Range          Name              !
 !    4           6          37          Single            !
 !    8          15         307          Double            !
 !   10          18        4931          Extnd1            !
 !   16          33        4931          Extnd2            !
 !                                                         !
 !                                                         !
 ! Integer Model Parameters:                               !
 ! Kind   Range                          Name              !
 !    1       2                          Int_01            !
 !    2       4                          Int_02            !
 !    4       9                         Int_Def            !
 !    8      18                          Int_08            !
 !   16      38                          Int_16            !
 !---------------------------------------------------------!


G95 (GCC 4.1.2 (g95 0.93!) Jun 16 2010)

 !---------------------------------------------------------!
 ! FloatingPoint Model Parameters:                         !
 ! Kind   Precision       Range          Name              !
 !    4           6          37          Single            !
 !    8          15         307          Double            !
 !   10          18        4931          Extnd1            !
 !   16          33        4931          Extnd2            !
 !                                                         !
 !                                                         !
 ! Integer Model Parameters:                               !
 ! Kind   Range                          Name              !
 !    1       2                          Int_01            !
 !    2       4                          Int_02            !
 !    4       9                         Int_Def            !
 !    8      18                          Int_08            !
 !---------------------------------------------------------!
1 Like

The processor shall provide one or
more representation methods that define sets of values for data of type integer.

The processor shall provide at least one representation method with a decimal exponent range greater than or equal to 18

The decimal exponent range of default integer shall be at least 5.

It would be standards conforming for a processor to provide only a single integer kind if it’s decimal exponent range was >= 18. Of course in practice, most processors use 32 bit integers as the default kind, and provide a 64 bit integer to satisfy the larger requirement, since that’s what is generally expected these days.

2 Likes