File: ref_c_bignum.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 (246 lines) | stat: -rw-r--r-- 5,937 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
<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="Bignum" super="Integer" type="class">
    <tt>Bignum</tt> objects hold integers outside the range of
  <tt>Fixnum</tt>. <tt>Bignum</tt> objects are created automatically when
  integer calculations would otherwise overflow a <tt>Fixnum</tt>. When a
  calculation involving <tt>Bignum</tt> objects returns a result that will 
  fit in a <tt>Fixnum</tt>, the result is automatically converted.
<p/>
  For the purposes of the bitwise operations and <tt>[]</tt>, a
  <tt>Bignum</tt> is treated as if it were an infinite-length bitstring
  with 2's complement representation.
<p/>
  While <tt>Fixnum</tt> values are immediate, <tt>Bignum</tt> objects are
  not---assignment and parameter passing work with references to
  objects, not the objects themselves.
<p/>
  <methods type="instance">
<p/>
        <method name="Arithmetic operations" ref="Arithmeticoperations">
      <callseq>
<p/>
      </callseq>
      <desc>
<p/>
      Performs various arithmetic operations on <obj>big</obj>.
<p/>
      <table>
<tr>
  <td><obj>big</obj></td>
  <td>+</td>
  <td><obj>aNumeric</obj></td>
  <td>Addition</td>
</tr>
<tr>
  <td><obj>big</obj></td>
  <td>--</td>
  <td><obj>aNumeric</obj></td>
  <td>Subtraction</td>
</tr>
<tr>
  <td><obj>big</obj></td>
  <td>*</td>
  <td><obj>aNumeric</obj></td>
  <td>Multiplication</td>
</tr>
<tr>
  <td><obj>big</obj></td>
  <td>/</td>
  <td><obj>aNumeric</obj></td>
  <td>Division</td>
</tr>
<tr>
  <td><obj>big</obj></td>
  <td>%</td>
  <td><obj>aNumeric</obj></td>
  <td>Modulo</td>
</tr>
<tr>
  <td><obj>big</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>Bignum</tt>.<nbsp/>
<p/>
      <table>
<tr>
<td colspan="3">~ <obj>big</obj></td>
  <td>Invert bits</td>
</tr>
<tr>
  <td><obj>big</obj></td>
  <td>|</td>
  <td><obj>aNumeric</obj></td>
  <td>Bitwise <smallfont>OR</smallfont></td>
</tr>
<tr>
  <td><obj>big</obj></td>
  <td>&amp;</td>
  <td><obj>aNumeric</obj></td>
  <td>Bitwise <smallfont>AND</smallfont></td>
</tr>
<tr>
  <td><obj>big</obj></td>
  <td>^</td>
  <td><obj>aNumeric</obj></td>
  <td>Bitwise <smallfont>EXCLUSIVE</smallfont> <smallfont>OR</smallfont></td>
</tr>
<tr>
  <td><obj>big</obj></td>
  <td>&lt;&lt;</td>
  <td><obj>aNumeric</obj></td>
  <td>Left-shift <em>aNumeric</em> bits</td>
</tr>
<tr>
  <td><obj>big</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>big</obj> &lt;=&gt; <obj>aNumeric</obj> <returns>-1, 0, +1</returns>
      </callseq>
      <desc>
<p/>
      Comparison---Returns -1, 0, or +1 depending on
      whether <obj>big</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>big</obj>[ <obj>n</obj> ] <returns>0, 1</returns>
      </callseq>
      <desc>
<p/>
      Bit Reference---Returns the <em>n</em>th bit in
      the (assumed) binary representation of <obj>big</obj>,
      where <obj>big</obj>[0] is the least significant bit.
<p/>
<codefragment>
<alltt><fullcode><![CDATA[        a = 9**15
        50.downto(0) do |n|
          print a[n]
        end
!-        print "\n"
]]></fullcode>
a<nbsp/>=<nbsp/>9**15
50.downto(0)<nbsp/>do<nbsp/>|n|
<nbsp/><nbsp/>print<nbsp/>a[n]
end
</alltt>
</codefragment>
<em>produces:</em>
<codefragment><alltt>
000101110110100000111000011110010100111100010111001
</alltt>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="size" ref="size">
      <callseq>
        <obj>big</obj>.size <returns><obj>anInteger</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns the number of bytes in the machine representation
      of <obj>big</obj>. 
<p/>
<codefragment>
<fullcode><![CDATA[        (256**10 - 1).size
        (256**20 - 1).size
        (256**40 - 1).size
]]></fullcode><rubycode>
<tr>
  <td><tt>(256**10<nbsp/>-<nbsp/>1).size</tt></td>
  <td>&#187;</td>
  <td><tt>12</tt></td>
</tr>
<tr>
  <td><tt>(256**20<nbsp/>-<nbsp/>1).size</tt></td>
  <td>&#187;</td>
  <td><tt>20</tt></td>
</tr>
<tr>
  <td><tt>(256**40<nbsp/>-<nbsp/>1).size</tt></td>
  <td>&#187;</td>
  <td><tt>40</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
      </desc>
    </method>
<p/>
        <method name="to_f" ref="to_f">
      <callseq>
        <obj>big</obj>.to_f <returns><obj>aFloat</obj></returns>
      </callseq>
      <desc>
<p/>
      Converts <obj>big</obj> to a <tt>Float</tt>.  If <obj>big</obj> doesn't fit in a
      <tt>Float</tt>, the result is infinity.
<p/>
      </desc>
    </method>
<p/>
        <method name="to_i" ref="to_i">
      <callseq>
        <obj>big</obj>.to_i <returns><obj><obj>big</obj></obj></returns>
      </callseq>
      <desc>
<p/>
      Returns <obj>big</obj>.
<p/>
      </desc>
    </method>
<p/>
        <method name="to_s" ref="to_s">
      <callseq>
        <obj>big</obj>.to_s <returns><obj>aString</obj></returns>
      </callseq>
      <desc>
<p/>
      Returns a string containing the decimal representation of <obj>big</obj>.
<p/>
      </desc>
    </method>
<p/>
  </methods>
<p/>
</class>
</ppdoc>