Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arithmetic involving integer and real operands

Tags:

fortran

In Fortran, will arithmetic involving an integer and real operand be always carried out by converting the integer operand to a real value of the same kind as the real operand? Or is there any exception?

like image 236
Millemila Avatar asked May 02 '26 03:05

Millemila


1 Answers

This is defined in Ch. 7.1.5.1 "Intrinsic operation classification" of the Fortran 2008 Standard:

Excerpt from NOTE 7.15:

Intrinsic operator      Type of     Type of       Type of
op                        x1          x2        [x1] op x2
----------------------------------------------------------
                           I        I, R, Z       I, R, Z
Binary +, –, *, /, **      R        I, R, Z       R, R, Z
                           Z        I, R, Z       Z, Z, Z

[...]

Note: The symbols I, R, Z, C, and L stand for the types integer, real, complex, character, and logical, respectively. Where more than one type for x 2 is given, the type of the result of the operation is given in the same relative position in the next column.

So yes, it is converted to real in your case.

like image 127
Alexander Vogt Avatar answered May 05 '26 10:05

Alexander Vogt