Arithmetic involving integer and real operands

前端 未结 3 1388
一向
一向 2021-01-21 01:54

In Fortran, will arithmetic involving an integer and real operand be always carried out by converting the integer operand to a real value of t

3条回答
  •  旧时难觅i
    2021-01-21 02:26

    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.

提交回复
热议问题