The functions MOD and REMAINDER both return the remainder of a division of two numbers. The difference is that MOD uses the function FLOOR in its algorithm, and REMAINDER uses the function ROUND instead. This difference can affect the result. For example, the call to MOD (34.5, 3) returns 1.5. The call REMAINDER (34.5, 3) returns -1.5. For REMAINDER, n cannot equal zero.
The formulas for the two functions are:
MOD (m, n) = SIGN (m) * (ABS(m) - (ABS (n) * FLOOR(ABS (m) / ABS (n))))
REMAINDER (m,n) = m - (n*ROUND (m/n)
You can see the differences that can result by examining the following table:
If m= | And n= | MOD (m,n) returns | REMAINDER (m,n) returns |
---|---|---|---|
11 | 4 | 3 | -1 |
11 | -4 | 3 | -1 |
-11 | 4 | -3 | 1 |
-11 | -4 | -3 | 1 |