This implementation follows Knuth's definition, mod(a, n) = a - n * floor(a / n),
which reflects the mathematical definition of modular arithmetic better than
JavasScript's % operator. (The primary difference is in handling negative numbers.)
For an implementation of the JavaScript % operator, see modulo.
This implementation follows Knuth's definition,
mod(a, n) = a - n * floor(a / n)
, which reflects the mathematical definition of modular arithmetic better than JavasScript's%
operator. (The primary difference is in handling negative numbers.) For an implementation of the JavaScript%
operator, see modulo.Example