Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
1 View

Fortran compound logical expression

Hi guys,

This is my first time in this community, so please forgive me if my question is sort of stupid.

I've been programming in Fortran but never claimed to be a programmer, so without further adieu here is my question:

I noticed that:

c**************************************************

real*8 :: x, y, b, c
if ((x .lt. b) .and. (y .gt. c))

is not equal to:

c******************************************

real*8 :: x, y, b, c
logical :: l1, l2

l1=(x.lt.b)

l2=(y.gt.c)

if (l1 .and. l2)

 

Any idea why?

I am using gfortran.

Regards,

Abedin

0 Kudos
4 Replies
Highlighted
Beginner
1 View

I am so sorry!!! Please

I am so sorry!!! Please disregard this post. There was a bug in my code.

Regards,

 

Abedin

0 Kudos
Highlighted
Valued Contributor I
1 View

Can you give a full example?

Can you give a full example?

 

0 Kudos
Highlighted
Valued Contributor III
1 View

Quote:Abedin, Abedin wrote:

Abedin, Abedin wrote:

.. I am using gfortran. ..

For any other questions with Fortran, you may want to consider posting on forums such as comp.lang.fortran and StackOverflow.com.

For any gfortran issues, you may want to try this site: https://gcc.gnu.org/wiki/GFortran#Reporting_bugs

0 Kudos
Highlighted
1 View

Abedin.

Abedin.

Seeing that you may be new to Fortran, it is important to you to realize that the evaluation rules/behavior in Fortran is not the same as that in C/C++/C#/...

Fortran evaluates all portions of the IF expressions, whereas C shortcuts the evaluations in left to right order

IF( (A > 0.0) .AND. ((B / A) > C) THEN...

Will (is permitted to) evaluate both sides of .AND., or right side then left side, or left side then right side, or both sides at the same time (different lanes in vector).

Whereas C in if((A>0.0) &&  ((B / A) > C)) will evaluate the left side of && and stop evaluating if the left side is false.

Jim Dempsey

0 Kudos