0

I am using FORTRAN 95 using Silverfrost Plato. Here, I am trying to create a conditional statement to compare a double precision variable with a double precision value. Somehow the compiler does not understand the condition.

program db
implicit none
integer :: j,n
double precision :: t,t_max,dt
n = 20
dt = 0.000020d0
t_max = 0.00632d0
t = 0.0d0
while (t .LE. t_max) do
    if ( t == 0.00158d0) then
        do j = 0,n
            print  *, j
        end do
    end if
print *, t 
t = t + dt    
end do
end program db

I am unable to resolve this issue on my own. Any help or links to relevant documentation would be greatly appreciated.

Suga
  • 201
  • 1
  • 3
  • 7
  • 1
    http://stackoverflow.com/q/588004/1004168 – agentp Apr 25 '16 at 00:30
  • 1
    It probably wouldn't do any harm to write syntactically-correct Fortran either. This line, `while (t .LE. t_max) do`, is wrong, `do` should precede `while`. – High Performance Mark Apr 25 '16 at 07:18
  • If you really want to see what is happening, try printing out the difference between t and 0.00158d0 each time through the loop. You can then see that adding 0.000020d0 multiple times to zero will never exactly equal 0.00158d0. Not only that, you need to know that when you set x=0.00158d0 x will not be exactly 0.00158d0.because that number cannot be exactly expressed in a finite number of binary digits. – FredK Apr 25 '16 at 21:46

0 Answers0