summaryrefslogtreecommitdiff
path: root/src/lmathlib.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/lmathlib.js')
-rw-r--r--src/lmathlib.js7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/lmathlib.js b/src/lmathlib.js
index 3e4486a..0c3b715 100644
--- a/src/lmathlib.js
+++ b/src/lmathlib.js
@@ -44,8 +44,11 @@ const math_random = function(L) {
};
const math_abs = function(L) {
- if (lua.lua_isinteger(L, 1))
- lua.lua_pushinteger(L, Math.abs(lua.lua_tointeger(L, 1)));
+ if (lua.lua_isinteger(L, 1)) {
+ let n = lua.lua_tointeger(L, 1);
+ if (n < 0) n = (-n)|0;
+ lua.lua_pushinteger(L, n);
+ }
else
lua.lua_pushnumber(L, Math.abs(lauxlib.luaL_checknumber(L, 1)));
return 1;