Maths encyclopedia and lessons  
Search

Mathematics Encyclopedia and Lessons

 
     
 

Lessons

Popular
Subjects

algebra
arithmetic
calculus
equations
geometry
differential equations
trigonometry
number theory
probability theory
more
 

References

applied mathematics
mathematical games
mathematicians
more
 
 

Modulo operation

In computing, the modulo operation finds the remainder of division of one number by another.

When given two numbers, a and n, a modulo n is the remainder, r, on division of a by n. Although typically performed with a and n both being integers, many computing systems allow other types of numeric operands.

Remainder calculation for the modulo operation

There are various ways of defining a remainder, and computers and calculators have various ways of storing and representing numbers, so what exactly constitutes the result of a modulo operation depends on the programming language and/or the underlying hardware.

In nearly all computing systems, the quotient resulting from the division is constrained to the set of integers, and the remainder r is typically constrained to

0 ≤ |r| < |n|,

with a negative remainder only resulting when n < 0. a modulo 0 is undefined in the majority of systems, although some do define it to be a.

The remainder can be calculated by using equations, in terms of other functions. Differences may arise according to the scope of the variables, which in common implementations is broader than in the definition just given.

Modulo operation expression

Some calculators have a mod() function button, and many programming languages have a mod() function or similar, expressed as mod(a,n), for example. Some also support expressions that use "%", "mod", or "Mod" as a modulo operator, such as

a % n

or

a mod n

both of which are pronounced "a modulo n" when spoken aloud.

Related articles

01-04-2007 01:18:14
The contents of this article are licensed from Wikipedia.org
under the GNU Free Documentation License. How to see transparent copy