Drexel dragonThe Math ForumDonate to the Math Forum

Ask Dr. Math - Questions and Answers from our Archives
_____________________________________________
Associated Topics || Dr. Math Home || Search Dr. Math
_____________________________________________

What is Modulus?


Date: 06/06/2001 at 17:04:15
From: Bryan Sydnor
Subject: Modulus - Why use it, and how do you calculate it?

I am a Mechanical Engineer, and am learning to program on my own. I 
have used the mod command and know what the results mean, but I don't 
understand the theory behind it and what is actually happening. If you 
could point me to a book or Web site that would explain what the 
modulus actually is, its implications in math, and methods for solving 
it, it would be greatly appreciated.

Bryan


Date: 06/07/2001 at 08:53:25
From: Doctor Peterson
Subject: Re: Modulus - Why use it, and how do you calculate it?

Hi, Bryan.

The "mod" operator in computer languages is simply the remainder. For 
example,

    17 mod 3 = 2

because

    17 / 3 = 5 rem 2

which in turn means

    17 = 3 * 5 + 2

There are some tricky issues when negative numbers are used, but that 
shouldn't ordinarily be necessary.

In math (number theory), the term is used a little differently. The 
"modulus" is actually not the remainder, but the number you are 
dividing by; and "mod" is not an operator, but a label telling "in 
what sense two quantities are considered congruent, or equal." For 
example, we would say

    17 = 11 (mod 3)

(read as "17 is congruent to 11, modulo 3"), meaning that 17 and 11 
both leave the SAME remainder when divided by 3. You probably won't 
see this usage if you are only reading about programming, but it's 
worth being aware of if you look deeper into the math behind it.

Here are three references in our archives:

   Modulus Operator Problem
   http://mathforum.org/library/drmath/view/55771.html   

   Mod
   http://mathforum.org/library/drmath/view/55910.html   

   Mod Function and Negative Numbers
   http://mathforum.org/library/drmath/view/52343.html   

If this hasn't answered all your questions, please write back and tell 
me a little more about what you are doing with "mod" and what aspects 
you don't fully understand. I can probably give you more details if I 
see what you need to know.

- Doctor Peterson, The Math Forum
  http://mathforum.org/dr.math/   
    
Associated Topics:
High School Calculators, Computers
High School Number Theory

Search the Dr. Math Library:


Find items containing (put spaces between keywords):
 
Click only once for faster results:

[ Choose "whole words" when searching for a word like age.]

all keywords, in any order at least one, that exact phrase
parts of words whole words

Submit your own question to Dr. Math

[Privacy Policy] [Terms of Use]

_____________________________________
Math Forum Home || Math Library || Quick Reference || Math Forum Search
_____________________________________

Ask Dr. MathTM
© 1994-2013 The Math Forum
http://mathforum.org/dr.math/