Related articles |
---|
Fortran compiler optimisation w.purvis@daresbury.ac.uk (1994-11-11) |
re: Fortran compiler optimisation 7549-15328 (dmr@research.att.com (Dennis Ritchie0112710)) (1994-11-14) |
Re: Fortran compiler optimisation doog@jade.ssd.csd.harris.com (1994-11-15) |
Re: Fortran compiler optimisation lionel@quark.enet.dec.com (1994-11-21) |
Newsgroups: | comp.compilers |
From: | w.purvis@daresbury.ac.uk (Bill Purvis, ext 3357) |
Keywords: | question, Fortran, comment |
Organization: | Daresbury Laboratory, UK |
Date: | Fri, 11 Nov 1994 13:42:36 GMT |
I have recently encountered a bug which appears to be endemic in Fortran
Compilers. At least I think it's a bug. The code which illustrates this
is:
c program to test bug
fred=10.0E-12
fred=(fred*1000000)*500000
george=10.0E-12
george=(george*1000000.0)*500000.0
print *, fred,george
end
My reading of the standard implies that the two numbers output should be
pretty near identical. Running on my Sun sparc gives:
1.78379E-02 5.00000
which is nowhere near!
No doubt there will be plenty of people who can point out what is going
wrong here - the compiler is spotting two constants and is multiplying
them and getting an overflow. However, this is in breach of the standard
which implies that the first constant (1000000) should be converted to
real, multiplied by fred and then by the other constant (500000). Even if
the compiler does optimise this, shouldn't any self-respecting compiler
check for overflows of this kind? I have tried this program on both Sun
and SGI machines and got the same effect. I also tried f2c and noted that
the C code had a single constant which looks nothing like 500000000000.0
Bill Purvis
[F2c does indeed seem to do this wrong, since the F77 standard (and I presume
F90) say that the compiler must respect parens. -John]
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.