Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Fortran compound logical expression

Abedin__Abedin
Beginner
584 Views

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
Abedin__Abedin
Beginner
584 Views

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

Regards,

 

Abedin

0 Kudos
Juergen_R_R
Valued Contributor I
584 Views

Can you give a full example?

 

0 Kudos
FortranFan
Honored Contributor II
584 Views

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
jimdempseyatthecove
Honored Contributor III
584 Views

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
Reply