List:General Discussion« Previous MessageNext Message »
From:Thomas Lenherr Date:February 25 2005 4:07pm
Subject:Re: modulo operation
View as plain text  
Hi Jigal, Hi Peter,

first of all: it's true, the wikipedia-site is not contradicting the 
mysql-implementation, it seems i didn't read it too carefully...

The guy who "invented" the modulo-operation was G.F. Gauss in his book 
"Disquisitiones Arithmeticae" which was published in 1801.
His definition is documented here: (section congruence 

He defined the equivalence operation "modulo" as following:
"We call two integers a, b congruent modulo n if their difference is 
divisible by n, or equivalently: if they leave the same remainder when 
divided by n. "

This sentence seems to be the source of your different opinion:
The difference of a and b is always >= 0 therefore their difference mod 
n would always be a positive integer.
The second part defines the relation in slightly other way, using the 
remainder. As pointed out by the table pasted by Peter "remainder" and 
"modulo" is not always exactly the same, but if the remainder by any 
chance can be negative, the following line is not more always working 
for example in an if-statement:

a mod n == b mod n

because if exactly one of a and b is negative so are the remainders (if 
they're not multiples of n), ex:

-3 mod 2 != 1 mod 2, as -3 mod 2 == -1

but abs(-3 - 1) mod 2 == abs(-4) mod 2 == 4 mod 2 == 0

were we get a contradiction...


Jigal van Hemert wrote:
> From: "Peter Brawley"
>>There are various interpretations of modulo. It's not simply
>>"remainder", eg see the discussion at
>> including this chart
>>from the 1983 Ada manual:
> The article at wikipedia already mentioned multiple interpretations.
> My point was that while Thomas wrote that modulo in MySQL was flawed and
> pointed to the wikipedia page to prove his point, the wikipedia page in
> question was not contradicting the MySQL implementation at all.
>>>From: "Thomas Lenherr"
>>>>(For the exact definition see
>>>> )
> It is strange for mathematical operations/functions to depend upon
> "interpretation" or "implementation". If there is anything in this world
> that is properly defined, it must be mathematics.
> Maybe Thomas (or you) can file a bugreport with the suggestion to add a
> mathematically correct modulo function; I don't think the current modulo
> function/operator should be altered, since this might break a lot of queries
> out there!
> Regards, Jigal.
modulo operationThomas Lenherr25 Feb
  • Re: modulo operationJigal van Hemert25 Feb
    • Re: modulo operationPeter Brawley25 Feb
  • Re: modulo operationJigal van Hemert25 Feb
    • Re: modulo operationThomas Lenherr25 Feb