forked from processing/processing-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodulo.xml
More file actions
executable file
·74 lines (52 loc) · 1.83 KB
/
modulo.xml
File metadata and controls
executable file
·74 lines (52 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<name>% (modulo)</name>
<category>Math</category>
<subcategory>Operators</subcategory>
<usage>Web & Application</usage>
<example>
<image></image>
<code><![CDATA[
int a = 5 % 4; // Sets 'a' to 1
int b = 125 % 100; // Sets 'b' to 25
float c = 285.5 % 140.0; // Sets 'c' to 5.5
float d = 30.0 % 33.0; // Sets 'd' to 30.0
]]></code>
</example>
<example>
<image></image>
<code><![CDATA[
int a = 0;
void draw() {
background(200);
a = (a + 1) % width; // 'a' increases between 0 and width
line(a, 0, a, height);
}
]]></code>
</example>
<description><![CDATA[
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/>
<br/>
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/>
<br/>
Modulo is extremely useful for ensuring values stay within a boundary, such as when keeping a shape on the screen. (See the second example above.)
]]></description>
<syntax>
<c>value1</c> % <c>value2</c>
</syntax>
<parameter>
<label>value1</label>
<description><![CDATA[int or float]]></description>
</parameter>
<parameter>
<label>value2</label>
<description><![CDATA[int or float]]></description>
</parameter>
<returns>int or float</returns>
<related>
/ (divide)
</related>
<availability>1.0</availability>
<type>Operator</type>
<partof>PDE</partof>
</root>