Definition:Modulo Operation

Let $$x, y \in \R$$ be real numbers.

Then the operation $$\mod$$ is defined as:
 * $$x \mod y \ \stackrel {\mathbf {def}} {=\!=} \ \begin{cases}

x - y \left \lfloor {\frac x y}\right \rfloor & : y \ne 0 \\ x & : y = 0 \end{cases}$$

From the definition of the floor function, we see that, when $$y \ne 0$$:


 * $$0 \le \frac x y - \left \lfloor {\frac x y}\right \rfloor = \frac {x \mod y} y < 1$$.

Hence:
 * $$y > 0 \implies 0 \le x \mod y < y$$;
 * $$y < 0 \implies 0 \ge x \mod y > y$$;
 * $$x - \left({x \mod y}\right)$$ is an integral multiple of $$y$$.

The operation is most usually defined when $$x$$ and $$y$$ are both integers.

From the Quotient Theorem it follows that the quantity $$x \mod y$$ is called the remainder when $$x$$ is divided by $$y$$. This still holds when $$x$$ and $$y$$ are not actually integers.

The value $$\left \lfloor {\frac x y}\right \rfloor$$ is called the quotient.