This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: non-compatible round-off when printing for gfortran


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]