forked from cwgem/Ruby-Documentation-Translation-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBignum.yaml
221 lines (204 loc) · 7.73 KB
/
Bignum.yaml
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
---
:name: Bignum
:comment: |-
Bignum objects hold integers outside the range of
Fixnum. Bignum objects are created
automatically when integer calculations would otherwise overflow a
Fixnum. When a calculation involving
Bignum objects returns a result that will fit in a
Fixnum, the result is automatically converted.
For the purposes of the bitwise operations and <code>[]</code>, a
Bignum is treated as if it were an infinite-length
bitstring with 2's complement representation.
While Fixnum values are immediate, Bignum
objects are not---assignment and parameter passing work with
references to objects, not the objects themselves.
:instance_methods:
- :name: to_s
:arglist: big.to_s(base=10) -> string
:comment: |-
Returns a string containing the representation of <i>big</i> radix
<i>base</i> (2 through 36).
12345654321.to_s #=> "12345654321"
12345654321.to_s(2) #=> "1011011111110110111011110000110001"
12345654321.to_s(8) #=> "133766736061"
12345654321.to_s(16) #=> "2dfdbbc31"
78546939656932.to_s(36) #=> "rubyrules"
- :name: coerce
:arglist: coerce(p1)
:comment: "MISSING: documentation"
- :name: -@
:arglist: -big -> integer
:comment: Unary minus (returns an integer whose value is 0-big)
- :name: +
:arglist: big + other -> Numeric
:comment: Adds big and other, returning the result.
- :name: "-"
:arglist: big - other -> Numeric
:comment: Subtracts other from big, returning the result.
- :name: "*"
:arglist: big * other -> Numeric
:comment: Multiplies big and other, returning the result.
- :name: /
:arglist: big / other -> Numeric
:comment: |-
Performs division: the class of the resulting object depends on
the class of <code>numeric</code> and on the magnitude of the
result.
- :name: "%"
:arglist: |-
big % other -> Numeric
big.modulo(other) -> Numeric
:comment: |-
Returns big modulo other. See Numeric.divmod for more
information.
- :name: div
:arglist: big.div(other) -> integer
:comment: "Performs integer division: returns integer value."
- :name: divmod
:arglist: big.divmod(numeric) -> array
:comment: See <code>Numeric#divmod</code>.
- :name: modulo
:arglist: |-
big % other -> Numeric
big.modulo(other) -> Numeric
:comment: |-
Returns big modulo other. See Numeric.divmod for more
information.
- :name: remainder
:arglist: big.remainder(numeric) -> number
:comment: |-
Returns the remainder after dividing <i>big</i> by <i>numeric</i>.
-1234567890987654321.remainder(13731) #=> -6966
-1234567890987654321.remainder(13731.24) #=> -9906.22531493148
- :name: fdiv
:arglist: big.fdiv(numeric) -> float
:comment: |-
Returns the floating point result of dividing <i>big</i> by
<i>numeric</i>.
-1234567890987654321.fdiv(13731) #=> -89910996357705.5
-1234567890987654321.fdiv(13731.24) #=> -89909424858035.7
- :name: "**"
:arglist: big ** exponent -> numeric
:comment: |-
Raises _big_ to the _exponent_ power (which may be an integer, float,
or anything that will coerce to a number). The result may be
a Fixnum, Bignum, or Float
123456789 ** 2 #=> 15241578750190521
123456789 ** 1.2 #=> 5126464716.09932
123456789 ** -2 #=> 6.5610001194102e-17
- :name: "&"
:arglist: big & numeric -> integer
:comment: Performs bitwise +and+ between _big_ and _numeric_.
- :name: "|"
:arglist: big | numeric -> integer
:comment: Performs bitwise +or+ between _big_ and _numeric_.
- :name: ^
:arglist: big ^ numeric -> integer
:comment: Performs bitwise +exclusive or+ between _big_ and _numeric_.
- :name: "~"
:arglist: ~big -> integer
:comment: |-
Inverts the bits in big. As Bignums are conceptually infinite
length, the result acts as if it had an infinite number of one
bits to the left. In hex representations, this is displayed
as two periods to the left of the digits.
sprintf("%X", ~0x1122334455) #=> "..FEEDDCCBBAA"
- :name: "<<"
:arglist: big << numeric -> integer
:comment: Shifts big left _numeric_ positions (right if _numeric_ is negative).
- :name: ">>"
:arglist: big >> numeric -> integer
:comment: Shifts big right _numeric_ positions (left if _numeric_ is negative).
- :name: "[]"
:arglist: big[n] -> 0, 1
:comment: |-
Bit Reference---Returns the <em>n</em>th bit in the (assumed) binary
representation of <i>big</i>, where <i>big</i>[0] is the least
significant bit.
a = 9**15
50.downto(0) do |n|
print a[n]
end
<em>produces:</em>
000101110110100000111000011110010100111100010111001
- :name: <=>
:arglist: big <=> numeric -> -1, 0, +1 or nil
:comment: |-
Comparison---Returns -1, 0, or +1 depending on whether <i>big</i> is
less than, equal to, or greater than <i>numeric</i>. This is the
basis for the tests in <code>Comparable</code>.
- :name: ==
:arglist: big == obj -> true or false
:comment: |-
Returns <code>true</code> only if <i>obj</i> has the same value
as <i>big</i>. Contrast this with <code>Bignum#eql?</code>, which
requires <i>obj</i> to be a <code>Bignum</code>.
68719476736 == 68719476736.0 #=> true
- :name: ">"
:arglist: big > real -> true or false
:comment: |-
Returns <code>true</code> if the value of <code>big</code> is
greater than that of <code>real</code>.
- :name: ">="
:arglist: big >= real -> true or false
:comment: |-
Returns <code>true</code> if the value of <code>big</code> is
greater than or equal to that of <code>real</code>.
- :name: <
:arglist: big < real -> true or false
:comment: |-
Returns <code>true</code> if the value of <code>big</code> is
less than that of <code>real</code>.
- :name: <=
:arglist: big <= real -> true or false
:comment: |-
Returns <code>true</code> if the value of <code>big</code> is
less than or equal to that of <code>real</code>.
- :name: ===
:arglist: big == obj -> true or false
:comment: |-
Returns <code>true</code> only if <i>obj</i> has the same value
as <i>big</i>. Contrast this with <code>Bignum#eql?</code>, which
requires <i>obj</i> to be a <code>Bignum</code>.
68719476736 == 68719476736.0 #=> true
- :name: eql?
:arglist: big.eql?(obj) -> true or false
:comment: |-
Returns <code>true</code> only if <i>obj</i> is a
<code>Bignum</code> with the same value as <i>big</i>. Contrast this
with <code>Bignum#==</code>, which performs type conversions.
68719476736.eql?(68719476736.0) #=> false
- :name: hash
:arglist: big.hash -> fixnum
:comment: Compute a hash based on the value of _big_.
- :name: to_f
:arglist: big.to_f -> float
:comment: |-
Converts <i>big</i> to a <code>Float</code>. If <i>big</i> doesn't
fit in a <code>Float</code>, the result is infinity.
- :name: abs
:arglist: big.abs -> aBignum
:comment: |-
Returns the absolute value of <i>big</i>.
-1234567890987654321.abs #=> 1234567890987654321
- :name: magnitude
:arglist: big.abs -> aBignum
:comment: |-
Returns the absolute value of <i>big</i>.
-1234567890987654321.abs #=> 1234567890987654321
- :name: size
:arglist: big.size -> integer
:comment: |-
Returns the number of bytes in the machine representation of
<i>big</i>.
(256**10 - 1).size #=> 12
(256**20 - 1).size #=> 20
(256**40 - 1).size #=> 40
- :name: odd?
:arglist: big.odd? -> true or false
:comment: Returns <code>true</code> if <i>big</i> is an odd number.
- :name: even?
:arglist: big.even? -> true or false
:comment: Returns <code>true</code> if <i>big</i> is an even number.
:class_methods: []