Variable assignment and truncation of floats on x86

Alexandre Oliva aoliva@redhat.com
Thu Apr 19 12:03:00 GMT 2001


On Apr 18, 2001, Joe Murray <jmurray@dsrnet.com> 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 http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me



More information about the Gcc-bugs mailing list