Variable assignment and truncation of floats on x86

Toshi Morita
Wed Apr 18 15:28:00 GMT 2001

> A routine that demonstrates the problem is below. I can provide several
> other examples. It was suggested previously that the floating point unit was
> being put into truncate mode from its default round-to mode. I don't know
> how to overcome this without major ramifications on the code baseline.
> 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)

[tm@localhost tm]$ uname -a
Linux localhost.localdomain 2.2.17-14smp #1 SMP Mon Feb 5 15:48:47 EST 2001 i686 unknown
[tm@localhost tm]$ gcc -v
Reading specs from /usr/local/lib/gcc-lib/i686-linux/2.95.3/specs
gcc version 2.95.3 20010315 (release)
[tm@localhost tm]$ gcc -O2 test2.c
[tm@localhost tm]$ ./a.out
Direct assign float to float = 7.0000000000
 Inplace assign float to int = 7
  Direct assign float to int = 7
[tm@localhost tm]$ 

This doesn't seem to occur on all versions of gcc.
It would probably help if you specified an exact version
which fails, instead of "gcc on x86".


More information about the Gcc-bugs mailing list