+ 1

modulus

how does 7 mod 8 equal 7? my math is 7/8= .87 which rounds up to 1. Why would the answer not be 1? Is it because your left with 1 and that 1 -8=7?

11th Nov 2019, 2:03 AM
Making A Change
Making A Change - avatar
3 odpowiedzi
+ 4
Modulus isn't attempting to round up a decimal, it looks to return a natural number. 8 does not divide into 7 so you get a return of 7. If you were dividing 8 into 9, you would get a return of 1 using modulus
11th Nov 2019, 2:08 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 3
Modulo operator gives you remainder... So 7/8 gives quotient as 0 as it's integer division and remainder 7
11th Nov 2019, 2:37 AM
Saurabh B
Saurabh B - avatar
+ 1
thanks
11th Nov 2019, 2:36 AM
Making A Change
Making A Change - avatar