Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
653 views
in Technique[技术] by (71.8m points)

fortran - Arithmetic involving integer and real operands

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...