** 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'. */
| 716 | ** otherwise 'floor(q) == trunc(q) - 1'. |
| 717 | */ |
| 718 | lua_Integer luaV_idiv (lua_State *L, lua_Integer m, lua_Integer n) { |
| 719 | if (l_unlikely(l_castS2U(n) + 1u <= 1u)) { /* special cases: -1 or 0 */ |
| 720 | if (n == 0) |
| 721 | luaG_runerror(L, "attempt to divide by zero"); |
| 722 | return intop(-, 0, m); /* n==-1; avoid overflow with 0x80000...//-1 */ |
| 723 | } |
| 724 | else { |
| 725 | lua_Integer q = m / n; /* perform C division */ |
| 726 | if ((m ^ n) < 0 && m % n != 0) /* 'm/n' would be negative non-integer? */ |
| 727 | q -= 1; /* correct result for different rounding */ |
| 728 | return q; |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | |
| 733 | /* |
no test coverage detected