diff options
author | daurnimator <quae@daurnimator.com> | 2017-05-21 20:46:54 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-05-21 20:46:54 +1000 |
commit | 93c8906ca2f77270054edb9f7669ca9b06f80b6f (patch) | |
tree | 0cdb8bf236bf9372f840ced37e951b510509be04 /src/lmathlib.js | |
parent | 7b7775f9edd1fd68bb4f6ec975fc08985e898816 (diff) | |
download | fengari-93c8906ca2f77270054edb9f7669ca9b06f80b6f.tar.gz fengari-93c8906ca2f77270054edb9f7669ca9b06f80b6f.tar.bz2 fengari-93c8906ca2f77270054edb9f7669ca9b06f80b6f.zip |
src/lmathlib.js: fix fmod: plain javascript % operator has correct behaviour
Diffstat (limited to 'src/lmathlib.js')
-rw-r--r-- | src/lmathlib.js | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/lmathlib.js b/src/lmathlib.js index 8c7b8a5..3e4486a 100644 --- a/src/lmathlib.js +++ b/src/lmathlib.js @@ -203,15 +203,15 @@ const math_type = function(L) { const math_fmod = function(L) { if (lua.lua_isinteger(L, 1) && lua.lua_isinteger(L, 2)) { let d = lua.lua_tointeger(L, 2); - if (Math.abs(d) + 1 <= 1) { - lauxlib.luaL_argcheck(L, d !== 0, 2, lua.to_luastring("zero", true)); - lua.lua_pushinteger(L, 0); + /* no special case needed for -1 in javascript */ + if (d === 0) { + lauxlib.luaL_argerror(L, 2, lua.to_luastring("zero", true)); } else - lua.lua_pushinteger(L, lua.lua_tointeger(L, 1) % d); + lua.lua_pushinteger(L, (lua.lua_tointeger(L, 1) % d)|0); } else { let a = lauxlib.luaL_checknumber(L, 1); let b = lauxlib.luaL_checknumber(L, 2); - lua.lua_pushnumber(L, Number((a - (Math.floor(a / b) * b)).toPrecision(8))); + lua.lua_pushnumber(L, a%b); } return 1; }; |