trouble with -ffinite-math-only

Ian Lance Taylor iant@google.com
Tue May 25 16:13:00 GMT 2010


Neal Becker <ndbecker2@gmail.com> 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



More information about the Gcc-help mailing list