Skip to content

Commit b55c512

Browse files
committed
Clarified modulo reference
1 parent cbf7fc8 commit b55c512

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

content/api_en/include/modulo.xml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,31 @@
1111
<example>
1212
<image></image>
1313
<code><![CDATA[
14-
int a = 20%100; // Sets 'a' to 20
15-
int b = 20%100; // Sets 'b' to 20
16-
float c = 75.0%100.0; // Sets 'c' to 75.0
17-
float d = 275.0%100.0; // Sets 'd' to 75.0
14+
int a = 5 % 4; // Sets 'a' to 1
15+
int b = 125 % 100; // Sets 'b' to 25
16+
float c = 285.5 % 140.0; // Sets 'c' to 5.5
17+
float d = 30.0 % 33.0; // Sets 'd' to 30.0
1818
]]></code>
1919
</example>
2020

2121
<example>
2222
<image></image>
2323
<code><![CDATA[
24-
float a = 0.0;
24+
int a = 0;
2525
void draw() {
26-
background(204);
27-
a = (a + 0.5) % width;
26+
background(200);
27+
a = (a + 1) % width; // 'a' increases between 0 and width
2828
line(a, 0, a, height);
2929
}
3030
]]></code>
3131
</example>
3232

3333
<description><![CDATA[
34-
Calculates the remainder when one number is divided by another. It is extremely useful for keeping numbers within a boundary such as keeping a shape on the screen.
34+
Calculates the remainder when one number is divided by another. For example, when 52.1 is divided by 10, the divisor (10) goes into the dividend (52.1) five times (5 * 10 == 50), and there is a remainder of 2.1 (52.1 - 50 == 2.1). Thus, <strong>52.1 % 10</strong> produces <strong>2.1</strong>.<br/>
35+
<br/>
36+
Note that when the divisor is greater than the dividend, the remainder constitutes the value of the entire dividend. That is, a number cannot be divided by any number larger than itself. For example, when 9 is divided by 10, the result is zero with a remainder of 9. Thus, <strong>9 % 10</strong> produces <strong>9</strong>.<br/>
37+
<br/>
38+
Modulo is extremely useful for keeping numbers within a boundary such as keeping a shape on the screen. (See the second example above.)
3539
]]></description>
3640

3741
<syntax>

0 commit comments

Comments
 (0)