### 5.6.11 The integer Euclidean remainder : irem remain smod mods mod %

irem (or remain) returns the integer remainder r from
the Euclidean division of two integers a and b given as arguments
(a=b*q+r with 0≤ r< b).

For Gaussian integers, we choose q so that b*q is as near to a as
possible and it can be proved that r may be chosen so that
|r|^{2} ≤ |b|^{2}/2.

Input :

irem(148,5)

Output :

3

irem works with long integers or with Gaussian integers.

Example :

irem(factorial(148),factorial(45)+2 )

Output :

111615339728229933018338917803008301992120942047239639312

Another example

irem(25+12*i,5+7*i)

Output :

-4+i

Here a−b*q=−4+i and |−4+i|^{2}=17<|5+7*i|^{2}/2=74/2=37

smod or mods is a prefixed
function and has two integers a and b as arguments.

smod or mods returns the
symmetric remainder s of the Euclidean division of the
arguments a and b (a=b*q+s with −b/2<s ≤ b/2).

Input :

smod(148,5)

Output :

-2

mod (or %) is an infixed function
and has two integers a and b
as arguments.

mod (or %) returns r% b of Z/bZ where r is the remainder of
the Euclidean division of the arguments a and b.

Input :

148 mod 5

or :

148 % 5

Output :

3 % 5

Note that the answer 3 % 5 is not an integer (3) but
an element of Z/5Z (see 5.32 to have
the possible operations in Z/5Z).