Definition:Modulo Operation
Jump to navigation
Jump to search
Definition
Let $x, y \in \R$ be real numbers.
Then the modulo operation is defined and denoted as:
- $x \bmod y := \begin{cases} x - y \floor {\dfrac x y} & : y \ne 0 \\ x & : y = 0 \end{cases}$
where $\floor {\, \cdot \,}$ denotes the floor function.
Modulo 0
We see that, from the definition:
- $\forall x \in \R: x \bmod 0 = x$
This can be considered as a special case of the modulo operation, but it is interesting to note that most of the results concerning the modulo operation still hold.
Modulo 1
Note also that from the definition:
- $x \bmod 1 = x - \floor x$
from which it follows directly that:
- $x = \floor x + \paren {x \bmod 1}$
Examples
Modulo Operation: $5 \bmod 3$
- $5 \bmod 3 = 2$
Modulo Operation: $18 \bmod 3$
- $18 \bmod 3 = 0$
Modulo Operation: $-2 \bmod 3$
- $-2 \bmod 3 = 1$
Modulo Operation: $100 \bmod 3$
- $100 \bmod 3 = 1$
Modulo Operation: $100 \bmod 7$
- $100 \bmod 7 = 2$
Modulo Operation: $-100 \bmod 7$
- $-100 \bmod 7 = 5$
Modulo Operation: $-100 \bmod 0$
- $-100 \bmod 0 = -100$
Modulo Operation: $5 \bmod -3$
- $5 \bmod -3 = -1$
Modulo Operation: $18 \bmod -3$
- $18 \bmod -3 = 0$
Modulo Operation: $-2 \bmod -3$
- $-2 \bmod -3 = -2$
Modulo Operation: $1 \cdotp 1 \bmod 1$
- $1 \cdotp 1 \bmod 1 = 0 \cdotp 1$
Modulo Operation: $0 \cdotp 11 \bmod 0 \cdotp 1$
- $0 \cdotp 11 \bmod 0 \cdotp 1 = 0 \cdotp 01$
Modulo Operation: $0 \cdotp 11 \bmod -0 \cdotp 1$
- $0 \cdotp 11 \bmod -0 \cdotp 1 = -0 \cdotp 09$
Modulo Operation: $x \bmod 3 = 2$ and $x \bmod 5 = 3$
Let $x \bmod 3 = 2$ and $x \bmod 5 = 3$.
Then:
- $x \bmod 15 = 8$
Also see
- Definition:Floor Function
- Definition:Fractional Part
- Definition:Quotient (Algebra)
- Definition:Remainder
- Definition:Congruence (Number Theory) which approaches the subject from a slightly different direction.
Sources
- 1997: Donald E. Knuth: The Art of Computer Programming: Volume 1: Fundamental Algorithms (3rd ed.) ... (previous) ... (next): $\S 1.2.4$: Integer Functions and Elementary Number Theory: $(1)$