[Tutor] The remainder %

Lloyd Kvam pythontutor@venix.com
Tue Jun 3 13:19:01 2003


PythonWin 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on win32.
Portions Copyright 1994-2001 Mark Hammond (mhammond@skippinet.com.au) - see 'Help/About PythonWin' for further copyright information.
 >>> -1 % 3
2

Bob Gailer wrote:
> At 02:09 PM 6/3/2003 +0200, Guillaume wrote:
> 
>> Hello,
>> I'm not very good in maths and I don't understand why
>> 14 % 3 = 2
>> Could someone explain me this mystery?
>> Thanks in advance :)
> 
> 
> What's really frustrating here is that the language reference says "% 
> (modulo) operator yields the remainder..."
> 
> In math modulo is NOT the same as remainder. At least the explanation 
> says "remainder". Modulo and remainder have the same values when the 
> left argument is >= 0, and different values for < 0. Example:
> n   n modulo 3  n % 3
> 3           0            0
> 2           2            2
> 1           1            1
> 0           0            0
> -1          2            1
> -2          1            2
> -3          0            0
> 
> The only programming language I know that "got is right" is APL. There 
> the function is named modulo and it DOES modulo. Most other languages 
> call it modulo and it does remainder.
> 
> Bob Gailer
> bgailer@alum.rpi.edu
> 303 442 2625
> 


-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice:	603-443-6155
fax:	801-459-9582