| 125 | |
| 126 | |
| 127 | static int math_fmod (lua_State *L) { |
| 128 | if (lua_isinteger(L, 1) && lua_isinteger(L, 2)) { |
| 129 | lua_Integer d = lua_tointeger(L, 2); |
| 130 | if ((lua_Unsigned)d + 1u <= 1u) { /* special cases: -1 or 0 */ |
| 131 | luaL_argcheck(L, d != 0, 2, "zero"); |
| 132 | lua_pushinteger(L, 0); /* avoid overflow with 0x80000... / -1 */ |
| 133 | } |
| 134 | else |
| 135 | lua_pushinteger(L, lua_tointeger(L, 1) % d); |
| 136 | } |
| 137 | else |
| 138 | lua_pushnumber(L, l_mathop(fmod)(luaL_checknumber(L, 1), |
| 139 | luaL_checknumber(L, 2))); |
| 140 | return 1; |
| 141 | } |
| 142 | |
| 143 | |
| 144 | /* |
nothing calls this directly
no test coverage detected