MCPcopy Create free account
hub / github.com/F-Stack/f-stack / luaV_div

Function luaV_div

freebsd/contrib/openzfs/module/lua/lvm.c:372–384  ·  view source on GitHub ↗

** 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'. */

Source from the content-addressed store, hash-verified

370** otherwise 'floor(q) == trunc(q) - 1'.
371*/
372static 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/*

Callers 1

luaV_arithFunction · 0.85

Calls 1

luaG_runerrorFunction · 0.70

Tested by

no test coverage detected