How much is 17 mod 3?
17 mod 3 equals 2 since dividing 17 by 3 gives a quotient of 5 and a remainder of 2. The remainder is the result of the modulus operation. In simpler terms, 17 mod 3 = 2.
What is a modulo operator?
The modulo operator is used to find the remainder during a division of two numbers. The operator is represented by the symbol % in most programming languages. It is also known as the remainder operator. As an example, 5 mod 2 returns 1.
How to calculate modulo division?
To calculate modulo division: subtract the divisor from the dividend until the resultant is less than the divisor.
I come from a computer science background and my mind is exploding rn from this.
In programming languages the % represents the modulo operation.
In most programming languages like C, Rust, Java, JavaScript -7 % 3 results in -1, this makes sense to me logically since if I have "negative 7 dollars" divided it across three people, each will get "-2 negative dollars" and "-1 negative dollar" will remain.
So how come in any calculators, and the few mathematics-friendly programming languages like Python and Haskell, -7 % 3 results in 2? Like logically speaking how could dividing a negative number result in a positive number, and where did the 2 even came from, from a logical standpoint?