supernova: fix boost.thread move semantics
[supercollider.git] / Help / Math / Integer.html
blob04891a5cbaaa33b7285d2dec92f1562a556e17df
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <title></title>
7 <meta name="Generator" content="Cocoa HTML Writer">
8 <meta name="CocoaVersion" content="949.43">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
15 p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica; min-height: 17.0px}
16 p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; min-height: 16.0px}
17 p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #ad140d}
18 span.s1 {font: 18.0px Helvetica}
19 span.s2 {color: #0024f8}
20 span.s3 {color: #0038eb}
21 span.s4 {color: #606060}
22 span.s5 {color: #000000}
23 span.Apple-tab-span {white-space:pre}
24 </style>
25 </head>
26 <body>
27 <p class="p1"><span class="s1"><b>Integer<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></b></span><b>integer number</b></p>
28 <p class="p2"><br></p>
29 <p class="p1"><b>superclass: </b><a href="SimpleNumber.html"><span class="s2">SimpleNumber</span></a></p>
30 <p class="p2"><br></p>
31 <p class="p1">A 32 bit integer. Integer inherits most of its behaviour from its superclass.</p>
32 <p class="p2"><br></p>
33 <p class="p2"><br></p>
34 <p class="p3"><b>Iteration</b></p>
35 <p class="p2"><br></p>
36 <p class="p1"><b>do(function)</b></p>
37 <p class="p2"><br></p>
38 <p class="p1">Executes function for all integers from zero to <b>this</b> minus one.</p>
39 <p class="p1"><b>function</b> - a Function which is passed two arguments, both of which are the same</p>
40 <p class="p1">integer from zero to this minus one. The reason two arguments are passed is for</p>
41 <p class="p1">symmetry with the implementations of do in Collection.</p>
42 <p class="p2"><br></p>
43 <p class="p1"><b>reverseDo(function)</b></p>
44 <p class="p1">Executes function for all integers from<span class="Apple-converted-space">  </span><b>this</b> minus one to zero.</p>
45 <p class="p2"><br></p>
46 <p class="p1"><b>for(endval, function)</b></p>
47 <p class="p2"><br></p>
48 <p class="p1">Executes function for all integers from <b>this</b> to <b>endval</b>, inclusive.</p>
49 <p class="p1"><b>endval</b> - an Integer.</p>
50 <p class="p1"><b>function</b> - a Function which is passed two arguments, the first which is an integer from this to</p>
51 <p class="p1">endval, and the second which is a number from zero to the number of iterations minus one.</p>
52 <p class="p2"><br></p>
53 <p class="p1"><b>forBy(endval, step, function)</b></p>
54 <p class="p2"><br></p>
55 <p class="p1">Executes function for all integers from <b>this</b> to<b> endval,</b> inclusive, stepping each time by <b>step</b>.</p>
56 <p class="p1"><b>endval</b> - an Integer.</p>
57 <p class="p1"><b>step</b> - an Integer.</p>
58 <p class="p1"><b>function</b> - a Function which is passed two arguments, the first which is an integer from this to</p>
59 <p class="p1">endval, and the second which is a number from zero to the number of iterations minus one.</p>
60 <p class="p2"><br></p>
61 <p class="p1"><b>collect(function)</b></p>
62 <p class="p2"><br></p>
63 <p class="p1">Return an Array of <b>this</b> size filled by objects generated from evaluating the <b>function</b>.</p>
64 <p class="p2"><br></p>
65 <p class="p1"><b>collectAs(function, class)</b></p>
66 <p class="p2"><br></p>
67 <p class="p1">Return a Collection of <b>class</b> of <b>this</b> size filled by objects generated from evaluating the <b>function</b>.</p>
68 <p class="p2"><br></p>
69 <p class="p1"><b>to(hi, step)</b></p>
70 <p class="p1">return an <a href="../Collections/Interval.html"><span class="s2">Interval</span></a> from this to hi.</p>
71 <p class="p2"><br></p>
72 <p class="p1"><b>geom(start, grow)</b></p>
73 <p class="p1">return an array with a geometric series of <b>this</b> size from <b>start</b>.<span class="Apple-converted-space"> </span></p>
74 <p class="p2"><br></p>
75 <p class="p1"><b>fib(a, b)</b></p>
76 <p class="p1">return an array with a fibonacci series of <b>this</b> size beginning with <b>a</b> and <b>b</b>.</p>
77 <p class="p2"><br></p>
78 <p class="p1"><b>factors</b></p>
79 <p class="p1">return the prime factors as array.</p>
80 <p class="p2"><br></p>
81 <p class="p1"><b>factorial</b></p>
82 <p class="p1">return the factorial of this.</p>
83 <p class="p2"><br></p>
84 <p class="p2"><br></p>
85 <p class="p2"><br></p>
86 <p class="p2"><br></p>
87 <p class="p3"><b>Random Numbers</b></p>
88 <p class="p1">see also: <a href="../Other Topics/Randomness.html"><span class="s2">Randomness</span></a></p>
89 <p class="p2"><br></p>
90 <p class="p1"><b>xrand(exclude)</b></p>
91 <p class="p2"><br></p>
92 <p class="p1">Answer a random value from zero to <b>this</b>, excluding the value <b>exclude</b>.</p>
93 <p class="p1"><b>exclude</b> - an Integer.</p>
94 <p class="p2"><br></p>
95 <p class="p1"><b>xrand2(exclude)</b></p>
96 <p class="p2"><br></p>
97 <p class="p1">Answer a random value from <b>this</b>.neg to <b>this,</b> excluding the value <b>exclude.</b></p>
98 <p class="p1"><b>exclude</b> - an Integer.</p>
99 <p class="p2"><br></p>
100 <p class="p2"><br></p>
101 <p class="p2"><br></p>
102 <p class="p3"><b>Conversion</b></p>
103 <p class="p2"><br></p>
104 <p class="p1"><b>asAscii</b></p>
105 <p class="p2"><br></p>
106 <p class="p1">Answer a Char which has the ASCII value of the receiver.</p>
107 <p class="p2"><br></p>
108 <p class="p1"><b>asDigit</b></p>
109 <p class="p2"><br></p>
110 <p class="p1">Answer a Char which represents the receiver as an ASCII digit. For example<span class="Apple-converted-space"> </span></p>
111 <p class="p1">5.asDigit returns $5.</p>
112 <p class="p2"><br></p>
113 <p class="p1"><b>asBinaryDigits(numDigits)</b></p>
114 <p class="p2"><br></p>
115 <p class="p1">Answer an array with the <b>binary digits</b> (integer 0 or 1). <b>numDigits</b> defaults to 8.</p>
116 <p class="p2"><br></p>
117 <p class="p1"><b>asDigits(base, numDigits)</b></p>
118 <p class="p2"><br></p>
119 <p class="p1">Answer an array with the <b>n-ary digits</b>, <b>base</b> defaults to 10.</p>
120 <p class="p1">See also the complementary method <a href="../Collections/SequenceableCollection.html"><span class="s3">SequenceableCollection</span></a> <b>convertDigits</b>.</p>
121 <p class="p2"><br></p>
122 <p class="p4">2007.asDigits;</p>
123 <p class="p4">2007.asDigits(2);</p>
124 <p class="p5"><br></p>
125 <p class="p2"><br></p>
126 <p class="p1"><b>asBinaryString(numDigits)</b></p>
127 <p class="p2"><br></p>
128 <p class="p1">Answer a string with the <b>binary digits</b> (0 or 1). <b>numDigits</b> defaults to 8.</p>
129 <p class="p2"><br></p>
130 <p class="p1"><b>asHexString(numDigits)</b></p>
131 <p class="p2"><br></p>
132 <p class="p1">Answer a string with the <b>hexadecimal digits</b> (integer 0 to F). <b>numDigits</b> defaults to 8.</p>
133 <p class="p5"><br></p>
134 <p class="p1"><b>asIPString</b></p>
135 <p class="p2"><br></p>
136 <p class="p1">Answer a string in IP format.</p>
137 <p class="p5"><br></p>
138 <p class="p2"><br></p>
139 <p class="p1"><b>degreeToKey(scale, stepsPerOctave)</b></p>
140 <p class="p1">Interpret <b>this</b> as index into a <b>scale</b> with a given number of steps per ocatve.</p>
141 <p class="p2"><br></p>
142 <p class="p4">2.degreeToKey([0, 2, 5, 7, 11]);</p>
143 <p class="p5"><br></p>
144 <p class="p1"><b>grayCode</b></p>
145 <p class="p1">Return the gray code for the number.</p>
146 <p class="p5"><br></p>
147 <p class="p4">2.grayCode</p>
148 <p class="p2"><br></p>
149 <p class="p2"><br></p>
150 <p class="p3"><b>Binary Representation</b></p>
151 <p class="p2"><br></p>
152 <p class="p1"><b>setBit(bitNumber, bool)</b></p>
153 <p class="p1">set nth bit to zero (bool = false) or one (bool = true)</p>
154 <p class="p2"><br></p>
155 <p class="p1"><b>leadingZeroes</b> { _CLZ }</p>
156 <p class="p2"><br></p>
157 <p class="p1"><b>trailingZeroes</b> { _CTZ }</p>
158 <p class="p2"><br></p>
159 <p class="p1"><b>numBits</b></p>
160 <p class="p1">return number of required bits</p>
161 <p class="p2"><br></p>
162 <p class="p2"><br></p>
163 <p class="p2"><br></p>
164 <p class="p3"><b>Properties</b></p>
165 <p class="p6"><br></p>
166 <p class="p1"><b>even</b></p>
167 <p class="p1">Answers true if dividable by 2 with no rest</p>
168 <p class="p2"><br></p>
169 <p class="p1"><b>odd</b></p>
170 <p class="p1">Answers true if not dividable by 2 with no rest</p>
171 <p class="p2"><br></p>
172 <p class="p2"><br></p>
173 <p class="p3"><b>Powers Of Two</b></p>
174 <p class="p2"><br></p>
175 <p class="p1"><b>nextPowerOfTwo</b></p>
176 <p class="p2"><br></p>
177 <p class="p1">Answer the next power of two greater than or equal to the receiver.</p>
178 <p class="p2"><br></p>
179 <p class="p4">13.nextPowerOfTwo.postln;</p>
180 <p class="p4">64.nextPowerOfTwo.postln;</p>
181 <p class="p2"><br></p>
182 <p class="p1"><b>isPowerOfTwo</b></p>
183 <p class="p2"><br></p>
184 <p class="p1">Answer the whether the receiver is a power of two.</p>
185 <p class="p2"><br></p>
186 <p class="p4">13.isPowerOfTwo.postln;</p>
187 <p class="p4">64.isPowerOfTwo.postln;</p>
188 <p class="p2"><br></p>
189 <p class="p3"><b>Prime Numbers</b></p>
190 <p class="p2"><br></p>
191 <p class="p1"><b>nthPrime</b></p>
192 <p class="p2"><br></p>
193 <p class="p1">Answer the nth prime number. The receiver must be from 0 to 6541.</p>
194 <p class="p2"><br></p>
195 <p class="p4">[0,1,2,3,4,5].collect({ arg i; i.nthPrime; }).postln;</p>
196 <p class="p2"><br></p>
197 <p class="p1"><b>prevPrime</b></p>
198 <p class="p2"><br></p>
199 <p class="p1">Answer the next prime less than or equal to the receiver up to 65521.</p>
200 <p class="p2"><br></p>
201 <p class="p4">25.prevPrime.postln;</p>
202 <p class="p2"><br></p>
203 <p class="p1"><b>nextPrime</b></p>
204 <p class="p2"><br></p>
205 <p class="p1">Answer the next prime less than or equal to the receiver up to 65521.</p>
206 <p class="p2"><br></p>
207 <p class="p4">25.nextPrime.postln;</p>
208 <p class="p2"><br></p>
209 <p class="p1"><b>isPrime</b></p>
210 <p class="p2"><br></p>
211 <p class="p1">Answer whether the receiver is prime.</p>
212 <p class="p2"><br></p>
213 <p class="p4">25.isPrime.postln;</p>
214 <p class="p4">13.isPrime.postln;</p>
215 <p class="p7"><br></p>
216 <p class="p1"><b>indexOfPrime</b></p>
217 <p class="p2"><br></p>
218 <p class="p1">Answer the index of a prime number less than or equal to the receiver up to 65521.</p>
219 <p class="p1">If the receiver is not a prime, the answer is nil.</p>
220 <p class="p2"><br></p>
221 <p class="p4">23.indexOfPrime;</p>
222 <p class="p4">25.indexOfPrime;</p>
223 <p class="p7"><br></p>
224 <p class="p2"><br></p>
225 <p class="p3"><b>Misc</b></p>
226 <p class="p2"><br></p>
227 <p class="p1"><b>pidRunning</b></p>
228 <p class="p2"><br></p>
229 <p class="p1">Returns a Boolean for whether or not the specified pid is running.</p>
230 <p class="p2"><br></p>
231 <p class="p4">p = <span class="s4">"cat"</span>.unixCmd;</p>
232 <p class="p8"><span class="s5">p.pidRunning; </span>// cat will stay alive</p>
233 <p class="p4">(<span class="s4">"kill"</span> + p).unixCmd</p>
234 <p class="p4">p.pidRunning;</p>
235 <p class="p2"><br></p>
236 <p class="p1"><b>getKeys</b></p>
237 <p class="p2"><br></p>
238 <p class="p1">Returns the bits from the Macintosh GetKeys() Toolbox call. Receiver should be 0 to 3.</p>
239 <p class="p2"><br></p>
240 <p class="p4">[0.getKeys, 1.getKeys, 2.getKeys, 3.getKeys].postln;</p>
241 </body>
242 </html>