In a C program i was trying the below operations(Just to check the behavior )
x = 5 % (-3); y = (-5) % (3); z = (-5) % (-3); printf(\"%d ,%d ,%d\", x, y
It seems the problem is that / is not floor operation.
/
int mod(int m, float n) { return m - floor(m/n)*n; }