** Integer modulus; return 'm % n'. (Assume that C '%' with ** negative operands follows C99 behavior. See previous comment ** about luaV_idiv.) */
| 733 | ** about luaV_idiv.) |
| 734 | */ |
| 735 | lua_Integer luaV_mod (lua_State *L, lua_Integer m, lua_Integer n) { |
| 736 | if (unlikely(l_castS2U(n) + 1u <= 1u)) { /* special cases: -1 or 0 */ |
| 737 | if (n == 0) |
| 738 | luaG_runerror(L, "attempt to perform 'n%%0'"); |
| 739 | return 0; /* m % -1 == 0; avoid overflow with 0x80000...%-1 */ |
| 740 | } |
| 741 | else { |
| 742 | lua_Integer r = m % n; |
| 743 | if (r != 0 && (r ^ n) < 0) /* 'm/n' would be non-integer negative? */ |
| 744 | r += n; /* correct result for different rounding */ |
| 745 | return r; |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | |
| 750 | /* |
no test coverage detected