lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> "NoW" means "Nitpicking on Wednesdays"
> (unimportant questions about Lua design and implementation)
> 
> Let's start with two simple examples:
>    for x = -2^53, -2^53 do print(x) end
>    for x = 1e100, 1e100 do print(x) end
> Did you expect such results?
> 
> There is a problem in numeric "for"-loop: Lua internally exceeds the range
> of values specified by user.
> 
> [...]

Maybe there is a simpler way for integer loops. I guess we could use
simple arithmetic to precompute, when entering the loop, how many times
it will iterate. Then, during the loop, we simply decrement the counter
until it reaches zero, without worries about overflows.

For loops with floating numbers, I guess the best is to do the "obvious"
computations (without the subtraction), due to all these problems with
precision.

-- Roberto