I was looking for some example on MOD and floor function from Concrete Mathematics book(1). But, the solution of each example is very confusing for me.
The general formula of x mod y is;
x mod y = x - y(lfloor (x / y) rfloor) [for y is not equal to 0]
Here, lfloor means left floor and rfloor means right floor
I know, how it works when value of x and y is positive. But, I get confused when value of x or y or both becomes negative.
Examples from the book(1):
5 mod -3 = 5 - (-3)(lfloor (5 / (-3)) rfloor) = -1
-5 mod 3 = -5 -3(lfloor (-5 / 3) rfloor) = 1
-5 mod -3 = -5 - (-3)(lfloor (-5 / (-3)) rfloor) = -2
Resource:
(1) Book - Concrete Mathematics See page 95