mod - luxembourg/muxcode-clm GitHub Wiki

MOD() (continued)

For positive y, mod(x,y) always returns a positive number less than y. For negative y, mod(x,y) always returns a negative number greater than y.

mod() is the more 'mathy' definition of a modulus as defined by the following:

x mod y is defined as x - y*floor(x/y) where x,y, every operation is over real numbers.

Example: > say mod(-9,5) You say, "1" > say mod(-9,-5) You say, "-4" > say mod(17,3) You say, "2" > say mod(18,3) You say, "0"

Related Topics: floordiv, iadd, idiv, imul, isub, remainder().

-1. floordiv() would return -2, and so, the mod() function properly goes with the floordiv() function:

floordiv(x,y)*y + mod(x,y) ==> x

{ 'help mod2' for more }