MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / luaV_idiv

Function luaV_idiv

third-party/lua-5.4.6/src/lvm.c:728–740  ·  view source on GitHub ↗

** Integer division; return 'm // n', that is, floor(m/n). ** C division truncates its result (rounds towards zero). ** 'floor(q) == trunc(q)' when 'q >= 0' or when 'q' is integer, ** otherwise 'floor(q) == trunc(q) - 1'. */

Source from the content-addressed store, hash-verified

726** otherwise 'floor(q) == trunc(q) - 1'.
727*/
728lua_Integer luaV_idiv (lua_State *L, lua_Integer m, lua_Integer n) {
729 if (l_unlikely(l_castS2U(n) + 1u <= 1u)) { /* special cases: -1 or 0 */
730 if (n == 0)
731 luaG_runerror(L, "attempt to divide by zero");
732 return intop(-, 0, m); /* n==-1; avoid overflow with 0x80000...//-1 */
733 }
734 else {
735 lua_Integer q = m / n; /* perform C division */
736 if ((m ^ n) < 0 && m % n != 0) /* 'm/n' would be negative non-integer? */
737 q -= 1; /* correct result for different rounding */
738 return q;
739 }
740}
741
742
743/*

Callers 1

intarithFunction · 0.70

Calls 1

luaG_runerrorFunction · 0.70

Tested by

no test coverage detected