ABSTRACT

As their name implies, integers in Fortran are the whole numbers 0, 1, 2, 3, 4,… and including the negatives –1, –2, –3, ….

Examples of integer constants are

+365 (the + sign is unnecessary but may be included) –9

Constant integers may appear explicitly in programs. Integers may alternatively be represented by names. The usual convention is to represent an integer by a name beginning with a letter in the range i-n. Unless otherwise specified (by a type declaration statement, Section 3.6 and Chapter 8) variables with names like

istructure j57 mlight nyear izero ides_april

will be therefore be taken by Fortran 95 to be integers. Arithmetic can be done with integers using the arithmetic operators introduced in Chapter 2. If i2=2 and i3=3,

i2**i3 has the value 8

i2*i3 has the value 6

i2+i3 has the value 5

i2-i3 has the value –1

and more surprisingly

i2/i3 has the value 0

The final example arises because of the way the ratio of two integers is interpreted: the exact ratio is calculated, then the fractional part of it is discarded if an integral result is required. Thus, 365/7 has the value 52. Where negative numbers are concerned, the ratio is cut back towards zero, i.e. –365/7 has the value –52. If we had an assignment statement such as

r = i2/i3

with i2 and i3 as above, and r being a real variable, the result would still be zero, because the expression i2/ i3 is first interpreted as an integer-valued expression; assigning an integer value to a real variable is something made clearer in the next section.