linux i-86 problem with rounding (gcc-3.1.1 & 3.2)

Martin Dickopp
Wed Sep 18 13:35:00 GMT 2002

On Wed, Sep 18, 2002 at 02:58:54PM -0500, Buddy Lott wrote:
> While I agree, that processor type would affect the precision of the
> answer, I would think the compiler should consistent when
> optimizing/not optimizing code. I would think it should never change
> the result of the code.

The observed behavior is a result of a peculiarity of the x86
processor: floating-point numbers have higher precision in registers
than in memory. Therefore, the result depends on what calculations
are done in registers, which is affected by optimization.

Gcc has an option -ffloat-store, which causes floating-point numbers
always to be stored in memory. With this option, the program gives
the same result with every optimization level.


More information about the Gcc-help mailing list