Difference between .eq. and ==

纵饮孤独 提交于 2020-03-16 05:23:44

问题


I see that a similar question exists for JSP but I don't see a StackOverflow question for Fortran.

The question is: what is the difference between the comparison operators ".eq." and "==" in Fortran?

Note that since I use multiple versions of Fortran (77 and 90 mostly) I'd be interested in knowing if this has changed across versions or at least to what version your answer is in regards to.

Also, since I've only been able to find tutorials on google, it would be great if you could reference something authoritative in your answer (though I'm not sure if a Fortran manual exists online).

Speaking of which, this is what I've found from tutorial pages: this tutorial page http://www.personal.psu.edu/jhm/f90/lectures/10.html seems to indicate there is no difference between them, while this set of slides http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/F90-Control.pdf seems to indicate that "==" is for string comparison while ".eq." is for complex values.

EDIT: Actually, the second hyperlink doesn't mention " .eq. " at all. In any case Alexander Vogt's answer is exactly what I was looking for.


回答1:


== and .EQ. are identical. The Fortran 2008 Standard, Cl. 7.1.5.5.1 "Interpretation of relational intrinsic operations" states:

2 The operators <, <=, >, >=, ==, and /= always have the same interpretations as the operators .LT., .LE., .GT., .GE., .EQ., and .NE., respectively.

In FORTRAN 77 and earlier, only .EQ. exists. The == operator has been introduced with Fortran 90 (Cl. 7.2.3 "Relational intrinsic operations", same text).

For the second part of your question, the Fortran 2008 Standard (Table 7.2: Type of operands and results for intrinsic operators) lists the applicable operand types. In that table, you can see that you are allowed to compare integers, reals, and complex numbers in any combination, but strings only tom strings. The result will always be .true. or .false.. There is no discrimination between == and .EQ..



来源:https://stackoverflow.com/questions/35831254/difference-between-eq-and

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!