| 115 | |
| 116 | |
| 117 | static int math_fmod (lua_State *L) { |
| 118 | if (lua_isinteger(L, 1) && lua_isinteger(L, 2)) { |
| 119 | lua_Integer d = lua_tointeger(L, 2); |
| 120 | if ((lua_Unsigned)d + 1u <= 1u) { /* special cases: -1 or 0 */ |
| 121 | luaL_argcheck(L, d != 0, 2, "zero"); |
| 122 | lua_pushinteger(L, 0); /* avoid overflow with 0x80000... / -1 */ |
| 123 | } |
| 124 | else |
| 125 | lua_pushinteger(L, lua_tointeger(L, 1) % d); |
| 126 | } |
| 127 | else |
| 128 | lua_pushnumber(L, l_mathop(fmod)(luaL_checknumber(L, 1), |
| 129 | luaL_checknumber(L, 2))); |
| 130 | return 1; |
| 131 | } |
| 132 | |
| 133 | |
| 134 | /* |
nothing calls this directly
no test coverage detected