Why 9 mod -7 = -5? Quotient and remainder with negative integers. Forgive me if this question does not belong on this site for it is simplistic and this is my first post, however I do not seem to understand the modulo function when it comes to negative numbers.
I'd assume the process for calculating modulo would be the same as with positive numbers:


*

*9 % 7 = 2 because 9 - (7 * 9/7) = 9 - (7 * 1) = 2


So wouldn't 9 % (-7) = 9 - (-7 * -9/7) = 9 - (-7 * -1) = 2?

It's absolutely true that $9\equiv 2\bmod (-7)$. It's also true that $9\equiv -5\bmod (-7)$, and also $9\equiv 9\bmod (-7)$, $9\equiv 16\bmod (-7)$,  etc.
I suspect you're being confused by the output from a computer. The output that a computer makes when the symbols 9 % -7 are entered into it might reflect whatever conventions a programmer decided on (e.g., this StackOverflow post).
