lua-users home
lua-l archive

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


Le jeu. 15 nov. 2018 à 20:41, Egor Skriptunoff <egor.skriptunoff@gmail.com> a écrit :
So, when parsing "for j = 1, 1e4 do", Ravi should conclude that "j" is integer, similar to how Lua 5.3 deduces type of loop variable.
This way there would be no reason to replace 1e4 with 10000

an integer yes, but in the value range of numbers (i.e. IEEE doubles...). Just retry with
  for j = 1, 1e99 do
and you'll conclude that j cannot be a 32-bit (or even 64-bit) integer because the upper limit is largely above MAXINT+1.

Note also that this loop would even be infinite in Lua (because adding incremental step of 1 will cease to be significant when j reaches 2^53 (if Lua "numbers" are compiled as IEEE 64-bit doubles) like in this example:
  for j = 2**53, 2**53+2**15-1 do
which you could expect perform (2**15)=32768 loops exactly, but will instead loop infinitely with j constantly set to the same start value (2**53), and the default step=1 has no effect (same here as step=0)... Lua does not check that (start+step != start) and that (limit-step != limit), i.e. that there will be an effective linear progression and that the limit will be reachable.