Mod

This is an old revision of Mod, edited by Michalis at . The current revision is 46965.

Fixed example for negative left side, citing the language reference

Mod (modulus) divides two numbers and returns only the remainder that is a whole number. For instance, the expression "a:= 13 mod 4;" would evaluate to 1 (a=1), while "b := 12 mod 4;" would evaluate to 0 (b=0).

From the language reference:

The sign of the result of a Mod operator is the same as the sign of the left side operand of the Mod operator. In fact, the Mod operator is equivalent to the following operation :

 I mod J = I - (I div J) * J 

For example "c := -13 mod 4;" results in c = -1.