Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between .eq. and ==

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.

like image 951
Ryan Farber Avatar asked Mar 06 '16 19:03

Ryan Farber


1 Answers

== 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..

like image 137
Alexander Vogt Avatar answered Oct 17 '22 22:10

Alexander Vogt