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.
==
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.
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With