floating point innacuracy :(

BlitzMax Forums/BlitzMax Beginners Area/floating point innacuracy :(

Nate the Great(Posted 2009) [#1]
alas I have reached a major problem in a program. It is just for fun so it is not urgent though. I am trying to do high accuracy physics simulation in real time 'no code necessary to solve my problem' and I use ! after every variable for the highest possible acuracy yet when I run it I still run into floating point inacuracy. Is there a way to make variables more acurate than ! in bmax?


Gabriel(Posted 2009) [#2]
I find it improbable that you've run into pure floating point precision issues with 64 bit floats. Most physics engines seem to manage perfectly well with them. I guess you could always write your own fixed point system, but I suspect that won't be trivial.

It is possible, however, that you've run into an issue where a wrong calculation or even just the wrong order of operations might be massively exacerbating a tiny floating point imprecision. Simple things such as forgetting to normalize a quaternion or vector could certainly lead you to suspect that. It would probably really help if you could be more specific about what operations you're performing and how you're determining that there is a problem which floating point inaccuracy could be causing.


TaskMaster(Posted 2009) [#3]
Your best bet for very high accuracy is to make your own precision number system.


Brucey(Posted 2009) [#4]
My mapm module is accurate to 2,147,483,647 digits, but since that would require the whole of 2gig of RAM to store a single number, it's unlikely many people would need accuracy to that depth.

How many decimal places do you really need your calculations accurate to? 4, 8, 12?
As Gabriel says, Doubles are generally good enough.


Nate the Great(Posted 2009) [#5]
2147483647 is plenty of places!!! oh ok I will check out your module brucey but I know it is floating point inacuracy because I have so many equations in a row that use variables from previous equations etc and it does this 10 times a loop to be as accurate as possible for collisions. I guess inacurate but stable physics is better than acurate and unstable physics. I just wanted to know if there was higher precicion.


Floyd(Posted 2009) [#6]
Double precision should be plenty good enough.

If your calculations are unstable then there are two possibilities. You may be modeling a physically unstable system, in which case there is not much you can do. Or the system is stable but the calculation is not, in which case your algorithms need work.


Otus(Posted 2009) [#7]
It is possible to run into floating point accuracy, but then you may be doing something 'wrong' - at least in some sense of the word. Examples include: adding and subtracting numbers that differ by multiple orders of magnitude, multiplying exponentiated numbers vs. adding the exponents, etc. Series approximations and iterative techniques may often trump 'exact' formulas, when you are using floating point numbers.


Nate the Great(Posted 2009) [#8]
@ Floyd - I dont think it is an unstable equation, it just makes 2 pixel jumps that get very annoying due to very small floating point inacuracy :( I have given up the equation though so the question no longer matters.