On 1 Dec 2004 12:11:36 -0800, Dave wrote:
> I guess my question (sorry for the waffle) is how to minimise rounding
> errors in floating point operations?
>
> So far I've tried to account for the errors (or eliminate them) by:
>
> - Using double precision decelerations and calculations
This will certainly decrease your rounding errors. You'll have to
measure whether any speed decrease is worth the mathematical
improvement.
> - Using the epsilon error on the variables to account for known
> internal storage errors
Do you mean using something like
if(result < epsilon) result = 0;
That's something I've had to do on occasion. (epsilon usually around
10^-8 I think, but don't quote me on that.)
> Unable to eliminate or account for the errors I then set about trying
> to use flags to ignore colliding objects from future collision during
> the current recursive collision routine call. Helped in some cases so
> started to try to account for all near critical iterations using
> flags.
This might also be a useful optimization trick, if it can often replace
a bunch of floating point calculations with a single boolean comparison.
> Getting close to a general solution now but my once clear simple
> routine has turned into a logical nightmare!
That does tend to be the way of these things. 99% of all situations are
handled very simply, and then you need a mass of special cases for the
last 1%.
> When working with numbers where accuracy is paramount should I be
> using a different approach? I've considered the following:
>
> - Using a quantised system where all values have to fall along a
> virtual 3D grid
> - Using sin and cos tables to support the above goal of quantisation
> - Using integer mathematics
These three will probably improve speed but decrease accuracy.
> - Use a high precision custom storage class for calculations (speed is
> off the essence so might not be an option?)
This could increase accuracy but decrease speed.
> I'm working on Windows 2000 using Visual Studio 6 and .net enterprise
> architect 2003 (c++).
Have you investigated the Visual Studio "improve floating point
consistency" compilation option? In a couple of projects I've worked
on, it has made a significant improvement. I didn't notice any speed
degradation, but my apps were not as computationally intense as yours
and didn't have real-time requirements.
--
Greg Schmidt
Trawna Publications
http://www.trawna.com/