** 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'. */
| 370 | ** otherwise 'floor(q) == trunc(q) - 1'. |
| 371 | */ |
| 372 | static lua_Number luaV_div (lua_State *L, lua_Number m, lua_Number n) { |
| 373 | if ((lua_Unsigned)(n) + 1u <= 1u) { /* special cases: -1 or 0 */ |
| 374 | if (n == 0) |
| 375 | luaG_runerror(L, "attempt to divide by zero"); |
| 376 | return (0 - m); /* n==-1; avoid overflow with 0x80000...//-1 */ |
| 377 | } |
| 378 | else { |
| 379 | lua_Number q = m / n; /* perform C division */ |
| 380 | if ((m ^ n) < 0 && m % n != 0) /* 'm/n' would be negative non-integer? */ |
| 381 | q -= 1; /* correct result for different rounding */ |
| 382 | return q; |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | |
| 387 | /* |
no test coverage detected