01-28-2016, 11:43 PM
(01-28-2016, 11:38 AM)Segolia Wrote: What's the actual code - simplifying the code to it's intended logical steps in pseudocode won't help resolve issues with the actual code.This is literally the code. The only difference is I replaced the things I was changing with generic value names, which would make no difference in practice, and cut out all the stuff that doesn't affect those values in any way at all.
If I had to take a random guess, since the logic seems to be giving you approximately correct values it's type fuckery, and floats are getting cast to ints or whatever in a way that the computer doesn't play nice with.
I don't understand how it can be messing with the types, since I've done much more complicated things with ints, floats, etc. being thrown around like... something which gets thrown around a lot, and the equations work fine.
(01-28-2016, 07:03 PM)OdinYggd Wrote: But it is how math works on computers.But even the first iteration of the calculation rounds wrong, directly after defining the variables and giving them their initial values, so I don't see how it can be an error caused by the number of calculations.
What you have encountered is the phenomena of Float Rounding. Basically, even decimal places to us are only rarely perfectly represented in binary. So the computer approximates as best it can.
Over time that little bit of error on EVERY SINGLE CALCULATION adds up significantly and causes weird phenomena.
In Kerbal Space Program, the phenomena would cause a ship to accelerate to speeds in excess of the speed of light when making a hairpin turn around the sun. The forces applied to the ship in such a maneuver would trigger float rounding to appear with an exponentially increasing result that would fling the ship into deep space at insane multiples of the speed of light.
I'll probably throw in a line to round it off... I think there are rounding functions in LUA? I don't really use stuff like that often, because usually when I work with simple values at a few decimals or integers it doesn't screw up and give me incorrect numbers :/
Apparently all numbers are already stored as doubles so that won't work. Rounding it is.