MCPcopy Create free account
hub / github.com/Overload-Technologies/Overload / luaV_idiv

Function luaV_idiv

Dependencies/lua/src/lvm.c:725–737  ·  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

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

Callers 1

intarithFunction · 0.85

Calls 1

luaG_runerrorFunction · 0.85

Tested by

no test coverage detected