MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / luaV_mod

Function luaV_mod

lib/lua/src/lvm.c:755–767  ·  view source on GitHub ↗

** Integer modulus; return 'm % n'. (Assume that C '%' with ** negative operands follows C99 behavior. See previous comment ** about luaV_idiv.) */

Source from the content-addressed store, hash-verified

753** about luaV_idiv.)
754*/
755lua_Integer luaV_mod (lua_State *L, lua_Integer m, lua_Integer n) {
756 if (l_unlikely(l_castS2U(n) + 1u <= 1u)) { /* special cases: -1 or 0 */
757 if (n == 0)
758 luaG_runerror(L, "attempt to perform 'n%%0'");
759 return 0; /* m % -1 == 0; avoid overflow with 0x80000...%-1 */
760 }
761 else {
762 lua_Integer r = m % n;
763 if (r != 0 && (r ^ n) < 0) /* 'm/n' would be non-integer negative? */
764 r += n; /* correct result for different rounding */
765 return r;
766 }
767}
768
769
770/*

Callers 1

intarithFunction · 0.85

Calls 1

luaG_runerrorFunction · 0.85

Tested by

no test coverage detected