FORTRAN 77 Language Reference

Mixed Mode

If both operands have the same type, then the resulting value has that type. If operands have different types, then the weaker of two types is promoted to the stronger type, where the weaker type is the one with less precision or fewer storage units. The ranking is summarized in the following table:

Data Type  

Rank  

BYTE or LOGICAL*1  

LOGICAL*2  

LOGICAL*4  

INTEGER*2  

INTEGER*4  

INTEGER*8 

LOGICAL*8 

REAL*4 (REAL)  

REAL*8 (DOUBLE PRECISION) 

REAL*16 (QUAD PRECISION) (SPARC only)

COMPLEX*8 (COMPLEX)  

COMPLEX*16 (DOUBLE COMPLEX)  

COMPLEX*32 (QUAD COMPLEX) (SPARC only)

1 (Weakest) 

2  

3  

4  

5  

6  

7  

8  

9  

10  

11 (Strongest) 


Note -

REAL*4, INTEGER*8, and LOGICAL*8 are of the same rank, but they can be the results of different pairs of operands. For example, INTEGER*8 results if you combine INTEGER*8 and any of the types between 1-5. Likewise, REAL*4 results if one of the operands is REAL*4, and the other is any of the types between 1-5. LOGICAL*8 dictates only the 8-byte size of the result.


Example of mixed mode: If R is real, and I is integer, then the expression:


	R * I 

has the type real, because first I is promoted to real, and then the multiplication is performed.

Rules

Note these rules for the data type of an expression:

Resultant Type

For integer operands with a logical operator, the operation is done bit by bit. The result is an integer.

If the operands are mixed integer and logical, then the logicals are converted to integers, and the result is an integer.