rbs 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +5 -0
- data/CHANGELOG.md +23 -0
- data/README.md +6 -1
- data/core/array.rbs +2866 -1086
- data/core/basic_object.rbs +150 -30
- data/core/binding.rbs +33 -0
- data/core/builtin.rbs +4 -4
- data/core/class.rbs +43 -5
- data/core/comparable.rbs +57 -0
- data/core/complex.rbs +170 -4
- data/core/constants.rbs +51 -0
- data/core/deprecated.rbs +7 -0
- data/core/dir.rbs +305 -20
- data/core/encoding.rbs +472 -77
- data/core/enumerable.rbs +2173 -234
- data/core/enumerator.rbs +448 -182
- data/core/env.rbs +448 -1
- data/core/errno.rbs +1 -10
- data/core/errors.rbs +152 -2
- data/core/exception.rbs +201 -127
- data/core/false_class.rbs +27 -0
- data/core/fiber.rbs +118 -37
- data/core/fiber_error.rbs +8 -9
- data/core/file.rbs +1059 -139
- data/core/file_test.rbs +287 -32
- data/core/float.rbs +776 -300
- data/core/gc.rbs +185 -34
- data/core/global_variables.rbs +5 -1
- data/core/hash.rbs +1582 -649
- data/core/integer.rbs +974 -204
- data/core/io/buffer.rbs +710 -0
- data/core/io/wait.rbs +29 -8
- data/core/io.rbs +2438 -417
- data/core/kernel.rbs +2315 -316
- data/core/marshal.rbs +37 -2
- data/core/match_data.rbs +123 -6
- data/core/math.rbs +126 -6
- data/core/method.rbs +226 -102
- data/core/module.rbs +421 -45
- data/core/nil_class.rbs +64 -0
- data/core/numeric.rbs +620 -142
- data/core/object.rbs +453 -81
- data/core/object_space.rbs +92 -2
- data/core/proc.rbs +482 -285
- data/core/process.rbs +443 -34
- data/core/ractor.rbs +232 -9
- data/core/random.rbs +151 -52
- data/core/range.rbs +885 -160
- data/core/rational.rbs +122 -6
- data/core/rb_config.rbs +14 -4
- data/core/refinement.rbs +44 -0
- data/core/regexp.rbs +156 -14
- data/core/ruby_vm.rbs +42 -3
- data/core/signal.rbs +78 -39
- data/core/string.rbs +2123 -567
- data/core/string_io.rbs +204 -0
- data/core/struct.rbs +283 -28
- data/core/symbol.rbs +304 -30
- data/core/thread.rbs +1288 -688
- data/core/thread_group.rbs +66 -10
- data/core/time.rbs +643 -217
- data/core/trace_point.rbs +100 -12
- data/core/true_class.rbs +24 -0
- data/core/unbound_method.rbs +73 -7
- data/core/warning.rbs +37 -12
- data/docs/CONTRIBUTING.md +40 -34
- data/docs/stdlib.md +3 -102
- data/lib/rbs/annotate/annotations.rb +197 -0
- data/lib/rbs/annotate/formatter.rb +80 -0
- data/lib/rbs/annotate/rdoc_annotator.rb +398 -0
- data/lib/rbs/annotate/rdoc_source.rb +120 -0
- data/lib/rbs/annotate.rb +6 -0
- data/lib/rbs/cli.rb +45 -1
- data/lib/rbs/definition_builder.rb +5 -1
- data/lib/rbs/location_aux.rb +12 -0
- data/lib/rbs/prototype/rb.rb +12 -0
- data/lib/rbs/version.rb +1 -1
- data/sig/annotate/annotations.rbs +102 -0
- data/sig/annotate/formatter.rbs +24 -0
- data/sig/annotate/rdoc_annotater.rbs +82 -0
- data/sig/annotate/rdoc_source.rbs +30 -0
- data/sig/cli.rbs +2 -0
- data/sig/collection/{collections.rbs → sources.rbs} +0 -0
- data/sig/location.rbs +6 -0
- data/sig/method_types.rbs +5 -1
- data/sig/polyfill.rbs +78 -0
- data/stdlib/abbrev/0/abbrev.rbs +6 -0
- data/stdlib/abbrev/0/array.rbs +26 -0
- data/stdlib/base64/0/base64.rbs +31 -0
- data/stdlib/benchmark/0/benchmark.rbs +74 -3
- data/stdlib/bigdecimal/0/big_decimal.rbs +614 -165
- data/stdlib/bigdecimal-math/0/big_math.rbs +41 -64
- data/stdlib/cgi/0/core.rbs +59 -0
- data/stdlib/coverage/0/coverage.rbs +164 -2
- data/stdlib/csv/0/csv.rbs +2862 -398
- data/stdlib/date/0/date.rbs +483 -25
- data/stdlib/date/0/date_time.rbs +187 -12
- data/stdlib/dbm/0/dbm.rbs +152 -17
- data/stdlib/digest/0/digest.rbs +146 -0
- data/stdlib/erb/0/erb.rbs +65 -245
- data/stdlib/fiber/0/fiber.rbs +73 -91
- data/stdlib/fileutils/0/fileutils.rbs +301 -1
- data/stdlib/find/0/find.rbs +9 -0
- data/stdlib/forwardable/0/forwardable.rbs +65 -1
- data/stdlib/io-console/0/io-console.rbs +227 -15
- data/stdlib/ipaddr/0/ipaddr.rbs +161 -0
- data/stdlib/json/0/json.rbs +1146 -144
- data/stdlib/logger/0/formatter.rbs +24 -0
- data/stdlib/logger/0/log_device.rbs +64 -0
- data/stdlib/logger/0/logger.rbs +165 -13
- data/stdlib/logger/0/period.rbs +10 -0
- data/stdlib/logger/0/severity.rbs +26 -0
- data/stdlib/monitor/0/monitor.rbs +163 -0
- data/stdlib/mutex_m/0/mutex_m.rbs +35 -6
- data/stdlib/net-http/0/net-http.rbs +1492 -683
- data/stdlib/nkf/0/nkf.rbs +372 -0
- data/stdlib/objspace/0/objspace.rbs +149 -90
- data/stdlib/openssl/0/openssl.rbs +8108 -71
- data/stdlib/optparse/0/optparse.rbs +487 -19
- data/stdlib/pathname/0/pathname.rbs +425 -124
- data/stdlib/prettyprint/0/prettyprint.rbs +120 -99
- data/stdlib/prime/0/integer-extension.rbs +20 -2
- data/stdlib/prime/0/prime.rbs +88 -21
- data/stdlib/pstore/0/pstore.rbs +102 -0
- data/stdlib/pty/0/pty.rbs +64 -14
- data/stdlib/resolv/0/resolv.rbs +420 -31
- data/stdlib/rubygems/0/basic_specification.rbs +4 -1
- data/stdlib/rubygems/0/config_file.rbs +33 -1
- data/stdlib/rubygems/0/dependency_installer.rbs +4 -3
- data/stdlib/rubygems/0/installer.rbs +13 -1
- data/stdlib/rubygems/0/path_support.rbs +4 -1
- data/stdlib/rubygems/0/platform.rbs +5 -1
- data/stdlib/rubygems/0/request_set.rbs +44 -2
- data/stdlib/rubygems/0/requirement.rbs +65 -2
- data/stdlib/rubygems/0/rubygems.rbs +407 -0
- data/stdlib/rubygems/0/source_list.rbs +13 -0
- data/stdlib/rubygems/0/specification.rbs +21 -1
- data/stdlib/rubygems/0/stream_ui.rbs +3 -1
- data/stdlib/rubygems/0/uninstaller.rbs +8 -1
- data/stdlib/rubygems/0/version.rbs +60 -157
- data/stdlib/securerandom/0/securerandom.rbs +44 -0
- data/stdlib/set/0/set.rbs +420 -106
- data/stdlib/shellwords/0/shellwords.rbs +55 -77
- data/stdlib/singleton/0/singleton.rbs +20 -0
- data/stdlib/socket/0/addrinfo.rbs +210 -9
- data/stdlib/socket/0/basic_socket.rbs +103 -11
- data/stdlib/socket/0/ip_socket.rbs +31 -9
- data/stdlib/socket/0/socket.rbs +586 -38
- data/stdlib/socket/0/tcp_server.rbs +22 -2
- data/stdlib/socket/0/tcp_socket.rbs +12 -1
- data/stdlib/socket/0/udp_socket.rbs +25 -2
- data/stdlib/socket/0/unix_server.rbs +22 -2
- data/stdlib/socket/0/unix_socket.rbs +45 -5
- data/stdlib/strscan/0/string_scanner.rbs +210 -9
- data/stdlib/tempfile/0/tempfile.rbs +58 -10
- data/stdlib/time/0/time.rbs +208 -116
- data/stdlib/timeout/0/timeout.rbs +10 -0
- data/stdlib/tmpdir/0/tmpdir.rbs +13 -4
- data/stdlib/tsort/0/cyclic.rbs +1 -0
- data/stdlib/tsort/0/interfaces.rbs +1 -0
- data/stdlib/tsort/0/tsort.rbs +42 -0
- data/stdlib/uri/0/common.rbs +57 -8
- data/stdlib/uri/0/file.rbs +55 -109
- data/stdlib/uri/0/ftp.rbs +6 -3
- data/stdlib/uri/0/generic.rbs +556 -327
- data/stdlib/uri/0/http.rbs +26 -115
- data/stdlib/uri/0/https.rbs +8 -102
- data/stdlib/uri/0/ldap.rbs +143 -137
- data/stdlib/uri/0/ldaps.rbs +8 -102
- data/stdlib/uri/0/mailto.rbs +3 -0
- data/stdlib/uri/0/rfc2396_parser.rbs +66 -26
- data/stdlib/uri/0/ws.rbs +6 -3
- data/stdlib/uri/0/wss.rbs +5 -3
- data/stdlib/yaml/0/dbm.rbs +151 -87
- data/stdlib/yaml/0/store.rbs +6 -0
- data/stdlib/zlib/0/zlib.rbs +90 -31
- metadata +17 -5
- data/lib/rbs/location.rb +0 -221
data/core/integer.rbs
CHANGED
@@ -1,70 +1,332 @@
|
|
1
|
-
#
|
2
|
-
#
|
1
|
+
# <!-- rdoc-file=numeric.c -->
|
2
|
+
# An Integer object represents an integer value.
|
3
|
+
#
|
4
|
+
# You can create an Integer object explicitly with:
|
5
|
+
#
|
6
|
+
# * An [integer
|
7
|
+
# literal](doc/syntax/literals_rdoc.html#label-Integer+Literals).
|
8
|
+
#
|
9
|
+
#
|
10
|
+
# You can convert certain objects to Integers with:
|
11
|
+
#
|
12
|
+
# * Method [Integer](Kernel.html#method-i-Integer).
|
13
|
+
#
|
14
|
+
#
|
15
|
+
# An attempt to add a singleton method to an instance of this class causes an
|
16
|
+
# exception to be raised.
|
17
|
+
#
|
18
|
+
# ## What's Here
|
19
|
+
#
|
20
|
+
# First, what's elsewhere. Class Integer:
|
21
|
+
#
|
22
|
+
# * Inherits from [class
|
23
|
+
# Numeric](Numeric.html#class-Numeric-label-What-27s+Here).
|
24
|
+
#
|
25
|
+
#
|
26
|
+
# Here, class Integer provides methods for:
|
27
|
+
#
|
28
|
+
# * [Querying](#class-Integer-label-Querying)
|
29
|
+
# * [Comparing](#class-Integer-label-Comparing)
|
30
|
+
# * [Converting](#class-Integer-label-Converting)
|
31
|
+
# * [Other](#class-Integer-label-Other)
|
32
|
+
#
|
33
|
+
#
|
34
|
+
# ### Querying
|
35
|
+
#
|
36
|
+
# #allbits?
|
37
|
+
# : Returns whether all bits in `self` are set.
|
38
|
+
#
|
39
|
+
# #anybits?
|
40
|
+
# : Returns whether any bits in `self` are set.
|
41
|
+
#
|
42
|
+
# #nobits?
|
43
|
+
# : Returns whether no bits in `self` are set.
|
44
|
+
#
|
45
|
+
#
|
46
|
+
#
|
47
|
+
# ### Comparing
|
48
|
+
#
|
49
|
+
# [<](#method-i-3C)
|
50
|
+
# : Returns whether `self` is less than the given value.
|
51
|
+
#
|
52
|
+
# [<=](#method-i-3C-3D)
|
53
|
+
# : Returns whether `self` is less than or equal to the given value.
|
54
|
+
#
|
55
|
+
# [<=>](#method-i-3C-3D-3E)
|
56
|
+
# : Returns a number indicating whether `self` is less than, equal to, or
|
57
|
+
# greater than the given value.
|
58
|
+
#
|
59
|
+
# [==](#method-i-3D-3D) (aliased as #===)
|
60
|
+
# : Returns whether `self` is equal to the given value.
|
61
|
+
#
|
62
|
+
# [>](#method-i-3E)
|
63
|
+
# : Returns whether `self` is greater than the given value.
|
64
|
+
#
|
65
|
+
# [>=](#method-i-3E-3D)
|
66
|
+
# : Returns whether `self` is greater than or equal to the given value.
|
67
|
+
#
|
68
|
+
#
|
69
|
+
#
|
70
|
+
# ### Converting
|
71
|
+
#
|
72
|
+
# ::sqrt
|
73
|
+
# : Returns the integer square root of the given value.
|
74
|
+
#
|
75
|
+
# ::try_convert
|
76
|
+
# : Returns the given value converted to an Integer.
|
77
|
+
#
|
78
|
+
# #% (aliased as #modulo)
|
79
|
+
# : Returns `self` modulo the given value.
|
80
|
+
#
|
81
|
+
# [&](#method-i-26)
|
82
|
+
# : Returns the bitwise AND of `self` and the given value.
|
83
|
+
#
|
84
|
+
# #*
|
85
|
+
# : Returns the product of `self` and the given value.
|
86
|
+
#
|
87
|
+
# [**](#method-i-2A-2A)
|
88
|
+
# : Returns the value of `self` raised to the power of the given value.
|
89
|
+
#
|
90
|
+
# #+
|
91
|
+
# : Returns the sum of `self` and the given value.
|
92
|
+
#
|
93
|
+
# #-
|
94
|
+
# : Returns the difference of `self` and the given value.
|
95
|
+
#
|
96
|
+
# [/](#method-i-2F)
|
97
|
+
# : Returns the quotient of `self` and the given value.
|
98
|
+
#
|
99
|
+
# #<<
|
100
|
+
# : Returns the value of `self` after a leftward bit-shift.
|
101
|
+
#
|
102
|
+
# #>>
|
103
|
+
# : Returns the value of `self` after a rightward bit-shift.
|
104
|
+
#
|
105
|
+
# #[]
|
106
|
+
# : Returns a slice of bits from `self`.
|
107
|
+
#
|
108
|
+
# [^](#method-i-5E)
|
109
|
+
# : Returns the bitwise EXCLUSIVE OR of `self` and the given value.
|
110
|
+
#
|
111
|
+
# #ceil
|
112
|
+
# : Returns the smallest number greater than or equal to `self`.
|
113
|
+
#
|
114
|
+
# #chr
|
115
|
+
# : Returns a 1-character string containing the character represented by
|
116
|
+
# the value of `self`.
|
117
|
+
#
|
118
|
+
# #digits
|
119
|
+
# : Returns an array of integers representing the base-radix digits of
|
120
|
+
# `self`.
|
121
|
+
#
|
122
|
+
# #div
|
123
|
+
# : Returns the integer result of dividing `self` by the given value.
|
124
|
+
#
|
125
|
+
# #divmod
|
126
|
+
# : Returns a 2-element array containing the quotient and remainder
|
127
|
+
# results of dividing `self` by the given value.
|
128
|
+
#
|
129
|
+
# #fdiv
|
130
|
+
# : Returns the Float result of dividing `self` by the given value.
|
131
|
+
#
|
132
|
+
# #floor
|
133
|
+
# : Returns the greatest number smaller than or equal to `self`.
|
134
|
+
#
|
135
|
+
# #pow
|
136
|
+
# : Returns the modular exponentiation of `self`.
|
137
|
+
#
|
138
|
+
# #pred
|
139
|
+
# : Returns the integer predecessor of `self`.
|
140
|
+
#
|
141
|
+
# #remainder
|
142
|
+
# : Returns the remainder after dividing `self` by the given value.
|
143
|
+
#
|
144
|
+
# #round
|
145
|
+
# : Returns `self` rounded to the nearest value with the given precision.
|
146
|
+
#
|
147
|
+
# #succ (aliased as #next)
|
148
|
+
# : Returns the integer successor of `self`.
|
149
|
+
#
|
150
|
+
# #to_f
|
151
|
+
# : Returns `self` converted to a Float.
|
152
|
+
#
|
153
|
+
# #to_s (aliased as #inspect)
|
154
|
+
# : Returns a string containing the place-value representation of `self`
|
155
|
+
# in the given radix.
|
156
|
+
#
|
157
|
+
# #truncate
|
158
|
+
# : Returns `self` truncated to the given precision.
|
159
|
+
#
|
160
|
+
# [/](#method-i-7C)
|
161
|
+
# : Returns the bitwise OR of `self` and the given value.
|
162
|
+
#
|
163
|
+
#
|
164
|
+
#
|
165
|
+
# ### Other
|
166
|
+
#
|
167
|
+
# #downto
|
168
|
+
# : Calls the given block with each integer value from `self` down to the
|
169
|
+
# given value.
|
170
|
+
#
|
171
|
+
# #times
|
172
|
+
# : Calls the given block `self` times with each integer in `(0..self-1)`.
|
173
|
+
#
|
174
|
+
# #upto
|
175
|
+
# : Calls the given block with each integer value from `self` up to the
|
176
|
+
# given value.
|
3
177
|
#
|
4
178
|
class Integer < Numeric
|
5
|
-
#
|
6
|
-
#
|
179
|
+
# <!--
|
180
|
+
# rdoc-file=numeric.c
|
181
|
+
# - Integer.sqrt(numeric) -> integer
|
182
|
+
# -->
|
183
|
+
# Returns the integer square root of the non-negative integer `n`, which is the
|
184
|
+
# largest non-negative integer less than or equal to the square root of
|
185
|
+
# `numeric`.
|
7
186
|
#
|
8
|
-
# Integer.sqrt(0)
|
9
|
-
# Integer.sqrt(1)
|
10
|
-
# Integer.sqrt(24)
|
11
|
-
# Integer.sqrt(25)
|
12
|
-
# Integer.sqrt(10**400)
|
187
|
+
# Integer.sqrt(0) # => 0
|
188
|
+
# Integer.sqrt(1) # => 1
|
189
|
+
# Integer.sqrt(24) # => 4
|
190
|
+
# Integer.sqrt(25) # => 5
|
191
|
+
# Integer.sqrt(10**400) # => 10**200
|
13
192
|
#
|
14
|
-
#
|
15
|
-
# may differ from the true value due to the limited precision of floating point
|
16
|
-
# arithmetic.
|
193
|
+
# If `numeric` is not an Integer, it is converted to an Integer:
|
17
194
|
#
|
18
|
-
# Integer.sqrt(
|
19
|
-
#
|
195
|
+
# Integer.sqrt(Complex(4, 0)) # => 2
|
196
|
+
# Integer.sqrt(Rational(4, 1)) # => 2
|
197
|
+
# Integer.sqrt(4.0) # => 2
|
198
|
+
# Integer.sqrt(3.14159) # => 1
|
20
199
|
#
|
21
|
-
#
|
22
|
-
#
|
200
|
+
# This method is equivalent to `Math.sqrt(numeric).floor`, except that the
|
201
|
+
# result of the latter code may differ from the true value due to the limited
|
202
|
+
# precision of floating point arithmetic.
|
203
|
+
#
|
204
|
+
# Integer.sqrt(10**46) # => 100000000000000000000000
|
205
|
+
# Math.sqrt(10**46).floor # => 99999999999999991611392
|
206
|
+
#
|
207
|
+
# Raises an exception if `numeric` is negative.
|
23
208
|
#
|
24
209
|
def self.sqrt: (int n) -> Integer
|
25
210
|
|
211
|
+
# <!--
|
212
|
+
# rdoc-file=numeric.rb
|
213
|
+
# - Integer.try_convert(object) -> object, integer, or nil
|
214
|
+
# -->
|
215
|
+
# If `object` is an Integer object, returns `object`.
|
216
|
+
# Integer.try_convert(1) # => 1
|
217
|
+
#
|
218
|
+
# Otherwise if `object` responds to `:to_int`, calls `object.to_int` and returns
|
219
|
+
# the result.
|
220
|
+
# Integer.try_convert(1.25) # => 1
|
221
|
+
#
|
222
|
+
# Returns `nil` if `object` does not respond to `:to_int`
|
223
|
+
# Integer.try_convert([]) # => nil
|
224
|
+
#
|
225
|
+
# Raises an exception unless `object.to_int` returns an Integer object.
|
226
|
+
#
|
227
|
+
def self.try_convert: (int) -> Integer
|
228
|
+
| (untyped) -> Integer?
|
229
|
+
|
26
230
|
public
|
27
231
|
|
28
|
-
#
|
232
|
+
# <!--
|
233
|
+
# rdoc-file=numeric.c
|
234
|
+
# - self % other -> real_number
|
235
|
+
# -->
|
236
|
+
# Returns `self` modulo `other` as a real number.
|
237
|
+
#
|
238
|
+
# For integer `n` and real number `r`, these expressions are equivalent:
|
29
239
|
#
|
30
|
-
#
|
240
|
+
# n % r
|
241
|
+
# n-r*(n/r).floor
|
242
|
+
# n.divmod(r)[1]
|
243
|
+
#
|
244
|
+
# See Numeric#divmod.
|
245
|
+
#
|
246
|
+
# Examples:
|
247
|
+
#
|
248
|
+
# 10 % 2 # => 0
|
249
|
+
# 10 % 3 # => 1
|
250
|
+
# 10 % 4 # => 2
|
251
|
+
#
|
252
|
+
# 10 % -2 # => 0
|
253
|
+
# 10 % -3 # => -2
|
254
|
+
# 10 % -4 # => -2
|
255
|
+
#
|
256
|
+
# 10 % 3.0 # => 1.0
|
257
|
+
# 10 % Rational(3, 1) # => (1/1)
|
258
|
+
#
|
259
|
+
# Integer#modulo is an alias for Integer#%.
|
31
260
|
#
|
32
261
|
def %: (Float) -> Float
|
33
262
|
| (Rational) -> Rational
|
34
263
|
| (Integer) -> Integer
|
35
264
|
| (Numeric) -> Numeric
|
36
265
|
|
37
|
-
#
|
266
|
+
# <!--
|
267
|
+
# rdoc-file=numeric.c
|
268
|
+
# - self & other -> integer
|
269
|
+
# -->
|
270
|
+
# Bitwise AND; each bit in the result is 1 if both corresponding bits in `self`
|
271
|
+
# and `other` are 1, 0 otherwise:
|
272
|
+
#
|
273
|
+
# "%04b" % (0b0101 & 0b0110) # => "0100"
|
274
|
+
#
|
275
|
+
# Raises an exception if `other` is not an Integer.
|
276
|
+
#
|
277
|
+
# Related: Integer#| (bitwise OR), Integer#^ (bitwise EXCLUSIVE OR).
|
38
278
|
#
|
39
279
|
def &: (Integer) -> Integer
|
40
280
|
|
41
|
-
#
|
42
|
-
#
|
281
|
+
# <!--
|
282
|
+
# rdoc-file=numeric.c
|
283
|
+
# - self * numeric -> numeric_result
|
284
|
+
# -->
|
285
|
+
# Performs multiplication:
|
286
|
+
#
|
287
|
+
# 4 * 2 # => 8
|
288
|
+
# 4 * -2 # => -8
|
289
|
+
# -4 * 2 # => -8
|
290
|
+
# 4 * 2.0 # => 8.0
|
291
|
+
# 4 * Rational(1, 3) # => (4/3)
|
292
|
+
# 4 * Complex(2, 0) # => (8+0i)
|
43
293
|
#
|
44
294
|
def *: (Float) -> Float
|
45
295
|
| (Rational) -> Rational
|
46
296
|
| (Complex) -> Complex
|
47
297
|
| (Integer) -> Integer
|
48
298
|
|
49
|
-
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
-
# 2 ** 0.5 #=> 1.4142135623730951
|
55
|
-
# (-1) ** 0.5 #=> (0.0+1.0i)
|
299
|
+
# <!--
|
300
|
+
# rdoc-file=numeric.c
|
301
|
+
# - self ** numeric -> numeric_result
|
302
|
+
# -->
|
303
|
+
# Raises `self` to the power of `numeric`:
|
56
304
|
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
305
|
+
# 2 ** 3 # => 8
|
306
|
+
# 2 ** -3 # => (1/8)
|
307
|
+
# -2 ** 3 # => -8
|
308
|
+
# -2 ** -3 # => (-1/8)
|
309
|
+
# 2 ** 3.3 # => 9.849155306759329
|
310
|
+
# 2 ** Rational(3, 1) # => (8/1)
|
311
|
+
# 2 ** Complex(3, 0) # => (8+0i)
|
60
312
|
#
|
61
313
|
def **: (Integer) -> Numeric
|
62
314
|
| (Float) -> Numeric
|
63
315
|
| (Rational) -> Numeric
|
64
316
|
| (Complex) -> Complex
|
65
317
|
|
66
|
-
#
|
67
|
-
#
|
318
|
+
# <!--
|
319
|
+
# rdoc-file=numeric.c
|
320
|
+
# - self + numeric -> numeric_result
|
321
|
+
# -->
|
322
|
+
# Performs addition:
|
323
|
+
#
|
324
|
+
# 2 + 2 # => 4
|
325
|
+
# -2 + 2 # => 0
|
326
|
+
# -2 + -2 # => -4
|
327
|
+
# 2 + 2.0 # => 4.0
|
328
|
+
# 2 + Rational(2, 1) # => (4/1)
|
329
|
+
# 2 + Complex(2, 0) # => (4+0i)
|
68
330
|
#
|
69
331
|
def +: (Integer) -> Integer
|
70
332
|
| (Float) -> Float
|
@@ -73,116 +335,271 @@ class Integer < Numeric
|
|
73
335
|
|
74
336
|
def +@: () -> Integer
|
75
337
|
|
76
|
-
#
|
77
|
-
#
|
338
|
+
# <!--
|
339
|
+
# rdoc-file=numeric.c
|
340
|
+
# - self - numeric -> numeric_result
|
341
|
+
# -->
|
342
|
+
# Performs subtraction:
|
343
|
+
#
|
344
|
+
# 4 - 2 # => 2
|
345
|
+
# -4 - 2 # => -6
|
346
|
+
# -4 - -2 # => -2
|
347
|
+
# 4 - 2.0 # => 2.0
|
348
|
+
# 4 - Rational(2, 1) # => (2/1)
|
349
|
+
# 4 - Complex(2, 0) # => (2+0i)
|
78
350
|
#
|
79
351
|
def -: (Integer) -> Integer
|
80
352
|
| (Float) -> Float
|
81
353
|
| (Rational) -> Rational
|
82
354
|
| (Complex) -> Complex
|
83
355
|
|
356
|
+
# <!--
|
357
|
+
# rdoc-file=numeric.rb
|
358
|
+
# - -int -> integer
|
359
|
+
# -->
|
84
360
|
# Returns `int`, negated.
|
85
361
|
#
|
86
362
|
def -@: () -> Integer
|
87
363
|
|
88
|
-
#
|
89
|
-
#
|
364
|
+
# <!--
|
365
|
+
# rdoc-file=numeric.c
|
366
|
+
# - self / numeric -> numeric_result
|
367
|
+
# -->
|
368
|
+
# Performs division; for integer `numeric`, truncates the result to an integer:
|
369
|
+
#
|
370
|
+
# 4 / 3 # => 1
|
371
|
+
# 4 / -3 # => -2
|
372
|
+
# -4 / 3 # => -2
|
373
|
+
# -4 / -3 # => 1
|
374
|
+
#
|
375
|
+
# For other +numeric+, returns non-integer result:
|
376
|
+
#
|
377
|
+
# 4 / 3.0 # => 1.3333333333333333
|
378
|
+
# 4 / Rational(3, 1) # => (4/3)
|
379
|
+
# 4 / Complex(3, 0) # => ((4/3)+0i)
|
90
380
|
#
|
91
381
|
def /: (Integer) -> Integer
|
92
382
|
| (Float) -> Float
|
93
383
|
| (Rational) -> Rational
|
94
384
|
| (Complex) -> Complex
|
95
385
|
|
96
|
-
#
|
386
|
+
# <!--
|
387
|
+
# rdoc-file=numeric.c
|
388
|
+
# - self < other -> true or false
|
389
|
+
# -->
|
390
|
+
# Returns `true` if the value of `self` is less than that of `other`:
|
391
|
+
#
|
392
|
+
# 1 < 0 # => false
|
393
|
+
# 1 < 1 # => false
|
394
|
+
# 1 < 2 # => true
|
395
|
+
# 1 < 0.5 # => false
|
396
|
+
# 1 < Rational(1, 2) # => false
|
397
|
+
#
|
398
|
+
# Raises an exception if the comparison cannot be made.
|
97
399
|
#
|
98
400
|
def <: (Numeric) -> bool
|
99
401
|
|
100
|
-
#
|
402
|
+
# <!--
|
403
|
+
# rdoc-file=numeric.c
|
404
|
+
# - self << count -> integer
|
405
|
+
# -->
|
406
|
+
# Returns `self` with bits shifted `count` positions to the left, or to the
|
407
|
+
# right if `count` is negative:
|
408
|
+
#
|
409
|
+
# n = 0b11110000
|
410
|
+
# "%08b" % (n << 1) # => "111100000"
|
411
|
+
# "%08b" % (n << 3) # => "11110000000"
|
412
|
+
# "%08b" % (n << -1) # => "01111000"
|
413
|
+
# "%08b" % (n << -3) # => "00011110"
|
414
|
+
#
|
415
|
+
# Related: Integer#>>.
|
101
416
|
#
|
102
417
|
def <<: (int) -> Integer
|
103
418
|
|
104
|
-
#
|
419
|
+
# <!--
|
420
|
+
# rdoc-file=numeric.c
|
421
|
+
# - self <= real -> true or false
|
422
|
+
# -->
|
423
|
+
# Returns `true` if the value of `self` is less than or equal to that of
|
424
|
+
# `other`:
|
425
|
+
#
|
426
|
+
# 1 <= 0 # => false
|
427
|
+
# 1 <= 1 # => true
|
428
|
+
# 1 <= 2 # => true
|
429
|
+
# 1 <= 0.5 # => false
|
430
|
+
# 1 <= Rational(1, 2) # => false
|
431
|
+
#
|
432
|
+
# Raises an exception if the comparison cannot be made.
|
105
433
|
#
|
106
434
|
def <=: (Numeric) -> bool
|
107
435
|
|
108
|
-
#
|
109
|
-
#
|
436
|
+
# <!--
|
437
|
+
# rdoc-file=numeric.c
|
438
|
+
# - self <=> other -> -1, 0, +1, or nil
|
439
|
+
# -->
|
440
|
+
# Returns:
|
110
441
|
#
|
111
|
-
#
|
442
|
+
# * -1, if `self` is less than `other`.
|
443
|
+
# * 0, if `self` is equal to `other`.
|
444
|
+
# * 1, if `self` is greater then `other`.
|
445
|
+
# * `nil`, if `self` and `other` are incomparable.
|
112
446
|
#
|
113
|
-
#
|
447
|
+
#
|
448
|
+
# Examples:
|
449
|
+
#
|
450
|
+
# 1 <=> 2 # => -1
|
451
|
+
# 1 <=> 1 # => 0
|
452
|
+
# 1 <=> 0 # => 1
|
453
|
+
# 1 <=> 'foo' # => nil
|
454
|
+
#
|
455
|
+
# 1 <=> 1.0 # => 0
|
456
|
+
# 1 <=> Rational(1, 1) # => 0
|
457
|
+
# 1 <=> Complex(1, 0) # => 0
|
458
|
+
#
|
459
|
+
# This method is the basis for comparisons in module Comparable.
|
114
460
|
#
|
115
461
|
def <=>: (Integer | Rational) -> Integer
|
116
462
|
| (untyped) -> Integer?
|
117
463
|
|
118
|
-
#
|
119
|
-
#
|
464
|
+
# <!-- rdoc-file=numeric.c -->
|
465
|
+
# Returns `true` if `self` is numerically equal to `other`; `false` otherwise.
|
120
466
|
#
|
121
467
|
# 1 == 2 #=> false
|
122
468
|
# 1 == 1.0 #=> true
|
123
469
|
#
|
470
|
+
# Related: Integer#eql? (requires `other` to be an Integer).
|
471
|
+
#
|
472
|
+
# Integer#=== is an alias for Integer#==.
|
473
|
+
#
|
124
474
|
def ==: (untyped) -> bool
|
125
475
|
|
126
|
-
#
|
127
|
-
#
|
476
|
+
# <!--
|
477
|
+
# rdoc-file=numeric.c
|
478
|
+
# - self == other -> true or false
|
479
|
+
# -->
|
480
|
+
# Returns `true` if `self` is numerically equal to `other`; `false` otherwise.
|
128
481
|
#
|
129
482
|
# 1 == 2 #=> false
|
130
483
|
# 1 == 1.0 #=> true
|
131
484
|
#
|
485
|
+
# Related: Integer#eql? (requires `other` to be an Integer).
|
486
|
+
#
|
487
|
+
# Integer#=== is an alias for Integer#==.
|
488
|
+
#
|
132
489
|
def ===: (untyped) -> bool
|
133
490
|
|
134
|
-
#
|
491
|
+
# <!--
|
492
|
+
# rdoc-file=numeric.c
|
493
|
+
# - self > other -> true or false
|
494
|
+
# -->
|
495
|
+
# Returns `true` if the value of `self` is greater than that of `other`:
|
496
|
+
#
|
497
|
+
# 1 > 0 # => true
|
498
|
+
# 1 > 1 # => false
|
499
|
+
# 1 > 2 # => false
|
500
|
+
# 1 > 0.5 # => true
|
501
|
+
# 1 > Rational(1, 2) # => true
|
502
|
+
#
|
503
|
+
# Raises an exception if the comparison cannot be made.
|
135
504
|
#
|
136
505
|
def >: (Numeric) -> bool
|
137
506
|
|
138
|
-
#
|
139
|
-
#
|
507
|
+
# <!--
|
508
|
+
# rdoc-file=numeric.c
|
509
|
+
# - self >= real -> true or false
|
510
|
+
# -->
|
511
|
+
# Returns `true` if the value of `self` is greater than or equal to that of
|
512
|
+
# `other`:
|
513
|
+
#
|
514
|
+
# 1 >= 0 # => true
|
515
|
+
# 1 >= 1 # => true
|
516
|
+
# 1 >= 2 # => false
|
517
|
+
# 1 >= 0.5 # => true
|
518
|
+
# 1 >= Rational(1, 2) # => true
|
519
|
+
#
|
520
|
+
# Raises an exception if the comparison cannot be made.
|
140
521
|
#
|
141
522
|
def >=: (Numeric) -> bool
|
142
523
|
|
143
|
-
#
|
524
|
+
# <!--
|
525
|
+
# rdoc-file=numeric.c
|
526
|
+
# - self >> count -> integer
|
527
|
+
# -->
|
528
|
+
# Returns `self` with bits shifted `count` positions to the right, or to the
|
529
|
+
# left if `count` is negative:
|
530
|
+
#
|
531
|
+
# n = 0b11110000
|
532
|
+
# "%08b" % (n >> 1) # => "01111000"
|
533
|
+
# "%08b" % (n >> 3) # => "00011110"
|
534
|
+
# "%08b" % (n >> -1) # => "111100000"
|
535
|
+
# "%08b" % (n >> -3) # => "11110000000"
|
536
|
+
#
|
537
|
+
# Related: Integer#<<.
|
144
538
|
#
|
145
539
|
def >>: (int) -> Integer
|
146
540
|
|
147
|
-
#
|
148
|
-
#
|
541
|
+
# <!--
|
542
|
+
# rdoc-file=numeric.c
|
543
|
+
# - self[offset] -> 0 or 1
|
544
|
+
# - self[offset, size] -> integer
|
545
|
+
# - self[range] -> integer
|
546
|
+
# -->
|
547
|
+
# Returns a slice of bits from `self`.
|
149
548
|
#
|
150
|
-
#
|
151
|
-
#
|
152
|
-
# #=> 0000000000000000011001100101010
|
549
|
+
# With argument `offset`, returns the bit at the given offset, where offset 0
|
550
|
+
# refers to the least significant bit:
|
153
551
|
#
|
154
|
-
#
|
155
|
-
#
|
156
|
-
#
|
552
|
+
# n = 0b10 # => 2
|
553
|
+
# n[0] # => 0
|
554
|
+
# n[1] # => 1
|
555
|
+
# n[2] # => 0
|
556
|
+
# n[3] # => 0
|
157
557
|
#
|
158
|
-
# In principle, `n[i]` is equivalent to `(n >> i) & 1`. Thus,
|
558
|
+
# In principle, `n[i]` is equivalent to `(n >> i) & 1`. Thus, negative index
|
159
559
|
# always returns zero:
|
160
560
|
#
|
161
|
-
#
|
561
|
+
# 255[-1] # => 0
|
562
|
+
#
|
563
|
+
# With arguments `offset` and `size`, returns `size` bits from `self`, beginning
|
564
|
+
# at `offset` and including bits of greater significance:
|
162
565
|
#
|
163
|
-
#
|
566
|
+
# n = 0b111000 # => 56
|
567
|
+
# "%010b" % n[0, 10] # => "0000111000"
|
568
|
+
# "%010b" % n[4, 10] # => "0000000011"
|
164
569
|
#
|
165
|
-
#
|
166
|
-
#
|
167
|
-
# * `n[i...j]` equals to `(n >> i) & ((1 << (j - i)) - 1)`.
|
168
|
-
# * `n[i..]` equals to `(n >> i)`.
|
169
|
-
# * `n[..j]` is zero if `n & ((1 << (j + 1)) - 1)` is zero. Otherwise, raises
|
170
|
-
# an ArgumentError.
|
171
|
-
# * `n[...j]` is zero if `n & ((1 << j) - 1)` is zero. Otherwise, raises an
|
172
|
-
# ArgumentError.
|
570
|
+
# With argument `range`, returns `range.size` bits from `self`, beginning at
|
571
|
+
# `range.begin` and including bits of greater significance:
|
173
572
|
#
|
573
|
+
# n = 0b111000 # => 56
|
574
|
+
# "%010b" % n[0..9] # => "0000111000"
|
575
|
+
# "%010b" % n[4..9] # => "0000000011"
|
174
576
|
#
|
175
|
-
#
|
176
|
-
# 1000000000000]` will raise NoMemoryError.
|
577
|
+
# Raises an exception if the slice cannot be constructed.
|
177
578
|
#
|
178
579
|
def []: (int) -> Integer
|
179
580
|
| (int i, int len) -> Integer
|
180
581
|
| (Range[int]) -> Integer
|
181
582
|
|
182
|
-
#
|
583
|
+
# <!--
|
584
|
+
# rdoc-file=numeric.c
|
585
|
+
# - self ^ other -> integer
|
586
|
+
# -->
|
587
|
+
# Bitwise EXCLUSIVE OR; each bit in the result is 1 if the corresponding bits in
|
588
|
+
# `self` and `other` are different, 0 otherwise:
|
589
|
+
#
|
590
|
+
# "%04b" % (0b0101 ^ 0b0110) # => "0011"
|
591
|
+
#
|
592
|
+
# Raises an exception if `other` is not an Integer.
|
593
|
+
#
|
594
|
+
# Related: Integer#& (bitwise AND), Integer#| (bitwise OR).
|
183
595
|
#
|
184
596
|
def ^: (Integer) -> Integer
|
185
597
|
|
598
|
+
# <!--
|
599
|
+
# rdoc-file=numeric.rb
|
600
|
+
# - int.abs -> integer
|
601
|
+
# - int.magnitude -> integer
|
602
|
+
# -->
|
186
603
|
# Returns the absolute value of `int`.
|
187
604
|
#
|
188
605
|
# (-12345).abs #=> 12345
|
@@ -195,18 +612,60 @@ class Integer < Numeric
|
|
195
612
|
|
196
613
|
def abs2: () -> Integer
|
197
614
|
|
198
|
-
#
|
615
|
+
# <!--
|
616
|
+
# rdoc-file=numeric.c
|
617
|
+
# - allbits?(mask) -> true or false
|
618
|
+
# -->
|
619
|
+
# Returns `true` if all bits that are set (=1) in `mask` are also set in `self`;
|
620
|
+
# returns `false` otherwise.
|
621
|
+
#
|
622
|
+
# Example values:
|
623
|
+
#
|
624
|
+
# 0b1010101 self
|
625
|
+
# 0b1010100 mask
|
626
|
+
# 0b1010100 self & mask
|
627
|
+
# true self.allbits?(mask)
|
628
|
+
#
|
629
|
+
# 0b1010100 self
|
630
|
+
# 0b1010101 mask
|
631
|
+
# 0b1010100 self & mask
|
632
|
+
# false self.allbits?(mask)
|
633
|
+
#
|
634
|
+
# Related: Integer#anybits?, Integer#nobits?.
|
199
635
|
#
|
200
636
|
def allbits?: (int mask) -> bool
|
201
637
|
|
202
638
|
def angle: () -> (Integer | Float)
|
203
639
|
|
204
|
-
#
|
640
|
+
# <!--
|
641
|
+
# rdoc-file=numeric.c
|
642
|
+
# - anybits?(mask) -> true or false
|
643
|
+
# -->
|
644
|
+
# Returns `true` if any bit that is set (=1) in `mask` is also set in `self`;
|
645
|
+
# returns `false` otherwise.
|
646
|
+
#
|
647
|
+
# Example values:
|
648
|
+
#
|
649
|
+
# 0b10000010 self
|
650
|
+
# 0b11111111 mask
|
651
|
+
# 0b10000010 self & mask
|
652
|
+
# true self.anybits?(mask)
|
653
|
+
#
|
654
|
+
# 0b00000000 self
|
655
|
+
# 0b11111111 mask
|
656
|
+
# 0b00000000 self & mask
|
657
|
+
# false self.anybits?(mask)
|
658
|
+
#
|
659
|
+
# Related: Integer#allbits?, Integer#nobits?.
|
205
660
|
#
|
206
661
|
def anybits?: (int mask) -> bool
|
207
662
|
|
208
663
|
alias arg angle
|
209
664
|
|
665
|
+
# <!--
|
666
|
+
# rdoc-file=numeric.rb
|
667
|
+
# - int.bit_length -> integer
|
668
|
+
# -->
|
210
669
|
# Returns the number of bits of the value of `int`.
|
211
670
|
#
|
212
671
|
# "Number of bits" means the bit position of the highest bit which is different
|
@@ -247,31 +706,55 @@ class Integer < Numeric
|
|
247
706
|
#
|
248
707
|
def bit_length: () -> Integer
|
249
708
|
|
250
|
-
#
|
251
|
-
#
|
709
|
+
# <!--
|
710
|
+
# rdoc-file=numeric.c
|
711
|
+
# - ceil(ndigits = 0) -> integer
|
712
|
+
# -->
|
713
|
+
# Returns the smallest number greater than or equal to `self` with a precision
|
714
|
+
# of `ndigits` decimal digits.
|
252
715
|
#
|
253
716
|
# When the precision is negative, the returned value is an integer with at least
|
254
|
-
# `ndigits.abs` trailing zeros
|
717
|
+
# `ndigits.abs` trailing zeros:
|
718
|
+
#
|
719
|
+
# 555.ceil(-1) # => 560
|
720
|
+
# 555.ceil(-2) # => 600
|
721
|
+
# -555.ceil(-2) # => -500
|
722
|
+
# 555.ceil(-3) # => 1000
|
255
723
|
#
|
256
724
|
# Returns `self` when `ndigits` is zero or positive.
|
257
725
|
#
|
258
|
-
#
|
259
|
-
#
|
260
|
-
#
|
261
|
-
#
|
726
|
+
# 555.ceil # => 555
|
727
|
+
# 555.ceil(50) # => 555
|
728
|
+
#
|
729
|
+
# Related: Integer#floor.
|
262
730
|
#
|
263
731
|
def ceil: () -> Integer
|
264
732
|
| (int digits) -> (Integer | Float)
|
265
733
|
|
266
|
-
#
|
267
|
-
#
|
734
|
+
# <!--
|
735
|
+
# rdoc-file=numeric.c
|
736
|
+
# - chr -> string
|
737
|
+
# - chr(encoding) -> string
|
738
|
+
# -->
|
739
|
+
# Returns a 1-character string containing the character represented by the value
|
740
|
+
# of `self`, according to the given `encoding`.
|
741
|
+
#
|
742
|
+
# 65.chr # => "A"
|
743
|
+
# 0..chr # => "\x00"
|
744
|
+
# 255.chr # => "\xFF"
|
745
|
+
# string = 255.chr(Encoding::UTF_8)
|
746
|
+
# string.encoding # => Encoding::UTF_8
|
268
747
|
#
|
269
|
-
#
|
270
|
-
#
|
271
|
-
#
|
748
|
+
# Raises an exception if `self` is negative.
|
749
|
+
#
|
750
|
+
# Related: Integer#ord.
|
272
751
|
#
|
273
752
|
def chr: (?encoding) -> String
|
274
753
|
|
754
|
+
# <!--
|
755
|
+
# rdoc-file=bignum.c
|
756
|
+
# - big.coerce(numeric) -> array
|
757
|
+
# -->
|
275
758
|
# Returns an array with both a `numeric` and a `big` represented as Bignum
|
276
759
|
# objects.
|
277
760
|
#
|
@@ -281,49 +764,98 @@ class Integer < Numeric
|
|
281
764
|
#
|
282
765
|
# (0x3FFFFFFFFFFFFFFF+1).coerce(42) #=> [42, 4611686018427387904]
|
283
766
|
#
|
284
|
-
def coerce: (Numeric) -> [Numeric, Numeric]
|
767
|
+
def coerce: (Numeric) -> [ Numeric, Numeric ]
|
285
768
|
|
286
769
|
def conj: () -> Integer
|
287
770
|
|
288
771
|
def conjugate: () -> Integer
|
289
772
|
|
773
|
+
# <!--
|
774
|
+
# rdoc-file=rational.c
|
775
|
+
# - int.denominator -> 1
|
776
|
+
# -->
|
290
777
|
# Returns 1.
|
291
778
|
#
|
292
779
|
def denominator: () -> Integer
|
293
780
|
|
294
|
-
#
|
295
|
-
#
|
296
|
-
#
|
297
|
-
#
|
298
|
-
#
|
781
|
+
# <!--
|
782
|
+
# rdoc-file=numeric.c
|
783
|
+
# - digits(base = 10) -> array_of_integers
|
784
|
+
# -->
|
785
|
+
# Returns an array of integers representing the `base`-radix digits of `self`;
|
786
|
+
# the first element of the array represents the least significant digit:
|
299
787
|
#
|
300
|
-
# 12345.digits
|
301
|
-
# 12345.digits(7)
|
302
|
-
# 12345.digits(100)
|
788
|
+
# 12345.digits # => [5, 4, 3, 2, 1]
|
789
|
+
# 12345.digits(7) # => [4, 6, 6, 0, 5]
|
790
|
+
# 12345.digits(100) # => [45, 23, 1]
|
303
791
|
#
|
304
|
-
#
|
792
|
+
# Raises an exception if `self` is negative or `base` is less than 2.
|
305
793
|
#
|
306
794
|
def digits: (?int base) -> ::Array[Integer]
|
307
795
|
|
308
|
-
#
|
309
|
-
#
|
796
|
+
# <!--
|
797
|
+
# rdoc-file=numeric.c
|
798
|
+
# - div(numeric) -> integer
|
799
|
+
# -->
|
800
|
+
# Performs integer division; returns the integer result of dividing `self` by
|
801
|
+
# `numeric`:
|
802
|
+
#
|
803
|
+
# 4.div(3) # => 1
|
804
|
+
# 4.div(-3) # => -2
|
805
|
+
# -4.div(3) # => -2
|
806
|
+
# -4.div(-3) # => 1
|
807
|
+
# 4.div(3.0) # => 1
|
808
|
+
# 4.div(Rational(3, 1)) # => 1
|
809
|
+
#
|
810
|
+
# Raises an exception if +numeric+ does not have method +div+.
|
310
811
|
#
|
311
812
|
def div: (Numeric) -> Integer
|
312
813
|
|
313
|
-
#
|
814
|
+
# <!--
|
815
|
+
# rdoc-file=numeric.c
|
816
|
+
# - divmod(other) -> array
|
817
|
+
# -->
|
818
|
+
# Returns a 2-element array `[q, r]`, where
|
819
|
+
#
|
820
|
+
# q = (self/other).floor # Quotient
|
821
|
+
# r = self % other # Remainder
|
822
|
+
#
|
823
|
+
# Examples:
|
824
|
+
#
|
825
|
+
# 11.divmod(4) # => [2, 3]
|
826
|
+
# 11.divmod(-4) # => [-3, -1]
|
827
|
+
# -11.divmod(4) # => [-3, 1]
|
828
|
+
# -11.divmod(-4) # => [2, -3]
|
314
829
|
#
|
315
|
-
|
316
|
-
|
317
|
-
|
830
|
+
# 12.divmod(4) # => [3, 0]
|
831
|
+
# 12.divmod(-4) # => [-3, 0]
|
832
|
+
# -12.divmod(4) # => [-3, 0]
|
833
|
+
# -12.divmod(-4) # => [3, 0]
|
834
|
+
#
|
835
|
+
# 13.divmod(4.0) # => [3, 1.0]
|
836
|
+
# 13.divmod(Rational(4, 1)) # => [3, (1/1)]
|
837
|
+
#
|
838
|
+
def divmod: (Integer) -> [ Integer, Integer ]
|
839
|
+
| (Float) -> [ Float, Float ]
|
840
|
+
| (Numeric) -> [ Numeric, Numeric ]
|
318
841
|
|
319
|
-
#
|
320
|
-
#
|
842
|
+
# <!--
|
843
|
+
# rdoc-file=numeric.c
|
844
|
+
# - downto(limit) {|i| ... } -> self
|
845
|
+
# - downto(limit) -> enumerator
|
846
|
+
# -->
|
847
|
+
# Calls the given block with each integer value from `self` down to `limit`;
|
848
|
+
# returns `self`:
|
321
849
|
#
|
322
|
-
#
|
850
|
+
# a = []
|
851
|
+
# 10.downto(5) {|i| a << i } # => 10
|
852
|
+
# a # => [10, 9, 8, 7, 6, 5]
|
853
|
+
# a = []
|
854
|
+
# 0.downto(-5) {|i| a << i } # => 0
|
855
|
+
# a # => [0, -1, -2, -3, -4, -5]
|
856
|
+
# 4.downto(5) {|i| fail 'Cannot happen' } # => 4
|
323
857
|
#
|
324
|
-
#
|
325
|
-
# puts "Liftoff!"
|
326
|
-
# #=> "5.. 4.. 3.. 2.. 1.. Liftoff!"
|
858
|
+
# With no block given, returns an Enumerator.
|
327
859
|
#
|
328
860
|
def downto: (Integer limit) { (Integer) -> void } -> Integer
|
329
861
|
| (Integer limit) -> ::Enumerator[Integer, self]
|
@@ -332,35 +864,60 @@ class Integer < Numeric
|
|
332
864
|
|
333
865
|
def eql?: (untyped) -> bool
|
334
866
|
|
867
|
+
# <!--
|
868
|
+
# rdoc-file=numeric.rb
|
869
|
+
# - int.even? -> true or false
|
870
|
+
# -->
|
335
871
|
# Returns `true` if `int` is an even number.
|
336
872
|
#
|
337
873
|
def even?: () -> bool
|
338
874
|
|
339
|
-
#
|
875
|
+
# <!--
|
876
|
+
# rdoc-file=numeric.c
|
877
|
+
# - fdiv(numeric) -> float
|
878
|
+
# -->
|
879
|
+
# Returns the Float result of dividing `self` by `numeric`:
|
880
|
+
#
|
881
|
+
# 4.fdiv(2) # => 2.0
|
882
|
+
# 4.fdiv(-2) # => -2.0
|
883
|
+
# -4.fdiv(2) # => -2.0
|
884
|
+
# 4.fdiv(2.0) # => 2.0
|
885
|
+
# 4.fdiv(Rational(3, 4)) # => 5.333333333333333
|
340
886
|
#
|
341
|
-
#
|
342
|
-
# 654321.fdiv(13731.24) #=> 47.65199646936475
|
343
|
-
# -654321.fdiv(13731) #=> -47.652829364212366
|
887
|
+
# Raises an exception if `numeric` cannot be converted to a Float.
|
344
888
|
#
|
345
889
|
def fdiv: (Numeric) -> Float
|
346
890
|
|
347
891
|
def finite?: () -> bool
|
348
892
|
|
349
|
-
#
|
350
|
-
#
|
893
|
+
# <!--
|
894
|
+
# rdoc-file=numeric.c
|
895
|
+
# - floor(ndigits = 0) -> integer
|
896
|
+
# -->
|
897
|
+
# Returns the largest number less than or equal to `self` with a precision of
|
898
|
+
# `ndigits` decimal digits.
|
351
899
|
#
|
352
|
-
# When
|
353
|
-
#
|
900
|
+
# When `ndigits` is negative, the returned value has at least `ndigits.abs`
|
901
|
+
# trailing zeros:
|
902
|
+
#
|
903
|
+
# 555.floor(-1) # => 550
|
904
|
+
# 555.floor(-2) # => 500
|
905
|
+
# -555.floor(-2) # => -600
|
906
|
+
# 555.floor(-3) # => 0
|
354
907
|
#
|
355
908
|
# Returns `self` when `ndigits` is zero or positive.
|
356
909
|
#
|
357
|
-
#
|
358
|
-
#
|
359
|
-
#
|
360
|
-
#
|
910
|
+
# 555.floor # => 555
|
911
|
+
# 555.floor(50) # => 555
|
912
|
+
#
|
913
|
+
# Related: Integer#ceil.
|
361
914
|
#
|
362
915
|
def floor: (?int digits) -> Integer
|
363
916
|
|
917
|
+
# <!--
|
918
|
+
# rdoc-file=rational.c
|
919
|
+
# - int.gcd(other_int) -> integer
|
920
|
+
# -->
|
364
921
|
# Returns the greatest common divisor of the two integers. The result is always
|
365
922
|
# positive. 0.gcd(x) and x.gcd(0) return x.abs.
|
366
923
|
#
|
@@ -371,6 +928,10 @@ class Integer < Numeric
|
|
371
928
|
#
|
372
929
|
def gcd: (Integer) -> Integer
|
373
930
|
|
931
|
+
# <!--
|
932
|
+
# rdoc-file=rational.c
|
933
|
+
# - int.gcdlcm(other_int) -> array
|
934
|
+
# -->
|
374
935
|
# Returns an array with the greatest common divisor and the least common
|
375
936
|
# multiple of the two integers, [gcd, lcm].
|
376
937
|
#
|
@@ -389,12 +950,36 @@ class Integer < Numeric
|
|
389
950
|
|
390
951
|
def infinite?: () -> Integer?
|
391
952
|
|
953
|
+
# <!-- rdoc-file=numeric.c -->
|
954
|
+
# Returns a string containing the place-value representation of `self` in radix
|
955
|
+
# `base` (in 2..36).
|
956
|
+
#
|
957
|
+
# 12345.to_s # => "12345"
|
958
|
+
# 12345.to_s(2) # => "11000000111001"
|
959
|
+
# 12345.to_s(8) # => "30071"
|
960
|
+
# 12345.to_s(10) # => "12345"
|
961
|
+
# 12345.to_s(16) # => "3039"
|
962
|
+
# 12345.to_s(36) # => "9ix"
|
963
|
+
# 78546939656932.to_s(36) # => "rubyrules"
|
964
|
+
#
|
965
|
+
# Raises an exception if `base` is out of range.
|
966
|
+
#
|
967
|
+
# Integer#inspect is an alias for Integer#to_s.
|
968
|
+
#
|
392
969
|
alias inspect to_s
|
393
970
|
|
971
|
+
# <!--
|
972
|
+
# rdoc-file=numeric.rb
|
973
|
+
# - int.integer? -> true
|
974
|
+
# -->
|
394
975
|
# Since `int` is already an Integer, this always returns `true`.
|
395
976
|
#
|
396
977
|
def integer?: () -> true
|
397
978
|
|
979
|
+
# <!--
|
980
|
+
# rdoc-file=rational.c
|
981
|
+
# - int.lcm(other_int) -> integer
|
982
|
+
# -->
|
398
983
|
# Returns the least common multiple of the two integers. The result is always
|
399
984
|
# positive. 0.lcm(x) and x.lcm(0) return zero.
|
400
985
|
#
|
@@ -405,47 +990,100 @@ class Integer < Numeric
|
|
405
990
|
#
|
406
991
|
def lcm: (Integer) -> Integer
|
407
992
|
|
408
|
-
#
|
409
|
-
#
|
410
|
-
#
|
411
|
-
#
|
412
|
-
# 12345.abs #=> 12345
|
413
|
-
#
|
414
|
-
# Integer#magnitude is an alias for Integer#abs.
|
993
|
+
# <!--
|
994
|
+
# rdoc-file=numeric.rb
|
995
|
+
# - magnitude()
|
996
|
+
# -->
|
415
997
|
#
|
416
998
|
def magnitude: () -> Integer
|
417
999
|
|
418
|
-
#
|
1000
|
+
# <!-- rdoc-file=numeric.c -->
|
1001
|
+
# Returns `self` modulo `other` as a real number.
|
1002
|
+
#
|
1003
|
+
# For integer `n` and real number `r`, these expressions are equivalent:
|
1004
|
+
#
|
1005
|
+
# n % r
|
1006
|
+
# n-r*(n/r).floor
|
1007
|
+
# n.divmod(r)[1]
|
1008
|
+
#
|
1009
|
+
# See Numeric#divmod.
|
1010
|
+
#
|
1011
|
+
# Examples:
|
1012
|
+
#
|
1013
|
+
# 10 % 2 # => 0
|
1014
|
+
# 10 % 3 # => 1
|
1015
|
+
# 10 % 4 # => 2
|
1016
|
+
#
|
1017
|
+
# 10 % -2 # => 0
|
1018
|
+
# 10 % -3 # => -2
|
1019
|
+
# 10 % -4 # => -2
|
1020
|
+
#
|
1021
|
+
# 10 % 3.0 # => 1.0
|
1022
|
+
# 10 % Rational(3, 1) # => (1/1)
|
419
1023
|
#
|
420
|
-
#
|
1024
|
+
# Integer#modulo is an alias for Integer#%.
|
421
1025
|
#
|
422
|
-
alias modulo
|
1026
|
+
alias modulo %
|
423
1027
|
|
424
1028
|
def negative?: () -> bool
|
425
1029
|
|
426
|
-
#
|
1030
|
+
# <!-- rdoc-file=numeric.c -->
|
1031
|
+
# Returns the successor integer of `self` (equivalent to `self + 1`):
|
427
1032
|
#
|
428
|
-
# 1.
|
429
|
-
#
|
430
|
-
#
|
431
|
-
#
|
1033
|
+
# 1.succ #=> 2
|
1034
|
+
# -1.succ #=> 0
|
1035
|
+
#
|
1036
|
+
# Integer#next is an alias for Integer#succ.
|
1037
|
+
#
|
1038
|
+
# Related: Integer#pred (predecessor value).
|
432
1039
|
#
|
433
1040
|
def next: () -> Integer
|
434
1041
|
|
435
|
-
#
|
1042
|
+
# <!--
|
1043
|
+
# rdoc-file=numeric.c
|
1044
|
+
# - nobits?(mask) -> true or false
|
1045
|
+
# -->
|
1046
|
+
# Returns `true` if no bit that is set (=1) in `mask` is also set in `self`;
|
1047
|
+
# returns `false` otherwise.
|
1048
|
+
#
|
1049
|
+
# Example values:
|
1050
|
+
#
|
1051
|
+
# 0b11110000 self
|
1052
|
+
# 0b00001111 mask
|
1053
|
+
# 0b00000000 self & mask
|
1054
|
+
# true self.nobits?(mask)
|
1055
|
+
#
|
1056
|
+
# 0b00000001 self
|
1057
|
+
# 0b11111111 mask
|
1058
|
+
# 0b00000001 self & mask
|
1059
|
+
# false self.nobits?(mask)
|
1060
|
+
#
|
1061
|
+
# Related: Integer#allbits?, Integer#anybits?.
|
436
1062
|
#
|
437
1063
|
def nobits?: (int mask) -> bool
|
438
1064
|
|
439
1065
|
def nonzero?: () -> self?
|
440
1066
|
|
1067
|
+
# <!--
|
1068
|
+
# rdoc-file=rational.c
|
1069
|
+
# - int.numerator -> self
|
1070
|
+
# -->
|
441
1071
|
# Returns self.
|
442
1072
|
#
|
443
1073
|
def numerator: () -> Integer
|
444
1074
|
|
1075
|
+
# <!--
|
1076
|
+
# rdoc-file=numeric.rb
|
1077
|
+
# - int.odd? -> true or false
|
1078
|
+
# -->
|
445
1079
|
# Returns `true` if `int` is an odd number.
|
446
1080
|
#
|
447
1081
|
def odd?: () -> bool
|
448
1082
|
|
1083
|
+
# <!--
|
1084
|
+
# rdoc-file=numeric.rb
|
1085
|
+
# - int.ord -> self
|
1086
|
+
# -->
|
449
1087
|
# Returns the `int` itself.
|
450
1088
|
#
|
451
1089
|
# 97.ord #=> 97
|
@@ -462,6 +1100,11 @@ class Integer < Numeric
|
|
462
1100
|
|
463
1101
|
def positive?: () -> bool
|
464
1102
|
|
1103
|
+
# <!--
|
1104
|
+
# rdoc-file=numeric.c
|
1105
|
+
# - integer.pow(numeric) -> numeric
|
1106
|
+
# - integer.pow(integer, integer) -> integer
|
1107
|
+
# -->
|
465
1108
|
# Returns (modular) exponentiation as:
|
466
1109
|
#
|
467
1110
|
# a.pow(b) #=> same as a**b
|
@@ -472,10 +1115,16 @@ class Integer < Numeric
|
|
472
1115
|
| (Rational) -> Rational
|
473
1116
|
| (Complex) -> Complex
|
474
1117
|
|
475
|
-
#
|
1118
|
+
# <!--
|
1119
|
+
# rdoc-file=numeric.c
|
1120
|
+
# - pred -> next_integer
|
1121
|
+
# -->
|
1122
|
+
# Returns the predecessor of `self` (equivalent to `self - 1`):
|
476
1123
|
#
|
477
|
-
# 1.pred
|
478
|
-
#
|
1124
|
+
# 1.pred #=> 0
|
1125
|
+
# -1.pred #=> -2
|
1126
|
+
#
|
1127
|
+
# Related: Integer#succ (successor value).
|
479
1128
|
#
|
480
1129
|
def pred: () -> Integer
|
481
1130
|
|
@@ -485,6 +1134,10 @@ class Integer < Numeric
|
|
485
1134
|
| (Complex) -> Complex
|
486
1135
|
| (Numeric) -> Numeric
|
487
1136
|
|
1137
|
+
# <!--
|
1138
|
+
# rdoc-file=rational.c
|
1139
|
+
# - int.rationalize([eps]) -> rational
|
1140
|
+
# -->
|
488
1141
|
# Returns the value as a rational. The optional argument `eps` is always
|
489
1142
|
# ignored.
|
490
1143
|
#
|
@@ -498,51 +1151,87 @@ class Integer < Numeric
|
|
498
1151
|
|
499
1152
|
alias rectangular rect
|
500
1153
|
|
501
|
-
#
|
1154
|
+
# <!--
|
1155
|
+
# rdoc-file=numeric.c
|
1156
|
+
# - remainder(other) -> real_number
|
1157
|
+
# -->
|
1158
|
+
# Returns the remainder after dividing `self` by `other`.
|
502
1159
|
#
|
503
|
-
#
|
1160
|
+
# Examples:
|
504
1161
|
#
|
505
|
-
#
|
506
|
-
#
|
507
|
-
#
|
508
|
-
# -
|
509
|
-
# 5.remainder(1.5) #=> 0.5
|
1162
|
+
# 11.remainder(4) # => 3
|
1163
|
+
# 11.remainder(-4) # => 3
|
1164
|
+
# -11.remainder(4) # => -3
|
1165
|
+
# -11.remainder(-4) # => -3
|
510
1166
|
#
|
511
|
-
#
|
1167
|
+
# 12.remainder(4) # => 0
|
1168
|
+
# 12.remainder(-4) # => 0
|
1169
|
+
# -12.remainder(4) # => 0
|
1170
|
+
# -12.remainder(-4) # => 0
|
1171
|
+
#
|
1172
|
+
# 13.remainder(4.0) # => 1.0
|
1173
|
+
# 13.remainder(Rational(4, 1)) # => (1/1)
|
512
1174
|
#
|
513
1175
|
def remainder: (Integer) -> Integer
|
514
1176
|
| (Float) -> Float
|
515
1177
|
| (Rational) -> Rational
|
516
1178
|
| (Numeric) -> Numeric
|
517
1179
|
|
518
|
-
#
|
519
|
-
#
|
1180
|
+
# <!--
|
1181
|
+
# rdoc-file=numeric.c
|
1182
|
+
# - round(ndigits= 0, half: :up) -> integer
|
1183
|
+
# -->
|
1184
|
+
# Returns `self` rounded to the nearest value with a precision of `ndigits`
|
1185
|
+
# decimal digits.
|
520
1186
|
#
|
521
|
-
# When
|
522
|
-
#
|
1187
|
+
# When `ndigits` is negative, the returned value has at least `ndigits.abs`
|
1188
|
+
# trailing zeros:
|
1189
|
+
#
|
1190
|
+
# 555.round(-1) # => 560
|
1191
|
+
# 555.round(-2) # => 600
|
1192
|
+
# 555.round(-3) # => 1000
|
1193
|
+
# -555.round(-2) # => -600
|
1194
|
+
# 555.round(-4) # => 0
|
523
1195
|
#
|
524
1196
|
# Returns `self` when `ndigits` is zero or positive.
|
525
1197
|
#
|
526
|
-
#
|
527
|
-
#
|
528
|
-
#
|
529
|
-
#
|
1198
|
+
# 555.round # => 555
|
1199
|
+
# 555.round(1) # => 555
|
1200
|
+
# 555.round(50) # => 555
|
1201
|
+
#
|
1202
|
+
# If keyword argument `half` is given, and `self` is equidistant from the two
|
1203
|
+
# candidate values, the rounding is according to the given `half` value:
|
530
1204
|
#
|
531
|
-
#
|
1205
|
+
# * `:up` or `nil`: round away from zero:
|
532
1206
|
#
|
533
|
-
#
|
534
|
-
#
|
535
|
-
#
|
536
|
-
#
|
537
|
-
#
|
538
|
-
#
|
539
|
-
#
|
540
|
-
#
|
541
|
-
#
|
1207
|
+
# 25.round(-1, half: :up) # => 30
|
1208
|
+
# (-25).round(-1, half: :up) # => -30
|
1209
|
+
#
|
1210
|
+
# * `:down`: round toward zero:
|
1211
|
+
#
|
1212
|
+
# 25.round(-1, half: :down) # => 20
|
1213
|
+
# (-25).round(-1, half: :down) # => -20
|
1214
|
+
#
|
1215
|
+
# * `:even`: round toward the candidate whose last nonzero digit is even:
|
1216
|
+
#
|
1217
|
+
# 25.round(-1, half: :even) # => 20
|
1218
|
+
# 15.round(-1, half: :even) # => 20
|
1219
|
+
# (-25).round(-1, half: :even) # => -20
|
1220
|
+
#
|
1221
|
+
#
|
1222
|
+
# Raises and exception if the value for `half` is invalid.
|
1223
|
+
#
|
1224
|
+
# Related: Integer#truncate.
|
542
1225
|
#
|
543
1226
|
def round: (?half: :up | :down | :even) -> Integer
|
544
1227
|
| (int digits, ?half: :up | :down | :even) -> (Integer | Float)
|
545
1228
|
|
1229
|
+
# <!--
|
1230
|
+
# rdoc-file=numeric.rb
|
1231
|
+
# - int.size -> int
|
1232
|
+
# -->
|
1233
|
+
# Document-method: Integer#size
|
1234
|
+
#
|
546
1235
|
# Returns the number of bytes in the machine representation of `int` (machine
|
547
1236
|
# dependent).
|
548
1237
|
#
|
@@ -559,51 +1248,84 @@ class Integer < Numeric
|
|
559
1248
|
| (Numeric limit, ?Integer step) { (Integer) -> void } -> void
|
560
1249
|
| (Numeric limit, ?Numeric step) { (Numeric) -> void } -> void
|
561
1250
|
| (to: Numeric, ?by: Integer) { (Integer) -> void } -> void
|
562
|
-
| (
|
1251
|
+
| (by: Numeric, ?to: Numeric) { (Numeric) -> void } -> void
|
563
1252
|
| () -> Enumerator[Integer, bot]
|
564
1253
|
| (Numeric limit, ?Integer step) -> Enumerator[Integer, void]
|
565
1254
|
| (Numeric limit, ?Numeric step) -> Enumerator[Numeric, void]
|
566
1255
|
| (to: Numeric, ?by: Integer) -> Enumerator[Integer, void]
|
567
|
-
| (
|
1256
|
+
| (by: Numeric, ?to: Numeric) -> Enumerator[Numeric, void]
|
568
1257
|
|
569
|
-
#
|
1258
|
+
# <!--
|
1259
|
+
# rdoc-file=numeric.c
|
1260
|
+
# - succ -> next_integer
|
1261
|
+
# -->
|
1262
|
+
# Returns the successor integer of `self` (equivalent to `self + 1`):
|
1263
|
+
#
|
1264
|
+
# 1.succ #=> 2
|
1265
|
+
# -1.succ #=> 0
|
570
1266
|
#
|
571
|
-
#
|
572
|
-
#
|
573
|
-
#
|
574
|
-
# (-1).succ #=> 0
|
1267
|
+
# Integer#next is an alias for Integer#succ.
|
1268
|
+
#
|
1269
|
+
# Related: Integer#pred (predecessor value).
|
575
1270
|
#
|
576
1271
|
def succ: () -> Integer
|
577
1272
|
|
578
|
-
#
|
579
|
-
#
|
1273
|
+
# <!--
|
1274
|
+
# rdoc-file=numeric.c
|
1275
|
+
# - times {|i| ... } -> self
|
1276
|
+
# - times -> enumerator
|
1277
|
+
# -->
|
1278
|
+
# Calls the given block `self` times with each integer in `(0..self-1)`:
|
580
1279
|
#
|
581
|
-
#
|
1280
|
+
# a = []
|
1281
|
+
# 5.times {|i| a.push(i) } # => 5
|
1282
|
+
# a # => [0, 1, 2, 3, 4]
|
582
1283
|
#
|
583
|
-
#
|
1284
|
+
# With no block given, returns an Enumerator.
|
584
1285
|
#
|
585
1286
|
def times: () { (Integer) -> void } -> self
|
586
1287
|
| () -> ::Enumerator[Integer, self]
|
587
1288
|
|
588
1289
|
def to_c: () -> Complex
|
589
1290
|
|
590
|
-
#
|
591
|
-
#
|
1291
|
+
# <!--
|
1292
|
+
# rdoc-file=numeric.c
|
1293
|
+
# - to_f -> float
|
1294
|
+
# -->
|
1295
|
+
# Converts `self` to a Float:
|
1296
|
+
#
|
1297
|
+
# 1.to_f # => 1.0
|
1298
|
+
# -1.to_f # => -1.0
|
1299
|
+
#
|
1300
|
+
# If the value of `self` does not fit in a Float, the result is infinity:
|
1301
|
+
#
|
1302
|
+
# (10**400).to_f # => Infinity
|
1303
|
+
# (-10**400).to_f # => -Infinity
|
592
1304
|
#
|
593
1305
|
def to_f: () -> Float
|
594
1306
|
|
1307
|
+
# <!--
|
1308
|
+
# rdoc-file=numeric.rb
|
1309
|
+
# - int.to_i -> integer
|
1310
|
+
# -->
|
595
1311
|
# Since `int` is already an Integer, returns `self`.
|
596
1312
|
#
|
597
1313
|
# #to_int is an alias for #to_i.
|
598
1314
|
#
|
599
1315
|
def to_i: () -> Integer
|
600
1316
|
|
1317
|
+
# <!--
|
1318
|
+
# rdoc-file=numeric.rb
|
1319
|
+
# - int.to_int -> integer
|
1320
|
+
# -->
|
601
1321
|
# Since `int` is already an Integer, returns `self`.
|
602
1322
|
#
|
603
|
-
# #to_int is an alias for #to_i.
|
604
|
-
#
|
605
1323
|
alias to_int to_i
|
606
1324
|
|
1325
|
+
# <!--
|
1326
|
+
# rdoc-file=rational.c
|
1327
|
+
# - int.to_r -> rational
|
1328
|
+
# -->
|
607
1329
|
# Returns the value as a rational.
|
608
1330
|
#
|
609
1331
|
# 1.to_r #=> (1/1)
|
@@ -611,16 +1333,24 @@ class Integer < Numeric
|
|
611
1333
|
#
|
612
1334
|
def to_r: () -> Rational
|
613
1335
|
|
614
|
-
#
|
615
|
-
#
|
1336
|
+
# <!--
|
1337
|
+
# rdoc-file=numeric.c
|
1338
|
+
# - to_s(base = 10) -> string
|
1339
|
+
# -->
|
1340
|
+
# Returns a string containing the place-value representation of `self` in radix
|
1341
|
+
# `base` (in 2..36).
|
616
1342
|
#
|
617
|
-
# 12345.to_s
|
618
|
-
# 12345.to_s(2)
|
619
|
-
# 12345.to_s(8)
|
620
|
-
# 12345.to_s(10)
|
621
|
-
# 12345.to_s(16)
|
622
|
-
# 12345.to_s(36)
|
623
|
-
# 78546939656932.to_s(36)
|
1343
|
+
# 12345.to_s # => "12345"
|
1344
|
+
# 12345.to_s(2) # => "11000000111001"
|
1345
|
+
# 12345.to_s(8) # => "30071"
|
1346
|
+
# 12345.to_s(10) # => "12345"
|
1347
|
+
# 12345.to_s(16) # => "3039"
|
1348
|
+
# 12345.to_s(36) # => "9ix"
|
1349
|
+
# 78546939656932.to_s(36) # => "rubyrules"
|
1350
|
+
#
|
1351
|
+
# Raises an exception if `base` is out of range.
|
1352
|
+
#
|
1353
|
+
# Integer#inspect is an alias for Integer#to_s.
|
624
1354
|
#
|
625
1355
|
def to_s: () -> String
|
626
1356
|
| (2) -> String
|
@@ -660,38 +1390,78 @@ class Integer < Numeric
|
|
660
1390
|
| (36) -> String
|
661
1391
|
| (int base) -> String
|
662
1392
|
|
663
|
-
#
|
664
|
-
#
|
1393
|
+
# <!--
|
1394
|
+
# rdoc-file=numeric.c
|
1395
|
+
# - truncate(ndigits = 0) -> integer
|
1396
|
+
# -->
|
1397
|
+
# Returns `self` truncated (toward zero) to a precision of `ndigits` decimal
|
1398
|
+
# digits.
|
665
1399
|
#
|
666
|
-
# When
|
667
|
-
#
|
1400
|
+
# When `ndigits` is negative, the returned value has at least `ndigits.abs`
|
1401
|
+
# trailing zeros:
|
1402
|
+
#
|
1403
|
+
# 555.truncate(-1) # => 550
|
1404
|
+
# 555.truncate(-2) # => 500
|
1405
|
+
# -555.truncate(-2) # => -500
|
668
1406
|
#
|
669
1407
|
# Returns `self` when `ndigits` is zero or positive.
|
670
1408
|
#
|
671
|
-
#
|
672
|
-
#
|
673
|
-
#
|
674
|
-
#
|
1409
|
+
# 555.truncate # => 555
|
1410
|
+
# 555.truncate(50) # => 555
|
1411
|
+
#
|
1412
|
+
# Related: Integer#round.
|
675
1413
|
#
|
676
1414
|
def truncate: () -> Integer
|
677
1415
|
| (int ndigits) -> Integer
|
678
1416
|
|
679
|
-
#
|
680
|
-
#
|
1417
|
+
# <!--
|
1418
|
+
# rdoc-file=numeric.c
|
1419
|
+
# - upto(limit) {|i| ... } -> self
|
1420
|
+
# - upto(limit) -> enumerator
|
1421
|
+
# -->
|
1422
|
+
# Calls the given block with each integer value from `self` up to `limit`;
|
1423
|
+
# returns `self`:
|
681
1424
|
#
|
682
|
-
#
|
1425
|
+
# a = []
|
1426
|
+
# 5.upto(10) {|i| a << i } # => 5
|
1427
|
+
# a # => [5, 6, 7, 8, 9, 10]
|
1428
|
+
# a = []
|
1429
|
+
# -5.upto(0) {|i| a << i } # => -5
|
1430
|
+
# a # => [-5, -4, -3, -2, -1, 0]
|
1431
|
+
# 5.upto(4) {|i| fail 'Cannot happen' } # => 5
|
683
1432
|
#
|
684
|
-
#
|
1433
|
+
# With no block given, returns an Enumerator.
|
685
1434
|
#
|
686
1435
|
def upto: (Integer limit) { (Integer) -> void } -> Integer
|
687
1436
|
| (Integer limit) -> ::Enumerator[Integer, self]
|
688
1437
|
|
1438
|
+
# <!--
|
1439
|
+
# rdoc-file=numeric.rb
|
1440
|
+
# - int.zero? -> true or false
|
1441
|
+
# -->
|
1442
|
+
# Returns `true` if `int` has a zero value.
|
1443
|
+
#
|
689
1444
|
def zero?: () -> bool
|
690
1445
|
|
691
|
-
#
|
1446
|
+
# <!--
|
1447
|
+
# rdoc-file=numeric.c
|
1448
|
+
# - self | other -> integer
|
1449
|
+
# -->
|
1450
|
+
# Bitwise OR; each bit in the result is 1 if either corresponding bit in `self`
|
1451
|
+
# or `other` is 1, 0 otherwise:
|
1452
|
+
#
|
1453
|
+
# "%04b" % (0b0101 | 0b0110) # => "0111"
|
1454
|
+
#
|
1455
|
+
# Raises an exception if `other` is not an Integer.
|
1456
|
+
#
|
1457
|
+
# Related: Integer#& (bitwise AND), Integer#^ (bitwise EXCLUSIVE OR).
|
692
1458
|
#
|
693
1459
|
def |: (Integer) -> Integer
|
694
1460
|
|
1461
|
+
# <!--
|
1462
|
+
# rdoc-file=numeric.rb
|
1463
|
+
# - ~int -> integer
|
1464
|
+
# -->
|
695
1465
|
# One's complement: returns a number where each bit is flipped.
|
696
1466
|
#
|
697
1467
|
# Inverts the bits in an Integer. As integers are conceptually of infinite
|