Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
600 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...