** Integer modulus; return 'm % n'. (Assume that C '%' with ** negative operands follows C99 behavior. See previous comment ** about luaV_idiv.) */
| 753 | ** about luaV_idiv.) |
| 754 | */ |
| 755 | lua_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 | /* |
no test coverage detected