lua-users home
lua-l archive

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


On 11/19/2017 1:35 PM, Paige DePol wrote:
KHMan wrote:

If I thought it was an open-and-shut case I would have called it a bug and
offered a patch. But no, perhaps my bias is that I have seen all too many
corner cases in my time and have no desire to handle or fix each and every
corner case. For example, for automotive firmware, one codes a only subset
of what a language is capable of, one does not step on the slippery stuff.
It's hardly ideal, yet this is what companies like SpaceX do successfully
-- that is, use C++ carefully instead of Ada.

I would consider it a bug... the issue is with the implementation. If you
loop from math.maxinteger - 10 to math.maxinteger I would not expect Lua to
enter into an infinite loop. The issue is simply one of logic in the looping
code in OP_FORPREP and OP_FORLOOP. By fixing this logic it fixes the edge
case when using min/max integer values in loops... which appropriately fixes
the sample code you provided, along with all the other edge cases provided.

I have no problem with a diversity of views. All you need to do now is to convince Roberto that he needs the patch... :-)

As for myself, I will take note of whatever the eventual outcome and get on with coding. My brain is already primed to sound klaxons on seeing math.huge. Keeping 2s complement arithmetic in looping and its flaw(s) isn't perfect but it's a known quantity. Patching the looping code would make it "2s complement but not quite 2s complement". Either way, I hope we can have some updates to the section on numerical loops in the reference manual.

Look at the patch I provided... it is an open-and-shut case, the issue was
fixed by a very simple logic adjustment. The entire test suite still runs as
expected, it just removes the need for the coder to be aware of the edge
case using min/max integers as they now work as one would expect.
[snip snip snip]


--
Cheers,
Kein-Hong Man (esq.)
Selangor, Malaysia