| 87 | |
| 88 | |
| 89 | int luaO_rawarith (lua_State *L, int op, const TValue *p1, const TValue *p2, |
| 90 | TValue *res) { |
| 91 | switch (op) { |
| 92 | case LUA_OPBAND: case LUA_OPBOR: case LUA_OPBXOR: |
| 93 | case LUA_OPSHL: case LUA_OPSHR: |
| 94 | case LUA_OPBNOT: { /* operate only on integers */ |
| 95 | lua_Integer i1; lua_Integer i2; |
| 96 | if (tointegerns(p1, &i1) && tointegerns(p2, &i2)) { |
| 97 | setivalue(res, intarith(L, op, i1, i2)); |
| 98 | return 1; |
| 99 | } |
| 100 | else return 0; /* fail */ |
| 101 | } |
| 102 | case LUA_OPDIV: case LUA_OPPOW: { /* operate only on floats */ |
| 103 | lua_Number n1; lua_Number n2; |
| 104 | if (tonumberns(p1, n1) && tonumberns(p2, n2)) { |
| 105 | setfltvalue(res, numarith(L, op, n1, n2)); |
| 106 | return 1; |
| 107 | } |
| 108 | else return 0; /* fail */ |
| 109 | } |
| 110 | default: { /* other operations */ |
| 111 | lua_Number n1; lua_Number n2; |
| 112 | if (ttisinteger(p1) && ttisinteger(p2)) { |
| 113 | setivalue(res, intarith(L, op, ivalue(p1), ivalue(p2))); |
| 114 | return 1; |
| 115 | } |
| 116 | else if (tonumberns(p1, n1) && tonumberns(p2, n2)) { |
| 117 | setfltvalue(res, numarith(L, op, n1, n2)); |
| 118 | return 1; |
| 119 | } |
| 120 | else return 0; /* fail */ |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | |
| 126 | void luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2, |
no test coverage detected