Mod

From Free Pascal wiki
Revision as of 17:49, 1 February 2009 by Michalis (talk | contribs) (Fixed example for negative left side, citing the language reference)
Jump to navigationJump to search

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.