floating point inconsistency

Neil Ferguson nferguso@eso.org
Tue Feb 16 04:40:00 GMT 2010


Christoph Groth wrote:

<snipped inconsistent floating point results>

> This is on a computer with an Intel Core 2 CPU (I tried several
> different variants).
> 
> If I take the second (-O1) binary and execute it on an Opteron it
> produces the _first_ result.  Thus, the same static binary produces
> different results on different processors!

This is a hardware-related effect - in a nutshell, it happens because Intel 
hardware can extend double-precision floating point operations to 80 bits 
internally, whereas AMD hardware usually enforces 64 bits at all times.

Here's a link to an old message from when I encountered the same problem and 
people on this list helped me out:

     http://gcc.gnu.org/ml/gcc-help/2005-12/msg00062.html

The links in that message point to articles which detail exactly why this sort 
of thing happens. Once you understand the problem, you'll need to read through 
the various floating point and optimisation related options for your compiler, 
then choose a set which provide you with an acceptable compromise.

> I observe this problem also with g++ 4.4.2. 

As this is a hardware-related effect, it can happen to you with any version of 
any compiler, not just GCC.

Hope that helps!

Neil.



More information about the Gcc-help mailing list