lua-users home
lua-l archive

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


> > I had another small issue on luaV_numtointeger(). I had an 'integer
> > overflow' on the line 81 of lvm.c. I solved as follows:
> > 
> > -  if (cast_num(MIN_INTEGER) <= n && n < (MAX_INTEGER + cast_num(1))) {
> > +  if (cast_num(MIN_INTEGER) <= n && (n - cast_num(1)) < MAX_INTEGER) {
> 
> This is tricky... In my machine, this change does not pass the standard
> tests for vanilla Lua (64-bit floats and integers). (I am trying to figure
> out why, but when I add some printfs to the code, it works again; weird...)

With the new code, the machine does all computations for
(n - cast_num(1)) < MAX_INTEGER in registers, with more precision than
64 bits. We do need the "overflow" here to get the right result.
(Think when 'n' is 2.0^63, which does not fit into a 64-bit integer.)

-- Roberto