The modulus operation computes the remainder corresponding to the truncating division //. The following relation always holds:
X =:= (X rem Y) + (X // Y) * Y.
The result Result is either zero, or has the same sign as Number1. The
absolute value of Result does not depend on the signs of the arguments.
This predicate can be used as a function in arithmetic expressions. In coroutining mode, if Number1 or Number2 are uninstantiated, the call to rem/3 is delayed until these variables are instantiated.
See also the mod operation, whose result only differs when the arguments have opposite signs.
Success:
X is 10 rem 3. % gives X = 1
X is -10 rem 3. % gives X = -1
X is 10 rem -3. % gives X = 1
X is -10 rem -3. % gives X = -1
Error:
rem(2, 0, Result). % arithmetic exception