Because the identity and negation operators operate on a single operand, the type of the resulting value is the same as the type of the operand.
The following table indicates the resulting type when an arithmetic operator acts on a pair of operands.
first operand | second operand | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
I(1) | I(2) | I(4) | I(8) | R(4) | R(8) | R(16) | X(4) | X(8) | X(16) | |
I(1) | I(1) | I(2) | I(4) | I(8) | R(4) | R(8) | R(16) | X(4) | X(8) | X(16) |
I(2) | I(2) | I(2) | I(4) | I(8) | R(4) | R(8) | R(16) | X(4) | X(8) | X(16) |
I(4) | I(4) | I(4) | I(4) | I(8) | R(4) | R(8) | R(16) | X(4) | X(8) | X(16) |
I(8) | I(8) | I(8) | I(8) | I(8) | R(4) | R(8) | R(16) | X(4) | X(8) | X(16) |
R(4) | R(4) | R(4) | R(4) | R(4) | R(4) | R(8) | R(16) | X(4) | X(8) | X(16) |
R(8) | R(8) | R(8) | R(8) | R(8) | R(8) | R(8) | R(16) | X(8) | X(8) | X(16) |
R(16) | R(16) | R(16) | R(16) | R(16) | R(16) | R(16) | R(16) | X(16) | X(16) | X(16) |
X(4) | X(4) | X(4) | X(4) | X(4) | X(4) | X(8) | X(16) | X(4) | X(8) | X(16) |
X(8) | X(8) | X(8) | X(8) | X(8) | X(8) | X(8) | X(16) | X(8) | X(8) | X(16) |
X(16) | X(16) | X(16) | X(16) | X(16) | X(16) | X(16) | X(16) | X(16) | X(16) | X(16) |
INTEGER(2) I2_1, I2_2, I2_RESULT
INTEGER(4) I4
I2_1 = 32767 ! Maximum I(2)
I2_2 = 32767 ! Maximum I(2)
I4 = I2_1 + I2_2
PRINT *, "I4=", I4 ! Prints I4=-2
I2_RESULT = I2_1 + I2_2 ! Assignment to I(2) variable
I4 = I2_RESULT ! and then assigned to an I(4)
PRINT *, "I4=", I4 ! Prints I4=-2
END