remainder - luxembourg/muxcode-clm GitHub Wiki
REMAINDER()
FUNCTION: remainder(<integer1>,<integer2>)
Returns the integer remainder from dividing <integer1> by <integer2>.
However, integer division for the case where either <integer1> or <integer2> is negative is defined in a specific way -- by choosing the smallest integer that is greater than or equal to the algebraic quotient. If <integer1> and <integer2> are the same sign, then mod() and remainder() are equivalent.
For example, division of -9 by 5 would give -1 by this definition instead of -2. idiv() would return -1. floordiv() would return -2, and so, the remainder() function properly goes with the idiv() function:
idiv(x,y)*y + remainder(x,y) ==> x
For positive x, remainder(x,y) always returns a positive number less than y. For negative x, remainder(x,y) always returns a negative number greater than y.
remainder() is usually the way the '%' operator in the C programming language is defined.
Example: > say remainder(-9,5) You say, "-4" > say remainder(-9,-5) You say, "-4" > say remainder(17,3) You say, "2" > say remainder(18,3) You say, "0"
Related Topics: iadd, idiv, imul, isub, floordiv, fmod, mod().