File: ref_c_fixnum.xml

package info (click to toggle)
rubybook 0.2.1-1
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k, lenny, squeeze, wheezy
  • size: 4,248 kB
  • ctags: 1,042
  • sloc: xml: 60,486; makefile: 25
file content (253 lines) | stat: -rw-r--r-- 6,497 bytes parent folder | download | duplicates (3)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<ppdoc>
<copyright>
    Copyright (c) 2001 by Addison Wesley Longman.  This
    material may be distributed only subject to the terms and
    conditions set forth in the Open Publication License, v1.0 or
    later (the latest version is presently available at
    http://www.opencontent.org/openpub/).
</copyright>
<class name="Fixnum" super="Integer" type="class">
    A <classname>Fixnum</classname> holds <tt>Integer</tt> values that can be represented in a
  native machine word (minus 1 bit). If any operation on a
  <tt>Fixnum</tt> exceeds this range, the value is automatically converted
  to a <tt>Bignum</tt>.
<p/>
  <tt>Fixnum</tt> objects have immediate value.  
  This means that when they
  are assigned or passed as parameters, the actual object is passed,
  rather than a reference to that object. Assignment does not alias
  <tt>Fixnum</tt> objects. There is effectively only one <tt>Fixnum</tt>
  object instance for any given integer value, so, for example, you
  cannot add a singleton method to a <classname>Fixnum</classname>.
<p/>
  <methods type="instance">
        <method name="Arithmetic operations" ref="Arithmeticoperations">
      <callseq>
<p/>
      </callseq>
      <desc>
<p/>
      Performs various arithmetic operations on <obj>fix</obj>.                                    
<p/>
      <table>
<tr>
  <td><obj>fix</obj></td>
  <td>+</td>
  <td><obj>aNumeric</obj></td>
  <td>Addition</td>
</tr>
<tr>
  <td><obj>fix</obj></td>
  <td>--</td>
  <td><obj>aNumeric</obj></td>
  <td>Subtraction</td>
</tr>
<tr>
  <td><obj>fix</obj></td>
  <td>*</td>
  <td><obj>aNumeric</obj></td>
  <td>Multiplication</td>
</tr>
<tr>
  <td><obj>fix</obj></td>
  <td>/</td>
  <td><obj>aNumeric</obj></td>
  <td>Division</td>
</tr>
<tr>
  <td><obj>fix</obj></td>
  <td>%</td>
  <td><obj>aNumeric</obj></td>
  <td>Modulo</td>
</tr>
<tr>
  <td><obj>fix</obj></td>
  <td>**</td>
  <td><obj>aNumeric</obj></td>
  <td>Exponentiation</td>
</tr>
</table>
<p/>
      </desc>
    </method>
<p/>
        <method name="Bit operations" ref="Bitoperations">
      <callseq>
<p/>
      </callseq>
      <desc>
<p/>
      Performs various operations on the binary representations of the
      <tt>Fixnum</tt>.                                    
<p/>
      <table>
<tr>
<td colspan="3">~ <obj>fix</obj></td>
  <td>Invert bits</td>
</tr>
<tr>
  <td><obj>fix</obj></td>
  <td>|</td>
  <td><obj>aNumeric</obj></td>
  <td>Bitwise <smallfont>OR</smallfont></td>
</tr>
<tr>
  <td><obj>fix</obj></td>
  <td>&amp;</td>
  <td><obj>aNumeric</obj></td>
  <td>Bitwise <smallfont>AND</smallfont></td>
</tr>
<tr>
  <td><obj>fix</obj></td>
  <td>^</td>
  <td><obj>aNumeric</obj></td>
  <td>Bitwise <smallfont>EXCLUSIVE</smallfont> <smallfont>OR</smallfont></td>
</tr>
<tr>
  <td><obj>fix</obj></td>
  <td>&lt;&lt;</td>
  <td><obj>aNumeric</obj></td>
  <td>Left-shift <em>aNumeric</em> bits</td>
</tr>
<tr>
  <td><obj>fix</obj></td>
  <td>&gt;&gt;</td>
  <td><obj>aNumeric</obj></td>
  <td>Right-shift <em>aNumeric</em>
      bits (with sign extension)</td>
</tr>
</table>
<p/>
      </desc>
    </method>
<p/>
        <method name="&lt;=&gt;" ref="_lt_eq_lt">
      <callseq>
        <obj>fix</obj> &lt;=&gt; <obj>aNumeric</obj>
        <returns>-1, 0, +1</returns>
      </callseq>
      <desc>
<p/>
      Comparison---Returns -1, 0, or +1 depending on whether <obj>fix</obj> is less
      than, equal to, or greater than <obj>aNumeric</obj>. This is the
      basis for the tests in <tt>Comparable</tt>.
<p/>
      </desc>
    </method>
<p/>
        <method name="[ ]" ref="_ob_cb">
      <callseq>
        <obj>fix</obj>[ <obj>n</obj> ] <returns>0, 1</returns>
      </callseq>
      <desc>
<p/>
      Bit Reference---Returns the <em>n</em>th bit in the binary
      representation of <obj>fix</obj>, where <obj>fix</obj>[0] is the least significant
      bit.
<p/>
<codefragment>
<alltt><fullcode><![CDATA[        a = 0b11001100101010
        30.downto(0) do |n| print a[n] end
!-        print "\n"
]]></fullcode>
a<nbsp/>=<nbsp/>0b11001100101010
30.downto(0)<nbsp/>do<nbsp/>|n|<nbsp/>print<nbsp/>a[n]<nbsp/>end
</alltt>
</codefragment>
<em>produces:</em>
<codefragment><alltt>
0000000000000000011001100101010
</alltt>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="id2name" ref="id2name">
      <callseq>
        <obj>fix</obj>.id2name <returns><obj>aString</obj> or <tt>nil</tt></returns>
      </callseq>
      <desc>
                    Returns the name of the object whose symbol
      id is the value of <obj>fix</obj>.  If there is no symbol in the symbol
      table with this value, returns <tt>nil</tt>.
      <meth>id2name</meth> has nothing to do with the <tt>Object.id</tt>
      method. See also <cim><file>string</file><front>String</front><back>intern</back><mref>intern</mref></cim>
      on page 376 and class <classname>Symbol</classname> on page 388.
<p/>
<codefragment>
<fullcode><![CDATA[         symbol = :@inst_var
         id     = symbol.to_i
         id.id2name
]]></fullcode><rubycode>
<tr>
  <td><tt>symbol<nbsp/>=<nbsp/>:@inst_var</tt></td>
  <td>&#187;</td>
  <td><tt>:@inst_var</tt></td>
</tr>
<tr>
  <td><tt>id<nbsp/><nbsp/><nbsp/><nbsp/><nbsp/>=<nbsp/>symbol.to_i</tt></td>
  <td>&#187;</td>
  <td><tt>8978</tt></td>
</tr>
<tr>
  <td><tt>id.id2name</tt></td>
  <td>&#187;</td>
  <td><tt>"@inst_var"</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="size" ref="size">
      <callseq>
        <obj>fix</obj>.size <returns><obj>aFixnum</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns the number of <em>bytes</em> in the machine representation
      of a <tt>Fixnum</tt>.
<p/>
      </desc>
    </method>
<p/>
        <method name="to_f" ref="to_f">
      <callseq>
        <obj>fix</obj>.to_f <returns><obj>aFloat</obj></returns>
      </callseq>
      <desc>
<p/>
      Converts <obj>fix</obj> to a <tt>Float</tt>.
<p/>
      </desc>
    </method>
<p/>
        <method name="to_i" ref="to_i">
      <callseq>
        <obj>fix</obj>.to_i <returns><obj>fix</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns <obj>fix</obj>.
<p/>
      </desc>
    </method>
<p/>
        <method name="to_s" ref="to_s">
      <callseq>
        <obj>fix</obj>.to_s <returns><obj>aString</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns a string containing the decimal representation of self.
<p/>
      </desc>
    </method>
<p/>
  </methods>
<p/>
</class>
</ppdoc>