Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there ever a reason to write .eqv. .true.?

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

like image 339
leftaroundabout Avatar asked Dec 14 '22 16:12

leftaroundabout


1 Answers

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.

like image 103
Vladimir F Героям слава Avatar answered Dec 17 '22 05:12

Vladimir F Героям слава