[Mono-dev] Optimising code breaks maths

Paul Betts bettsp at cse.ohio-state.edu
Sun Jan 28 13:38:52 EST 2007


On Sun, 2007-01-28 at 11:41 +0000, Alan McGovern wrote:
> Does anyone have any advice on how to code the methods to reduce the
> impact of the optimiser? Or should i just disable optimisations
> altogether, although I'd assume that wouldn't be advisable for
> performance reasons. 

Welcome to the world of floating-point arithmetic unfortunately. Off the
top of my head, there are a few ways you can avoid inaccuracy; the
obvious one is to use doubles but for a game library that's probably not
a great idea. Another choice that will help is avoiding subtraction as
much as possible (negation is still ok though); division isn't too hot
either (as far as I can remember, it's been awhile since I took
Numerical Representation). Make sure to check your Dot and Cross
routines as well. 

Keep in mind too, you don't need 100% accuracy in 3D graphics, just
enough to get by; remember that you can never test for equality either,
only "close-enough'ity" ie (a == b) => ( (a-b) < 0.00001 /* Typically
called Epsilon */). Sorry if you knew all this stuff but I just thought
I'd help out a bit

Looks like this should be handy too (from the Wikipedia page):
http://docs.sun.com/source/806-3568/ncg_goldberg.html

-- 
Paul Betts <bettsp at cse.ohio-state.edu>




More information about the Mono-devel-list mailing list