Testing floating point numbers equality

Viewed 7167

I am using gfortran in MinGW under Windows 7 (32bit) to compile Fortran code. Here is the minimal code contained in the file testequal.f:

      program testequal
      real*8 a1, a2

      a1 = 0.3d0
      a2 = 0.7d0

      write(*,*) 1.d0
      write(*,*) a1+a2
      write(*,*) a1+a2.eq.1.0
      write(*,*) a1+a2.eq.1.d0
      end

Compiled with

gfortran testequal.f -std=legacy

the output is:

1.0000000000000000
1.0000000000000000
F
F

But I expect the two booleans to be both T (true). What is the problem here?

3 Answers
Related