Hello,
I'm facing a very bizarre problem: a logical expression of the form (A .and. B) .or. (C .and. D) has to be evaluated in a do while construct. But if gives the wrong result. I mean: when printing the expressions one by one, they are correct. When printing the left part, and the right part, they are also correct. When the full expression is used, its wrong.
A, B, C, D are : T, F, T, F
(A .and. B) gives F
(C .and. D) gives F
BUT: (A .and. B) .or. (C .and. D) gives T !!!!
Here is a copy of the code:
100 IF ( (Direction.GT.0).AND.((T-Tend)+Roundoff.LE.ZERO)& .OR. (Direction.LT.0).AND.((Tend-T)+Roundoff.LE.ZERO) ) THEN print*,'*** start of time loop**' print*,'T, Tend',T,Tend print*,'test result',(Direction.GT.0).AND.((T-Tend)+Roundoff.LE.& ZERO) .OR. (Direction.LT.0).AND.((Tend-T)+Roundoff.LE.ZERO) ! (list of statements, which increase T towards Tend) print'(a,2f25.18)','T, Tend',T,Tend print*,'Roundoff =',Roundoff AA = (Direction.GT.0).AND.((T-Tend)+Roundoff.LE.ZERO) BB = (Direction.LT.0).AND.((Tend-T)+Roundoff.LE.ZERO) print*,'test result',& (Direction.GT.0).AND.((T-Tend)+Roundoff.LE.ZERO)& .OR.& (Direction.LT.0).AND.((Tend-T)+Roundoff.LE.ZERO) print*,'test with previous evalution',AA.OR.BB print*,'each part A,B (for A .OR. B test)',AA,BB print*,"" print*,'subtest p1',& (Direction.GT.0).AND.((T-Tend)+Roundoff.LE.ZERO) print*,'subtest p2',& (Direction.LT.0).AND.((Tend-T)+Roundoff.LE.ZERO) print*,'split 1',(Direction.GT.0),((T-Tend)+Roundoff.LE.ZERO) print*,'split 2',(Direction.LT.0),((Tend-T)+Roundoff.LE.ZERO) print*,'*** END of time loop**' GOTO 100 END IF
and here is the output:
*** start of time loop** T, Tend 19.3310000000000 20.0000000000000 test result T T, Tend 20.000000000000000000 20.000000000000000000 Roundoff = 2.220446049250313E-016 test result T test with previous evalution T each part A,B (for A .OR. B test) T F subtest p1 F subtest p2 F split 1 T F split 2 F T *** END of time loop** *** start of time loop** T, Tend 20.0000000000000 20.0000000000000 test result T forrtl: error (73): floating divide by zero
Look: when evaluation first the logical expressions, and storing them in logical variables AA and BB, they are said to be T (which is wrong!) and F (which is correct).
Now, when evaluated inside the print*, command (see "subtest p1/2"), they are F and F (which is now correct).
How is that possible ?
Note that "Roundoff" is defined as epsilon(1.d0).
The ifort version used is 9.0.
Many thanks for your help.