Avoiding floating point problems on Pentium Xeon platform w/ GCC 3.2
Kleinbussink, Erik
erik.kleinbussink@lmco.com
Mon Jun 9 04:10:00 GMT 2003
I am porting an engineering application which uses double precision
calculations from its original platform (Alpha-based Tru64 UNIX) to Intel
Xeon-based linux. I have run into problems with floating point handling.
Below is one of the situations I ran into.
int main()
{
double d1, d2;
int i1, i2;
d1 = 0.04;
i1 = 100;
i2 = 100;
d2 = i1 / d1;
i1 = d2;
i2 = i2 / d1;
printf("%d %d\n", i1, i2);
return 0;
}
On Alpha, the above application results in "2500 2500", but on Intel Xeon,
it results in "2500 2499".
I have been reading gcc documentation, and it sounds like this is a known
complaint with x86 series chips. I am interested in help on what the best
course of action is?
- Review / Rework all source code manually (Very painful)
- Neat compiler flags/tricks which make this problem not a
problem...
Erik
More information about the Gcc-help
mailing list