mirror of https://github.com/rusefi/lua.git
use unsigneds for unary minus, too
This commit is contained in:
parent
b5f5fcd782
commit
2f8c51a552
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lbaselib.c,v 1.278 2013/07/05 14:35:49 roberto Exp roberto $
|
** $Id: lbaselib.c,v 1.279 2013/07/05 14:39:15 roberto Exp roberto $
|
||||||
** Basic library
|
** Basic library
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -63,7 +63,7 @@ static int b_str2int (const char *s, const char *e, int base, lua_Integer *pn) {
|
||||||
s += strspn(s, SPACECHARS); /* skip trailing spaces */
|
s += strspn(s, SPACECHARS); /* skip trailing spaces */
|
||||||
if (s != e) /* invalid trailing characters? */
|
if (s != e) /* invalid trailing characters? */
|
||||||
return 0;
|
return 0;
|
||||||
*pn = (neg) ? -(lua_Integer)n : (lua_Integer)n;
|
*pn = (lua_Integer)((neg) ? (0u - n) : n);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lobject.c,v 2.66 2013/06/04 19:36:42 roberto Exp roberto $
|
** $Id: lobject.c,v 2.67 2013/06/25 18:58:32 roberto Exp roberto $
|
||||||
** Some generic functions over Lua objects
|
** Some generic functions over Lua objects
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -78,7 +78,7 @@ static lua_Integer intarith (lua_State *L, int op, lua_Integer v1,
|
||||||
case LUA_OPMUL:return intop(*, v1, v2);
|
case LUA_OPMUL:return intop(*, v1, v2);
|
||||||
case LUA_OPMOD: return luaV_mod(L, v1, v2);
|
case LUA_OPMOD: return luaV_mod(L, v1, v2);
|
||||||
case LUA_OPPOW: return luaV_pow(v1, v2);
|
case LUA_OPPOW: return luaV_pow(v1, v2);
|
||||||
case LUA_OPUNM: return -v1;
|
case LUA_OPUNM: return intop(-, 0, v1);
|
||||||
default: lua_assert(0); return 0;
|
default: lua_assert(0); return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -260,8 +260,7 @@ int luaO_str2int (const char *s, size_t len, lua_Integer *result) {
|
||||||
while (lisspace(cast_uchar(*s))) s++; /* skip trailing spaces */
|
while (lisspace(cast_uchar(*s))) s++; /* skip trailing spaces */
|
||||||
if (empty || s != ends) return 0; /* something wrong in the numeral */
|
if (empty || s != ends) return 0; /* something wrong in the numeral */
|
||||||
else {
|
else {
|
||||||
if (neg) *result = -cast(lua_Integer, a);
|
*result = cast_integer((neg) ? 0u - a : a);
|
||||||
else *result = cast(lua_Integer, a);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
6
lvm.c
6
lvm.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lvm.c,v 2.174 2013/06/19 14:27:00 roberto Exp roberto $
|
** $Id: lvm.c,v 2.175 2013/06/20 15:02:49 roberto Exp roberto $
|
||||||
** Lua virtual machine
|
** Lua virtual machine
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -334,7 +334,7 @@ lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y) {
|
||||||
if (y == 0)
|
if (y == 0)
|
||||||
luaG_runerror(L, "attempt to divide by zero");
|
luaG_runerror(L, "attempt to divide by zero");
|
||||||
else /* -1 */
|
else /* -1 */
|
||||||
return -x; /* avoid overflow with 0x80000... */
|
return intop(-, 0, x); /* avoid overflow with 0x80000... */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
lua_Integer d = x / y; /* perform division */
|
lua_Integer d = x / y; /* perform division */
|
||||||
|
@ -699,7 +699,7 @@ void luaV_execute (lua_State *L) {
|
||||||
lua_Number nb;
|
lua_Number nb;
|
||||||
if (ttisinteger(rb)) {
|
if (ttisinteger(rb)) {
|
||||||
lua_Integer ib = ivalue(rb);
|
lua_Integer ib = ivalue(rb);
|
||||||
setivalue(ra, -ib);
|
setivalue(ra, intop(-, 0, ib));
|
||||||
}
|
}
|
||||||
else if (tonumber(rb, &nb)) {
|
else if (tonumber(rb, &nb)) {
|
||||||
setnvalue(ra, luai_numunm(L, nb));
|
setnvalue(ra, luai_numunm(L, nb));
|
||||||
|
|
Loading…
Reference in New Issue