|
You're right, I've tried the same in C and got "incorrect" results too.On 03/31/2013 04:27 PM, Kevin Martin wrote:
On 31 Mar 2013, at 09:06, vitaminx wrote:
With this simple one-liner I can reproduce the following arithmetic error:Are you sure this is a Lua error? Can you give a language/example where this works as you expected?
for var=10,0,-0.1 do print(var) end
Unless using fixed/arbitrary precision, which have their own trade-offs, non-integer numbers in a computer tend to be stored in standard form in base 2. There will be a finite number of digits for both the mantissa and exponent (52 and 11 IIRC for normal Lua).
Try and write 1/10 in standard form in base 2, and you will see the problem.
Thanks,
Kev
Never had to use for loops with floats before, so I never ran into this issue.