mirror of
https://github.com/lua/lua
synced 2025-03-25 07:02:51 +03:00
'x//y' extended to floats
This commit is contained in:
parent
049cf14cf9
commit
5fbd40dbe5
6
lcode.c
6
lcode.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lcode.c,v 2.94 2014/10/30 18:53:28 roberto Exp roberto $
|
** $Id: lcode.c,v 2.95 2014/11/02 19:19:04 roberto Exp roberto $
|
||||||
** Code generator for Lua
|
** Code generator for Lua
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -768,12 +768,10 @@ static int validop (int op, TValue *v1, TValue *v2) {
|
|||||||
(cast_void(tonumber(v2, &b)), b)))
|
(cast_void(tonumber(v2, &b)), b)))
|
||||||
return 0;
|
return 0;
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case LUA_OPIDIV: /* division by 0 and conversion errors */
|
|
||||||
return (tointeger(v1, &i) && tointeger(v2, &i) && i != 0);
|
|
||||||
case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR:
|
case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR:
|
||||||
case LUA_OPSHL: case LUA_OPSHR: case LUA_OPBNOT: /* conversion errors */
|
case LUA_OPSHL: case LUA_OPSHR: case LUA_OPBNOT: /* conversion errors */
|
||||||
return (tointeger(v1, &i) && tointeger(v2, &i));
|
return (tointeger(v1, &i) && tointeger(v2, &i));
|
||||||
case LUA_OPMOD: /* integer module by 0 */
|
case LUA_OPIDIV: case LUA_OPMOD: /* integer division by 0 */
|
||||||
return !(ttisinteger(v1) && ttisinteger(v2) && ivalue(v2) == 0);
|
return !(ttisinteger(v1) && ttisinteger(v2) && ivalue(v2) == 0);
|
||||||
default: return 1; /* everything else is valid */
|
default: return 1; /* everything else is valid */
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lobject.c,v 2.98 2014/11/02 19:19:04 roberto Exp roberto $
|
** $Id: lobject.c,v 2.99 2014/11/04 19:16:25 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
|
||||||
*/
|
*/
|
||||||
@ -101,6 +101,7 @@ static lua_Number numarith (lua_State *L, int op, lua_Number v1,
|
|||||||
case LUA_OPMUL: return luai_nummul(L, v1, v2);
|
case LUA_OPMUL: return luai_nummul(L, v1, v2);
|
||||||
case LUA_OPDIV: return luai_numdiv(L, v1, v2);
|
case LUA_OPDIV: return luai_numdiv(L, v1, v2);
|
||||||
case LUA_OPPOW: return luai_numpow(L, v1, v2);
|
case LUA_OPPOW: return luai_numpow(L, v1, v2);
|
||||||
|
case LUA_OPIDIV: return luai_numidiv(L, v1, v2);
|
||||||
case LUA_OPUNM: return luai_numunm(L, v1);
|
case LUA_OPUNM: return luai_numunm(L, v1);
|
||||||
case LUA_OPMOD: {
|
case LUA_OPMOD: {
|
||||||
lua_Number m;
|
lua_Number m;
|
||||||
@ -115,9 +116,9 @@ static lua_Number numarith (lua_State *L, int op, lua_Number v1,
|
|||||||
void luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2,
|
void luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2,
|
||||||
TValue *res) {
|
TValue *res) {
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case LUA_OPIDIV: case LUA_OPBAND: case LUA_OPBOR:
|
case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR:
|
||||||
case LUA_OPBXOR: case LUA_OPSHL: case LUA_OPSHR:
|
case LUA_OPSHL: case LUA_OPSHR:
|
||||||
case LUA_OPBNOT: { /* operates only on integers */
|
case LUA_OPBNOT: { /* operate only on integers */
|
||||||
lua_Integer i1; lua_Integer i2;
|
lua_Integer i1; lua_Integer i2;
|
||||||
if (tointeger(p1, &i1) && tointeger(p2, &i2)) {
|
if (tointeger(p1, &i1) && tointeger(p2, &i2)) {
|
||||||
setivalue(res, intarith(L, op, i1, i2));
|
setivalue(res, intarith(L, op, i1, i2));
|
||||||
|
6
ltm.c
6
ltm.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: ltm.c,v 2.31 2014/11/10 14:46:05 roberto Exp roberto $
|
** $Id: ltm.c,v 2.32 2014/11/10 17:24:43 roberto Exp roberto $
|
||||||
** Tag methods
|
** Tag methods
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -117,12 +117,12 @@ void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2,
|
|||||||
switch (event) {
|
switch (event) {
|
||||||
case TM_CONCAT:
|
case TM_CONCAT:
|
||||||
luaG_concaterror(L, p1, p2);
|
luaG_concaterror(L, p1, p2);
|
||||||
case TM_IDIV: case TM_BAND: case TM_BOR: case TM_BXOR:
|
case TM_BAND: case TM_BOR: case TM_BXOR:
|
||||||
case TM_SHL: case TM_SHR: case TM_BNOT: {
|
case TM_SHL: case TM_SHR: case TM_BNOT: {
|
||||||
lua_Number dummy;
|
lua_Number dummy;
|
||||||
if (tonumber(p1, &dummy) && tonumber(p2, &dummy))
|
if (tonumber(p1, &dummy) && tonumber(p2, &dummy))
|
||||||
luaG_tointerror(L, p1, p2);
|
luaG_tointerror(L, p1, p2);
|
||||||
else if (event != TM_IDIV)
|
else
|
||||||
luaG_opinterror(L, p1, p2, "perform bitwise operation on");
|
luaG_opinterror(L, p1, p2, "perform bitwise operation on");
|
||||||
/* else go through */
|
/* else go through */
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user