In logic, and in *ahem* properly designed programming languages, comparing a boolean to true is always redundant, i.e. a == True
should be replaced by simply a
. (And similarly, a == False
by not a
).
Many languages, including C, don't have a proper boolean type so it can make a difference whether you compare with true (e.g. 2 == true
yields 0
, which as a boolean represents false, while 2
itself can represent true).
Is this also an issue in Fortran, or can I always replace a .eqv. .true.
by a
?
(I found that in some legacy code, and I heavily suspect it's just one of the many things that the authors didn't really think through... but I'm curious whether there's actually some special case hidden there I should watch out for.)
No, there is no reason to write that. a .eqv. .true.
is the same as a
. Just don't use ==
, that is used for different data types.
Regarding things found in legacy codes, don't forget that many, if not most, Fortran users are not professional programmers and never received thorough training in proper programming techniques. Often, they were just taught the language rules.
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