Variable assignment and truncation of floats on x86

Alexandre Oliva
Thu Apr 19 12:03:00 GMT 2001

On Apr 18, 2001, Joe Murray <> wrote:

> 3 results in: 7.0000000000 (actually probably 6.999999? rounded to
> 7.00000000)
> 4 results in: 6 <------- PROBLEM WITH INPLACE ASSIGNMENT
> 5 results in: 7 (correct answer)

FP is not exact, and is, in a sense, even less exact on x86, in which
the result depends on whether the intermediate result was kept in an
80-bit FP register or was stored in a 64-bit memory location.  I
suppose you man want to use roundf() to avoid getting 6.999999
truncated to 6.

Alexandre Oliva   Enjoy Guarana', see
Red Hat GCC Developer                  aoliva@{,}
CS PhD student at IC-Unicamp        oliva@{,}
Free Software Evangelist    *Please* write to mailing lists, not to me

More information about the Gcc-bugs mailing list