What's the actual algebraic algorithm the modulo function uses? How does it work with one negative and one positive operand? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What's the actual algebraic algorithm the modulo function uses? How does it work with one negative and one positive operand?

Modulo

1st Nov 2018, 9:37 AM
ሚካኤል
2 Answers
+ 4
From the docs: "The modulo operator always yields a result with the same sign as its second operand (or zero); the absolute value of the result is strictly smaller than the absolute value of the second operand." See more at: https://docs.python.org/3/reference/expressions.html#binary-arithmetic-operations
1st Nov 2018, 9:50 AM
Kishalaya Saha
Kishalaya Saha - avatar
0
modulo finds the remaining amount. what i have found by playing around is -6%4 returns 2 whereas -6%-4 returns -2 the algorithm is just like long division except you stop before turning to decimal values and look at how much is remaining
1st Nov 2018, 9:51 AM
Adrian Ward
Adrian Ward - avatar