Fortran Wiki
Intrinsic types

Fortran has five intrinsic data types: integer, real, complex, logical, and character. Each of those types can be additionally characterized by a kind which defines internal representation of the type. For the three numeric types, it defines the precision and range, and for the other two, the specifics of storage representation.

The numeric types are based on number models with associated inquiry functions. These functions are important for portable numerical software:

  • digits—number of significant digits
  • epsilon—almost negligible compared to one (real)
  • huge—largest number
  • maxexponent—maximum model exponent (real)
  • minexponent—minimum model exponent (real)
  • precision—decimal precision (real and complex)
  • radix—base of the model
  • range—decimal exponent range
  • tiny—smallest positive number (real)

integer

Integer literal constants of the default kind take the form:

1   0   -999   32767   +10

Kind can be defined as a named constant. If the desired range is ±10 kind, the portable syntax for defining the appropriate kind, two_bytes is:

integer, parameter :: two_bytes = selected_int_kind(4)

that allows subsequent definition of constants of the form:

-1234_two_bytes   +1_two_bytes

Here, two_bytes is the kind type parameter; it can also be an explicit default integer literal constant, like

-1234_2

but such use is non-portable.

The kind function supplies the value of a kind type parameter:

kind(1)            kind(1_two_bytes)

and the range function supplies the actual decimal range (so the user must make the actual mapping to bytes):

range(1_two_bytes)

Also, in data (initialization) statements, binary (b), octal (o) and hexcadecimal (z) constants may be used (often informally referred to as “BOZ constants”):

b'01010101'   o'01234567'   z'10fa'

real

There are at least two real kinds—the default, and one with greater precision (this replaces double precision). selected_real_kind functions returns the kind number for desired range and precision; for at least 9 decimal digits of precision and a range of 10 99 to 10 99, it can be specified as:

integer, parameter :: long = selected_real_kind(9, 99)

and literals subsequently specified as:

1.7_long

Also, there are the intrinsic functions

kind(1.7_long)   precision(1.7_long)   range(1.7_long)

that give in turn the kind type value, the actual precision (here at least 9), and the actual range (here at least 99).

complex

The complex data type is built of two integer or real components:

(1, 3.7_long)

logical

There are only two basic values of logical constants: .true. and .false.. Here, there may also be different kinds (to allow for packing into bits or bytes). Logicals don’t have their own kind inquiry functions, but use the kinds specified for integers. The default kind of logical is the same that as of integer.

.false.   .true._one_bit

and the kind function operates as expected:

kind(.true.)

character

The forms of literal constants for the character data type are:

'A string'   "Another"   'A "quote"'   ''

where the last being an empty string. Different kinds are allowed (for example, to distinguish ASCII and UNICODE strings), but not widely supported by compilers. Again, the kind value is given by the kind function:

kind('ascii')