Cool Engineering

Info on some cool engineering projects

Wednesday, September 06, 2006

Problems (a)float

My recent glossy posts have really gotten off topic - the topic of engineering project work. I will take off my marketing hat for a moment and put the engineering one (in this case software) back on.
An interesting recent problem I have been encountering is in the calculation of bearings. Well, not really the calculation of bearings - that part was rather trivial. It is a rather quirky compiler or emulator bug in how floating point numbers are used. Basically I can make assignments to these numbers without a worry (i.e. ratio = opposite/(float) adjacent). (You may recognise that I'm calculating bearings based on tangents - so next time a high school maths teacher gets asked why are studying trigonometry? they can answer - well when you are developing vectoring algorithms for autonomous craft it will really come in handy - NOTE: I wasn't the one to ask such questions - I'd just hear them again and again from the same people).
Back to the problem - when I try any compare these floating point numbers I come into grief.
Simple statements like:
if (ratio > 0)
or even:
if (ratio > 0.0)
would corrupt other data variables not even passed to the specific function.
To cut a long story short - I switched over to integers (which don't have any decimal places) which allows me to do the calculations in half the space and with much greater speed (I'm not sure why I didn't do this to begin with).

0 Comments:

Post a Comment

<< Home