up previous next
mod    --    remainder for integers


Syntax
mod(N: INT, D: INT): INT

Description
This function computes the remainder of integer division of N by D; the remainder is zero or has the same sign asN. If R is the remainder then abs(R) < abs(M).

If we set Q = div(N,D) and R = mod(N,D) then N = Q*D + R.

NOTE: for polynomials use NR (remainder), DivAlg (quotients and remainder), IsIn (ideal membership).

Example
/**/  mod(10,3);
1
/**/  mod(-10,3);
-1
/**/  // How to test if two numbers are equivalent modulo M
/**/  A := 10; B := -5; M := 3;
/**/  mod(A-B,M) = 0;      // CORRECT!
true
/**/  mod(A,M) = mod(B,M); // WRONG!!  Do not do this!
false

See Also