I found this definition for modulo
mod(a, n) = a - n * floor(a / n)
Doing an integer division and then multiplying it again means finding the biggest number smaller than a that is dividable by n without a remainder. Subtracting this from a yields the remainder of the division and by that the modulo." source:https://torstencurdt.com/tech/posts/modulo-of-negative-numbers/
It seemed to help me understand intuitively, and it worked for cases where both a and n where positive and also cases where a was negative while b was positive. For example:
-10 mod 3
-12 is the largest number smaller than -10 divisible by 3. So the remainder is -10-(-12)=2 which is correct.
But when I tried doing 10 mod -3 my answer was incorrect. Because while 9 is the largest number smaller than 10 divisible by -3 it will give the wrong answer as it would evaluate to 10-9=1.
Instead it is supposed to be 10 -((-4)*(-3))=10-12=-2.
But 12 isn't the biggest number smaller than a.
I understand how to solve for the answer using the formula a= (a//n)(n)+(a%n) in python. But is there an intuitive definition to help me understand?