01-28-2016, 07:03 PM
(01-28-2016, 11:28 AM)Shaadaris Wrote: *Flips table of values*
ARGIULWUDHBNWIDHUWIHU
THIS IS RIDICULOUS.
Here's the very basic, absolute minimum barebones version of the LUA code that I'm using right now:
Code:
val1 = 0.25
val2 = 2
val3 = 1
repeat
wait(0.01)
print(val3 .. "\n --- \n")
val3 = val3 - val1 / 100 * val2
until (val3 == 0)
Makes sense, right?
val3 goes to 0.995, then to 0.990, and so on, until it's 0.
...Or rather, that's what it should be doing, because apparently I BROKE MATH ITSELF.
Here's the output I get:
and so on...Code:
1
---
1
---
0.99500000476837
---
0.99500000476837
---
0.99000000953674
---
0.99000000953674
---
0.98500001430511
---
0.98500001430511
---
0.98000001907349
---
0.98000001907349
---
0.97500002384186
---
0.97500002384186
---
0.97000002861023
---
0.97000002861023
---
0.9650000333786
---
0.9650000333786
---
0.96000003814697
---
0.96000003814697
---
0.95500004291534
---
0.95500004291534
---
0.95000004768372
---
0.95000004768372
---
0.94500005245209
---
0.94500005245209
---
THIS MAKES NO SENSE. THIS IS NOT HOW YOU MATH. I EVEN CHECKED WITH A CALCULATOR.
But it is how math works on computers.
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.
Feel free to PM me if anything is broken