** Integer modulus; return 'm % n'. (Assume that C '%' with ** negative operands follows C99 behavior. See previous comment ** about luaV_div.) */
| 390 | ** about luaV_div.) |
| 391 | */ |
| 392 | static lua_Number luaV_mod (lua_State *L, lua_Number m, lua_Number n) { |
| 393 | if ((lua_Unsigned)(n) + 1u <= 1u) { /* special cases: -1 or 0 */ |
| 394 | if (n == 0) |
| 395 | luaG_runerror(L, "attempt to perform 'n%%0'"); |
| 396 | return 0; /* m % -1 == 0; avoid overflow with 0x80000...%-1 */ |
| 397 | } |
| 398 | else { |
| 399 | lua_Number r = m % n; |
| 400 | if (r != 0 && (m ^ n) < 0) /* 'm/n' would be non-integer negative? */ |
| 401 | r += n; /* correct result for different rounding */ |
| 402 | return r; |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | /* |
| 407 | * End patch from 5.3.2 |
no test coverage detected