-
-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathfloat.xml
More file actions
executable file
·77 lines (61 loc) · 2.47 KB
/
float.xml
File metadata and controls
executable file
·77 lines (61 loc) · 2.47 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
75
76
77
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<name>float</name>
<category>Data</category>
<subcategory>Primitive</subcategory>
<usage>Web & Application</usage>
<example>
<image></image>
<code><![CDATA[
float a; // Declare variable 'a' of type float
a = 1.5387; // Assign 'a' the value 1.5387
float b = -2.984; // Declare variable 'b' and assign it the value -2.984
float c = a + b; // Declare variable 'c' and assign it the sum of 'a' and 'b'
]]></code>
</example>
<example>
<image></image>
<code><![CDATA[
float f1 = 0.0;
for (int i = 0 ; i < 100000; i++) {
f1 = f1 + 0.0001; // Bad idea! See below.
}
println(f1);
float f2 = 0.0;
for (int i = 0; i < 100000; i++) {
// The variable 'f2' will work better here, less affected by rounding
f2 = i / 1000.0; // Count by thousandths
}
println(f2);
]]></code>
</example>
<description><![CDATA[
Data type for floating-point numbers, e.g. numbers that have a decimal point.<br />
<br />
Floats are not precise, so adding small values (such as 0.0001) may not always increment precisely due to rounding errors. If you want to increment a value in small intervals, use an <b>int</b>, and divide by a <b>float</b> value before using it. (See the second example above.)<br />
<br />
Floating-point numbers can be as large as 3.40282347E+38 and as low as -3.40282347E+38. They are stored as 32 bits (4 bytes) of information. The <b>float</b> data type is inherited from Java; you can read more about the technical details <a href="https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html">here</a> and <a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-4.html#jls-4.2.3">here</a>.<br />
<br />
Processing supports the <b>double</b> datatype from Java as well. However, none of the Processing functions use <b>double</b> values, which use more memory and are typically overkill for most work created in Processing. We do not plan to add support for <b>double</b> values, as doing so would require increasing the number of API functions significantly.
]]></description>
<syntax>
float <c>var</c>
float <c>var</c> = <c>value</c>
</syntax>
<parameter>
<label>var</label>
<description><![CDATA[variable name referencing the float]]></description>
</parameter>
<parameter>
<label>value</label>
<description><![CDATA[any floating-point value]]></description>
</parameter>
<returns></returns>
<related>
int
double
</related>
<availability>1.0</availability>
<type>Datatype</type>
<partof>PDE</partof>
</root>