Floating point problems (accuracy).

Eljay Love-Jensen eljay@adobe.com
Tue Jan 18 20:06:00 GMT 2005


Hi Phil,

 >Does any one know a better way of fixing this? ... Is there a generic 
solution?

There are several different strategies for addressing this kind of 
problem.  What's "The Best" strategy?  Depends on your needs.

Some of the strategies:

1. hardware differences mean that different architectures may be 
inconsistent with the less signficant bits (aka "the fiddly bits").  Expect 
that to be the case, and live with it.

2. use strict IEEE 754 compliance throughout your program -- this does put 
a considerable burden on the developers

3. avoid floating point; use fixed point or just integers for all your 
calculations (this is The Answer if you absolutely MUST have the same 
result on all platforms)

4. use software floating point (e.g., -msoft-float) -- be aware of the 
significant performance penalty

HTH,
--Eljay



More information about the Gcc-help mailing list