xref: /llvm-project/flang/docs/IntrinsicTypes.md (revision 70150d5d068d4808facf045e26b688ca6721d611)
1<!--===- docs/IntrinsicTypes.md
2
3   Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4   See https://llvm.org/LICENSE.txt for license information.
5   SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
7-->
8
9# Implementation of `Intrinsic` types in f18
10
11```{contents}
12---
13local:
14---
15```
16
17Intrinsic types are integer, real, complex, character, and logical.
18All intrinsic types have a kind type parameter called KIND,
19which determines the representation method for the specified type.
20The intrinsic type character also has a length type parameter called LEN,
21which determines the length of the character string.
22
23The implementation of `CHARACTER` type in f18 is described
24in [Character.md](Character.md).
25
26## Supported TYPES and KINDS
27
28Here are the type and kind combinations supported in f18:
29
30INTEGER(KIND=1) 8-bit two's-complement integer
31INTEGER(KIND=2) 16-bit two's-complement integer
32INTEGER(KIND=4) 32-bit two's-complement integer
33INTEGER(KIND=8) 64-bit two's-complement integer
34INTEGER(KIND=16) 128-bit two's-complement integer
35
36REAL(KIND=2) 16-bit IEEE 754 binary16 (5e11m)
37REAL(KIND=3) 16-bit upper half of 32-bit IEEE 754 binary32 (8e8m)
38REAL(KIND=4) 32-bit IEEE 754 binary32 (8e24m)
39REAL(KIND=8) 64-bit IEEE 754 binary64 (11e53m)
40REAL(KIND=10) 80-bit extended precision with explicit normalization bit (15e64m)
41REAL(KIND=16) 128-bit IEEE 754 binary128 (15e113m)
42
43COMPLEX(KIND=2) Two 16-bit IEEE 754 binary16
44COMPLEX(KIND=3) Two 16-bit upper half of 32-bit IEEE 754 binary32
45COMPLEX(KIND=4) Two 32-bit IEEE 754 binary32
46COMPLEX(KIND=8) Two 64-bit IEEE 754 binary64
47COMPLEX(KIND=10) Two 80-bit extended precisions values
48COMPLEX(KIND=16) Two 128-bit IEEE 754 binary128
49
50No
51[double-double
52](https://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format)
53quad precision type is supported.
54
55LOGICAL(KIND=1) 8-bit integer
56LOGICAL(KIND=2) 16-bit integer
57LOGICAL(KIND=4) 32-bit integer
58LOGICAL(KIND=8) 64-bit integer
59
60No 128-bit logical support.
61
62### Defaults kinds
63
64INTEGER 4
65REAL 4
66COMPLEX 4
67DOUBLE PRECISION 8
68LOGICAL 4
69
70#### Modifying the default kind with default-real-8.
71REAL 8
72DOUBLE PRECISION  8
73COMPLEX 8
74
75#### Modifying the default kind with default-integer-8:
76INTEGER 8
77LOGICAL 8
78
79Modules compiled with different default-real and default-integer kinds
80may be freely mixed.
81Module files encode the kind value for every entity.
82
83## Representation of LOGICAL variables
84
85The default logical is `LOGICAL(KIND=4)`.
86
87Logical literal constants with kind 1, 2, 4, and 8
88share the following characteristics:
89.TRUE. is represented as 1_kind
90.FALSE. is represented as 0_kind
91
92Tests for true is *integer value is not zero*.
93
94The implementation matches gfortran.
95
96Programs should not use integer values in LOGICAL contexts or
97use LOGICAL values to interface with other languages.
98
99### Representations of LOGICAL variables in other compilers
100
101#### Intel ifort / NVIDA nvfortran / PGI pgf90
102.TRUE. is represented as -1_kind
103.FALSE. is represented as 0_kind
104Any other values result in undefined behavior.
105
106Values with a low-bit set are treated as .TRUE..
107Values with a low-bit clear are treated as .FALSE..
108
109#### IBM XLF
110.TRUE. is represented as 1_kind
111.FALSE. is represented as 0_kind
112
113Values with a low-bit set are treated as .TRUE..
114Values with a low-bit clear are treated as .FALSE..
115