MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / luaV_div

Function luaV_div

libraries/AP_Scripting/lua/src/lvm.c:556–568  ·  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

554** otherwise 'floor(q) == trunc(q) - 1'.
555*/
556lua_Integer luaV_div (lua_State *L, lua_Integer m, lua_Integer n) {
557 if (l_castS2U(n) + 1u <= 1u) { /* special cases: -1 or 0 */
558 if (n == 0)
559 luaG_runerror(L, "attempt to divide by zero");
560 return intop(-, 0, m); /* n==-1; avoid overflow with 0x80000...//-1 */
561 }
562 else {
563 lua_Integer q = m / n; /* perform C division */
564 if ((m ^ n) < 0 && m % n != 0) /* 'm/n' would be negative non-integer? */
565 q -= 1; /* correct result for different rounding */
566 return q;
567 }
568}
569
570
571/*

Callers 2

luaV_executeFunction · 0.85
intarithFunction · 0.85

Calls 1

luaG_runerrorFunction · 0.85

Tested by

no test coverage detected