This program works Ok on the Macintosh. On linux this program fails with -O2, but works Ok with -g - dir/tests> gfortran -O2 -o timefun02 timefun02.f dir/tests> timefun02 Error 1.00000000000000 1.00000000000000 STOP 0 dir/tests> gfortran -g -o timefun02 timefun02.f dir/tests> timefun02 STOP 0 dir/tests> cat timefun02.f program main implicit real*8 (a-h,o-z) time2=0d0 do 20 i=1,10 time2 = time2 + 0.1d0 20 continue call sub1(time2) stop end subroutine sub1(time) implicit real*8 (a-h,o-z) time2=0d0 do 30 i=1,10 time2 = time2 + 0.1d0 30 continue if(time2.ne.time)then write(6,*)'Error ',time2,time endif return end dir/tests> gfortran --v Using built-in specs. Target: i686-pc-linux-gnu Configured with: ./configure --prefix=/home/dir/gfortran --enable-languages=c,f95 Thread model: posix gcc version 4.1.0 20050815 (experimental)
This almost can be considered a bug in the processor (x86 that is). The issue is that on x86 GCC is using excessive precision so you cannot really rely on equals with floating point. Either use -ffloat-store or use -mfpmath=sse -msse2 or stop relying on float being equal. This is a dup of bug 323. *** This bug has been marked as a duplicate of 323 ***