lua-users home
lua-l archive

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


It was thus said that the Great Egor Skriptunoff once stated:
> On Thu, May 9, 2019 at 7:59 PM Egor Skriptunoff wrote:
> 
> > On Thu, May 9, 2019 at 7:43 PM Dirk Laurie wrote:
> >
> >>
> >> It's a ten-line patch to lvm.c:
> >> 534a535,544
> >> >     case LUA_TNUMINT: {
> >> >       lua_Integer n=ivalue(rb);
> >> >       setivalue(ra,n<0?-n:n);
> >> >       return;
> >> >     }
> >>
> >
> > Ten lines are not enough.
> > What result would you expect for INT_MIN ?
> >
> 
> BTW, math.abs(1<<63) in both Lua 5.3 and 5.4 returns negative value.
> That's a bug.

  That's also a bug in most CPUs (those that are 2's complement), although a
number will set the overflow flag [1] to signal the condision [2].

  -spc

[1]	6809, 8080, Z80, 68k series, x86 series do; other CPUs might as
	well.

[2]	The VAX doesn't.  Also, there's no integer instruction on the MIPS
	that does negation.  There are two obvious sequences that will do
	negation, but only one will trap on overflow.