Difference between revisions of "Mod"
From Free Pascal wiki
Jump to navigationJump to search (New page: Mod ('''mod'''ulus) 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;...) |
(Fixed example for negative left side, citing the language reference) |
||
Line 2: | Line 2: | ||
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). | 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 [http://www.freepascal.org/docs-html/ref/refsu29.html 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. |
Revision as of 17:49, 1 February 2009
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.