On 05/25/2010 04:41 PM, Ian Lance Taylor wrote:
Neal Becker<ndbecker2@xxxxxxxxx> writes:
gcc-4.4.3-4.fc12.x86_64
I have some code that gives wrong results if compiled with -ffinite-math-
only. I'm wondering what could cause this. I don't really expect any
operations to produce NaN or Inf. Is it true that this behavior could only
be explained if indeed some operation is producing NaN or Inf?
-ffinite-math by itself (i.e., without -ffast-math or
-funsafe-math-optimizations) should only enable optimizations which
assume that math operations never generate NaN or Inf. This is
mainly optimizations around comparisons of various sorts. If no NaN
can occur, the compiler has much more scope for optimizing floating
point comparisons. While bugs are always possible, I don't know of
any case where code that never generates a NaN or an Inf will change
behaviour with -ffinite-math-only.
Ian's explanation is spot on - see my initial rationale for the option
-ffinite-math-only at:
http://gcc.gnu.org/ml/gcc-patches/2002-07/msg01668.html
However, that said, it's still possible that:
1. The implementation contains a bug (note that none have been
found in the past 8 years as far as I am aware).
2. The option enables some optimizations that expose a bug
in your program.
Without a self contained example of the problem we cannot determine
which of 1. or 2. (or even a third possibility that I didn't come up
with yet) is the case.
Please try to isolate the problem in a (preferably small) example.
Thanks !
--
Toon Moene - e-mail: toon@xxxxxxxxx - phone: +31 346 214290
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
At home: http://moene.org/~toon/; weather: http://moene.org/~hirlam/
Progress of GNU Fortran: http://gcc.gnu.org/gcc-4.5/changes.html#Fortran