This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Avoiding floating point problems on Pentium Xeon platform w/GCC 3.2


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".

First of all the obvious answer that your code is highly suspect for an engineering app, since you don't want to ever convert from double -> integer without using either lround() or lrint().


On the other hand, this "problem" goes away if you use "-march=pentium4 -mfpmath=sse" or (due to happenstance in this particular instance) if you enable optimization with "-O2".

Kelley Cook



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]