- #1
swampwiz
- 571
- 83
I am confused about this. I have always thought that the modulo operator always has the result of a while number between 0 and the modulo divisor minus 1.
I presume that the terms are called:
a % b = c
a : dividend
b : divisor
c : remainder
a & b > 0 : a % b = b * [ ( a / b ) - INT( a / b ) ]
23 % 4 = 4 * [ ( 23 / 4 ) - INT( 23 / 4 ) ] = 4 * [ { 5 + ( 3 / 4 ) } - INT( { 5 + ( 3 / 4 ) } ) ]
= 4 * [ { 5 + ( 3 / 4 ) } - { 5 } ] = 4 * ( 3 / 4 ) = 3
I am not so sure about the arguments not being positive, but I would think that the divisor must be a positive integer, and a negative dividend is simply added to by some product of the divisor that results in a positive number, which then goes through the modulo operation.
a < 0
d : positive integer
a % b = ( a + d b ) % b
d > INT( | a | / b )
-23 % 4 :
d > INT( | -23 | / 4 ) = INT( 23 / 4 ) = 5 → let d = 6
-23 % 4 = [ -23 + ( 6 ) ( 4 ) ] % 4 = 1 % 4 = 1
And thus there is the relationship that
a % b = { b - [ ( - a ) % b ] } % b
such that if
( a / b ) = INT ( a / b ) → a % b = 0
( a / b ) ≠ INT ( a / b ) → a % b = b - [ ( - a ) % b ]
Finally, I was reading an excerpt from the book Love and Math by Edward Frenkel, in which there is the statement
So presuming that modulo has the same meaning as %, and my earlier definition is accurate, this would mean
2 + 2 = 1 % 3 = 1
I presume that the terms are called:
a % b = c
a : dividend
b : divisor
c : remainder
a & b > 0 : a % b = b * [ ( a / b ) - INT( a / b ) ]
23 % 4 = 4 * [ ( 23 / 4 ) - INT( 23 / 4 ) ] = 4 * [ { 5 + ( 3 / 4 ) } - INT( { 5 + ( 3 / 4 ) } ) ]
= 4 * [ { 5 + ( 3 / 4 ) } - { 5 } ] = 4 * ( 3 / 4 ) = 3
I am not so sure about the arguments not being positive, but I would think that the divisor must be a positive integer, and a negative dividend is simply added to by some product of the divisor that results in a positive number, which then goes through the modulo operation.
a < 0
d : positive integer
a % b = ( a + d b ) % b
d > INT( | a | / b )
-23 % 4 :
d > INT( | -23 | / 4 ) = INT( 23 / 4 ) = 5 → let d = 6
-23 % 4 = [ -23 + ( 6 ) ( 4 ) ] % 4 = 1 % 4 = 1
And thus there is the relationship that
a % b = { b - [ ( - a ) % b ] } % b
such that if
( a / b ) = INT ( a / b ) → a % b = 0
( a / b ) ≠ INT ( a / b ) → a % b = b - [ ( - a ) % b ]
Finally, I was reading an excerpt from the book Love and Math by Edward Frenkel, in which there is the statement
2 + 2 = 1 modulo 3
So presuming that modulo has the same meaning as %, and my earlier definition is accurate, this would mean
2 + 2 = 1 % 3 = 1