2.2.1.1 Integer Constants

An integer constant is a whole number with no decimal point. It can have a leading sign and is interpreted as a decimal number. Integer constants take the following form:

snn
s
Is an optional sign.
nn
Is a string of decimal digits. Any leading zeros are ignored.

Rules and Behavior

A minus sign must appear before a negative integer constant, whereas a plus sign is optional before a positive constant (an unsigned constant is assumed to be positive).

Except for a leading algebraic sign, an integer constant cannot contain any character other than the numerals 0 through 9.

The ranges for the integer data types are shown in Section E.3.

The value of an integer constant is normally INTEGER*2, INTEGER*4, or INTEGER*8 (Alpha only). If a value is within INTEGER*2 range, it is treated as an INTEGER*2 value; if a value is outside INTEGER*2 range, but within INTEGER*4 range, it is treated as an INTEGER*4 value, and so forth.

Examples

The following examples show valid and invalid integer constants:

Valid   
0    
-127    
+32123    
Invalid  Explanation 
9999999999999999999   Number too large 
3.14   Decimal point not allowed 
32,767   Comma not allowed 

You can use integer constants to assign values to data. The following table shows assignments to different data and lists the integer and hexadecimal values in the data:

Fortran Assignment    Integer Value in Data    Hexadecimal Value in Data

LOGICAL*1 X
INTEGER*1 X

X = -128 -128 '80'X X = 127 127 '7F'X X = 255 -1 'FF'X LOGICAL*2 X INTEGER*2 X
X = 255 255 'FF'X X = -32768 -32768 '8000'X X = 32767 32767 '7FFF'X X = 65535 -1 'FFFF'X

For More Information:


Previous Page Next Page Table of Contents