Browse Source

no more integer exponentiation

pull/9/head
Roberto Ierusalimschy 11 years ago
parent
commit
27d9219cf3
  1. 8
      lobject.c
  2. 25
      lvm.c
  3. 3
      lvm.h

8
lobject.c

@ -1,5 +1,5 @@
/*
** $Id: lobject.c,v 2.83 2014/04/30 16:48:44 roberto Exp roberto $
** $Id: lobject.c,v 2.84 2014/05/01 18:18:06 roberto Exp roberto $
** Some generic functions over Lua objects
** See Copyright Notice in lua.h
*/
@ -77,7 +77,6 @@ static lua_Integer intarith (lua_State *L, int op, lua_Integer v1,
case LUA_OPSUB:return intop(-, v1, v2);
case LUA_OPMUL:return intop(*, v1, v2);
case LUA_OPMOD: return luaV_mod(L, v1, v2);
case LUA_OPPOW: return luaV_pow(v1, v2);
case LUA_OPIDIV: return luaV_div(L, v1, v2);
case LUA_OPBAND: return intop(&, v1, v2);
case LUA_OPBOR: return intop(|, v1, v2);
@ -123,7 +122,7 @@ void luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2,
}
else break; /* go to the end */
}
case LUA_OPDIV: { /* operates only on floats */
case LUA_OPDIV: case LUA_OPPOW: { /* operate only on floats */
lua_Number n1; lua_Number n2;
if (tonumber(p1, &n1) && tonumber(p2, &n2)) {
setfltvalue(res, numarith(L, op, n1, n2));
@ -133,8 +132,7 @@ void luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2,
}
default: { /* other operations */
lua_Number n1; lua_Number n2;
if (ttisinteger(p1) && ttisinteger(p2) &&
(op != LUA_OPPOW || ivalue(p2) >= 0)) {
if (ttisinteger(p1) && ttisinteger(p2)) {
setivalue(res, intarith(L, op, ivalue(p1), ivalue(p2)));
return;
}

25
lvm.c

@ -1,5 +1,5 @@
/*
** $Id: lvm.c,v 2.206 2014/05/09 14:20:52 roberto Exp roberto $
** $Id: lvm.c,v 2.207 2014/05/12 19:13:32 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@ -480,22 +480,6 @@ lua_Integer luaV_mod (lua_State *L, lua_Integer m, lua_Integer n) {
}
lua_Integer luaV_pow (lua_Integer m, lua_Integer n) {
lua_assert(n >= 0);
if (n == 0)
return 1; /* m^0 == 1 */
else {
lua_Integer r = 1;
for (; n > 1; n >>= 1) {
if (n & 1) r = intop(*, r, m);
m = intop(*, m, m);
}
r = intop(*, r, m);
return r;
}
}
/* number of bits in an integer */
#define NBITS cast_int(sizeof(lua_Integer) * CHAR_BIT)
@ -869,12 +853,7 @@ void luaV_execute (lua_State *L) {
TValue *rb = RKB(i);
TValue *rc = RKC(i);
lua_Number nb; lua_Number nc;
lua_Integer ic;
if (ttisinteger(rb) && ttisinteger(rc) && (ic = ivalue(rc)) >= 0) {
lua_Integer ib = ivalue(rb);
setivalue(ra, luaV_pow(ib, ic));
}
else if (tonumber(rb, &nb) && tonumber(rc, &nc)) {
if (tonumber(rb, &nb) && tonumber(rc, &nc)) {
setfltvalue(ra, luai_numpow(L, nb, nc));
}
else { Protect(luaT_trybinTM(L, rb, rc, ra, TM_POW)); }

3
lvm.h

@ -1,5 +1,5 @@
/*
** $Id: lvm.h,v 2.28 2014/04/15 16:32:49 roberto Exp roberto $
** $Id: lvm.h,v 2.29 2014/04/27 14:41:11 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@ -40,7 +40,6 @@ LUAI_FUNC void luaV_execute (lua_State *L);
LUAI_FUNC void luaV_concat (lua_State *L, int total);
LUAI_FUNC lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y);
LUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y);
LUAI_FUNC lua_Integer luaV_pow (lua_Integer x, lua_Integer y);
LUAI_FUNC lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y);
LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb);

Loading…
Cancel
Save