non-compatible round-off when printing for gfortran
Dominique Dhumieres
dominiq@lps.ens.fr
Fri Jul 20 12:42:00 GMT 2007
While trying to write a small code showing the effect of the
optimization of round-off, I ended up with the following code:
real e, f, o, x
o = 1.0
e = epsilon(o)/2.0
f = 2.0**23
!print *, (f+1.4)-f
x = (o + e) - o
print *, e, x
if (x > epsilon(o)) call abort()
print *, 'normal'
if (x /= 0.0) call abort()
print *, 'parenthese obeyed'
end
with the commented line I get:
[karma] f90/bug% gfc -O3 -funsafe-math-optimizations add_eps.f90
[karma] f90/bug% a.out
5.9604645E-08 0.000000
normal
parenthese obeyed
(which was not what I expected), uncommenting the line, I get:
[karma] f90/bug% gfc -O3 -funsafe-math-optimizations add_eps.f90
[karma] f90/bug% a.out
1.000000
5.9604645E-08 5.9604645E-08
normal
Abort
[karma] f90/bug% gfc -O3 add_eps.f90
[karma] f90/bug% a.out
1.000000
5.9604645E-08 0.000000
normal
parenthese obeyed
i.e., more or less what I expected. Now my question is:
why the optimzation of '(o + e) - o' to 'e' is done
only if I have the previous PRINT and why
'(f+1.4)-f' is not optimized as '1.4'?
Looks like a bug, isn't it?
Dominique
More information about the Fortran
mailing list