Fortran provides all the typical data types supported directly by most CPUs, as well as a few abstract types. Table 17.2, “Fortran 90 Data Types” outlines the standard data types available in Fortran 90.
Table 17.2. Fortran 90 Data Types
Fortran 90 Type | Description | Range | Precision |
---|---|---|---|
integer(1) | 8-bit signed integer | -128 to +127 | Exact |
integer(2) | 16-bit signed integer | -32,768 to +32,767 | Exact |
integer(4) [ integer ] | 32-bit signed integer | -2,147,483,648 to +2,147,483,647 | Exact |
integer(8) | 64-bit signed integer | +/- 9.22 x 1018 | Exact |
integer(16) | 128-bit signed integer | +/- 9.22 x 1018 or +/- 1.70 x 1038 | Exact |
real(4) [ real ] | 32-bit floating point | +/- (1.1754 x 10-38 to 3.4028 x 1038) | 24 bits (6-7 decimal digits) |
real(8) [ double precision ] | 64-bit floating point | +/- (2.2250 x 10-308 to 1.7976 x 10308) | 52 bits (15-16 decimal digits) |
real(16) | 128-bit floating point | +/- 3.3621 x 10-4932 to 1.1897 x 10+4932) | 114 bits (64 decimal digits) |
character | 8-bit ISO, 16-bit in non-Latin locales | ISO 0 (NUL) to 255 (y-umlaut in ISO-Latin1) | Exact |
logical | .true. or .false. | false to true | Exact |
complex(4) [ complex ] | Two 32-bit floating point values | Same as real(4) | Same as real(4) |
complex(8) [ double complex ] | Two 64-bit floating point values | Same as real(8) | Same as real(8) |
complex(16) | Two 128-bit floating point values | Same as real(16) | Same as real(16) |
What would be the best Fortran data type to use for each of the following values? Explain your reasoning in each case. Use the C types table in the text and the adjoining explanations to make optimal choices.
A single variable containing a person's age, in years.
A single variable holding the temperature of a star, up to 40,000 Kelvin. The value is only approximate within 1,000 degrees.
The balance of Joe Sixpack's checking account, in pennies.
A huge array of people's ages in years.
A single variable holding Avogadro's constant.
A large array holding values like Avogadro's constant.