Integer remainder for negative numbers
Hello, I'm looking for a way in C to get the remainder of a negative number such that the remainder is positive, i.e. using truncation toward negative infinity rather than truncation toward zero.
Example; using the modulus operator, -10%3 returns -1 as it is equivalent to the following:
-10 - 3*int(-10/3) = -10 -3(-3) = -1
I want an expression that returns 2:
-10 - 3*floor(-10/3) = -10 - 3(-4) = 2
I'd like to avoid using a floating point function (floor()); integer math only.
Thanks, Stan