[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [PATCH] Loop Overflow Bug Fix
- From: Paige DePol <lual@...>
- Date: Mon, 20 Nov 2017 21:17:19 -0600
KHMan <keinhong@gmail.com> wrote:
> Sorry to myself for not being specific enough. I was discussing the integer portion, I thought that was obvious. I assumed the specified loop pseudo-code intentionally matches C-style loop behaviour, and so integer loops are more or less 2s complement thingies. I'm happy to follow specifications, that is, the pseudo-code.
>
> All those terminology ends up just being terminology when you get to corner cases. Try these:
>
> local j = 1
> for i = 2^53-10,math.huge do
> print(string.format("%4d %20d", j, i))
> j = j + 1; if j == 20 then return end
> end
With my patch I get "lua: khman.lua:3: 'for' step magnitude too small" and
the script dies, in vanilla Lua it terminates due to 'j' becoming 20.
> local j = 1
> for i = 2^53-10,2^53 do
> print(string.format("%4d %20d", j, i))
> j = j + 1; if j == 20 then return end
> end
This loop executes correctly with my patch.
> local j = 1
> for i = 2^53-10,2^53+1 do
> print(string.format("%4d %20d", j, i))
> j = j + 1; if j == 20 then return end
> end
This loop iterates 11 times instead of 12, then terminates and the code
continues to the next loop.
> local j = 1
> for i = 2^53-10,2^53+2 do
> print(string.format("%4d %20d", j, i))
> j = j + 1; if j == 20 then return end
> end
This loop does not iterate correctly, it runs until 'j' becomes 20 once
'i' becomes stuck at 9007199254740992 on iteration #12.
> Corner cases are fun, as long as one does not use them in serious code.
Being aware of them is always nice, however, if the math.[min/max]integer
values are going to be used in examples of loop constructs then those
particular edge cases probably should be handled by Lua... or documented,
either way I guess.
~Paige
- References:
- [PATCH] Loop Overflow Bug Fix, Paige DePol
- Re: [PATCH] Loop Overflow Bug Fix, dyngeccetor8
- Re: [PATCH] Loop Overflow Bug Fix, Paige DePol
- Re: [PATCH] Loop Overflow Bug Fix, Paige DePol
- Re: [PATCH] Loop Overflow Bug Fix, Roberto Ierusalimschy
- Re: [PATCH] Loop Overflow Bug Fix, Paige DePol
- Re: [PATCH] Loop Overflow Bug Fix, Roberto Ierusalimschy
- Re: [PATCH] Loop Overflow Bug Fix, Paige DePol
- Re: [PATCH] Loop Overflow Bug Fix, Paige DePol
- Re: [PATCH] Loop Overflow Bug Fix, Dirk Laurie
- Re: [PATCH] Loop Overflow Bug Fix, Hisham
- Re: [PATCH] Loop Overflow Bug Fix, Coda Highland
- Re: [PATCH] Loop Overflow Bug Fix, KHMan
- Re: [PATCH] Loop Overflow Bug Fix, Paige DePol
- Re: [PATCH] Loop Overflow Bug Fix, KHMan
- Re: [PATCH] Loop Overflow Bug Fix, Paige DePol
- Re: [PATCH] Loop Overflow Bug Fix, KHMan
- Re: [PATCH] Loop Overflow Bug Fix, Coda Highland
- Re: [PATCH] Loop Overflow Bug Fix, KHMan