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
@@ -1,3 +1,4 @@
|
|
1
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
1
2
|
# BigDecimal provides arbitrary-precision floating point decimal arithmetic.
|
2
3
|
#
|
3
4
|
# ## Introduction
|
@@ -40,6 +41,19 @@
|
|
40
41
|
#
|
41
42
|
# (1.2 - 1.0) == 0.2 #=> false
|
42
43
|
#
|
44
|
+
# ## A Note About Precision
|
45
|
+
#
|
46
|
+
# For a calculation using a BigDecimal and another `value`, the precision of the
|
47
|
+
# result depends on the type of `value`:
|
48
|
+
#
|
49
|
+
# * If `value` is a Float, the precision is Float::DIG + 1.
|
50
|
+
# * If `value` is a Rational, the precision is larger than Float::DIG + 1.
|
51
|
+
# * If `value` is a BigDecimal, the precision is `value`'s precision in the
|
52
|
+
# internal representation, which is platform-dependent.
|
53
|
+
# * If `value` is other object, the precision is determined by the result of
|
54
|
+
# +BigDecimal(value)+.
|
55
|
+
#
|
56
|
+
#
|
43
57
|
# ## Special features of accurate decimal arithmetic
|
44
58
|
#
|
45
59
|
# Because BigDecimal is more accurate than normal binary floating point
|
@@ -121,17 +135,36 @@
|
|
121
135
|
# many other contributors.
|
122
136
|
#
|
123
137
|
class BigDecimal < Numeric
|
138
|
+
# <!--
|
139
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
140
|
+
# - _load(p1)
|
141
|
+
# -->
|
124
142
|
# Internal method used to provide marshalling support. See the Marshal module.
|
125
143
|
#
|
126
144
|
def self._load: (String) -> BigDecimal
|
127
145
|
|
128
|
-
#
|
129
|
-
#
|
146
|
+
# <!--
|
147
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
148
|
+
# - BigDecimal.double_fig -> integer
|
149
|
+
# -->
|
150
|
+
# Returns the number of digits a Float object is allowed to have; the result is
|
151
|
+
# system-dependent:
|
152
|
+
#
|
153
|
+
# BigDecimal.double_fig # => 16
|
130
154
|
#
|
131
155
|
def self.double_fig: () -> Integer
|
132
156
|
|
157
|
+
# <!--
|
158
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
159
|
+
# - interpret_loosely(p1)
|
160
|
+
# -->
|
161
|
+
#
|
133
162
|
def self.interpret_loosely: (string) -> BigDecimal
|
134
163
|
|
164
|
+
# <!--
|
165
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
166
|
+
# - BigDecimal.limit(digits)
|
167
|
+
# -->
|
135
168
|
# Limit the number of significant digits in newly created BigDecimal numbers to
|
136
169
|
# the specified value. Rounding is performed as necessary, as specified by
|
137
170
|
# BigDecimal.mode.
|
@@ -143,55 +176,172 @@ class BigDecimal < Numeric
|
|
143
176
|
#
|
144
177
|
def self.limit: (?Integer? digits) -> Integer
|
145
178
|
|
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
|
-
#
|
179
|
+
# <!--
|
180
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
181
|
+
# - BigDecimal.mode(mode, setting = nil) -> integer
|
182
|
+
# -->
|
183
|
+
# Returns an integer representing the mode settings for exception handling and
|
184
|
+
# rounding.
|
185
|
+
#
|
186
|
+
# These modes control exception handling:
|
187
|
+
#
|
188
|
+
# * BigDecimal::EXCEPTION_NaN.
|
189
|
+
# * BigDecimal::EXCEPTION_INFINITY.
|
190
|
+
# * BigDecimal::EXCEPTION_UNDERFLOW.
|
191
|
+
# * BigDecimal::EXCEPTION_OVERFLOW.
|
192
|
+
# * BigDecimal::EXCEPTION_ZERODIVIDE.
|
193
|
+
# * BigDecimal::EXCEPTION_ALL.
|
194
|
+
#
|
195
|
+
#
|
196
|
+
# Values for `setting` for exception handling:
|
197
|
+
#
|
198
|
+
# * `true`: sets the given `mode` to `true`.
|
199
|
+
# * `false`: sets the given `mode` to `false`.
|
200
|
+
# * `nil`: does not modify the mode settings.
|
201
|
+
#
|
202
|
+
#
|
203
|
+
# You can use method BigDecimal.save_exception_mode to temporarily change, and
|
204
|
+
# then automatically restore, exception modes.
|
205
|
+
#
|
206
|
+
# For clarity, some examples below begin by setting all exception modes to
|
207
|
+
# `false`.
|
208
|
+
#
|
209
|
+
# This mode controls the way rounding is to be performed:
|
210
|
+
#
|
211
|
+
# * BigDecimal::ROUND_MODE
|
212
|
+
#
|
213
|
+
#
|
214
|
+
# You can use method BigDecimal.save_rounding_mode to temporarily change, and
|
215
|
+
# then automatically restore, the rounding mode.
|
216
|
+
#
|
217
|
+
# **NaNs**
|
218
|
+
#
|
219
|
+
# Mode BigDecimal::EXCEPTION_NaN controls behavior when a BigDecimal NaN is
|
220
|
+
# created.
|
221
|
+
#
|
222
|
+
# Settings:
|
223
|
+
#
|
224
|
+
# * `false` (default): Returns `BigDecimal('NaN')`.
|
225
|
+
# * `true`: Raises FloatDomainError.
|
226
|
+
#
|
227
|
+
#
|
228
|
+
# Examples:
|
229
|
+
#
|
230
|
+
# BigDecimal.mode(BigDecimal::EXCEPTION_ALL, false) # => 0
|
231
|
+
# BigDecimal('NaN') # => NaN
|
232
|
+
# BigDecimal.mode(BigDecimal::EXCEPTION_NaN, true) # => 2
|
233
|
+
# BigDecimal('NaN') # Raises FloatDomainError
|
234
|
+
#
|
235
|
+
# **Infinities**
|
236
|
+
#
|
237
|
+
# Mode BigDecimal::EXCEPTION_INFINITY controls behavior when a BigDecimal
|
238
|
+
# Infinity or -Infinity is created. Settings:
|
239
|
+
#
|
240
|
+
# * `false` (default): Returns `BigDecimal('Infinity')` or
|
241
|
+
# `BigDecimal('-Infinity')`.
|
242
|
+
# * `true`: Raises FloatDomainError.
|
243
|
+
#
|
244
|
+
#
|
245
|
+
# Examples:
|
246
|
+
#
|
247
|
+
# BigDecimal.mode(BigDecimal::EXCEPTION_ALL, false) # => 0
|
248
|
+
# BigDecimal('Infinity') # => Infinity
|
249
|
+
# BigDecimal('-Infinity') # => -Infinity
|
250
|
+
# BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY, true) # => 1
|
251
|
+
# BigDecimal('Infinity') # Raises FloatDomainError
|
252
|
+
# BigDecimal('-Infinity') # Raises FloatDomainError
|
253
|
+
#
|
254
|
+
# **Underflow**
|
255
|
+
#
|
256
|
+
# Mode BigDecimal::EXCEPTION_UNDERFLOW controls behavior when a BigDecimal
|
257
|
+
# underflow occurs. Settings:
|
258
|
+
#
|
259
|
+
# * `false` (default): Returns `BigDecimal('0')` or `BigDecimal('-Infinity')`.
|
260
|
+
# * `true`: Raises FloatDomainError.
|
261
|
+
#
|
262
|
+
#
|
263
|
+
# Examples:
|
264
|
+
#
|
265
|
+
# BigDecimal.mode(BigDecimal::EXCEPTION_ALL, false) # => 0
|
266
|
+
# def flow_under
|
267
|
+
# x = BigDecimal('0.1')
|
268
|
+
# 100.times { x *= x }
|
269
|
+
# end
|
270
|
+
# flow_under # => 100
|
271
|
+
# BigDecimal.mode(BigDecimal::EXCEPTION_UNDERFLOW, true) # => 4
|
272
|
+
# flow_under # Raises FloatDomainError
|
273
|
+
#
|
274
|
+
# **Overflow**
|
275
|
+
#
|
276
|
+
# Mode BigDecimal::EXCEPTION_OVERFLOW controls behavior when a BigDecimal
|
277
|
+
# overflow occurs. Settings:
|
278
|
+
#
|
279
|
+
# * `false` (default): Returns `BigDecimal('Infinity')` or
|
280
|
+
# `BigDecimal('-Infinity')`.
|
281
|
+
# * `true`: Raises FloatDomainError.
|
282
|
+
#
|
283
|
+
#
|
284
|
+
# Examples:
|
285
|
+
#
|
286
|
+
# BigDecimal.mode(BigDecimal::EXCEPTION_ALL, false) # => 0
|
287
|
+
# def flow_over
|
288
|
+
# x = BigDecimal('10')
|
289
|
+
# 100.times { x *= x }
|
290
|
+
# end
|
291
|
+
# flow_over # => 100
|
292
|
+
# BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW, true) # => 1
|
293
|
+
# flow_over # Raises FloatDomainError
|
294
|
+
#
|
295
|
+
# **Zero Division**
|
296
|
+
#
|
297
|
+
# Mode BigDecimal::EXCEPTION_ZERODIVIDE controls behavior when a zero-division
|
298
|
+
# occurs. Settings:
|
299
|
+
#
|
300
|
+
# * `false` (default): Returns `BigDecimal('Infinity')` or
|
301
|
+
# `BigDecimal('-Infinity')`.
|
302
|
+
# * `true`: Raises FloatDomainError.
|
303
|
+
#
|
304
|
+
#
|
305
|
+
# Examples:
|
306
|
+
#
|
307
|
+
# BigDecimal.mode(BigDecimal::EXCEPTION_ALL, false) # => 0
|
308
|
+
# one = BigDecimal('1')
|
309
|
+
# zero = BigDecimal('0')
|
310
|
+
# one / zero # => Infinity
|
311
|
+
# BigDecimal.mode(BigDecimal::EXCEPTION_ZERODIVIDE, true) # => 16
|
312
|
+
# one / zero # Raises FloatDomainError
|
313
|
+
#
|
314
|
+
# **All Exceptions**
|
315
|
+
#
|
316
|
+
# Mode BigDecimal::EXCEPTION_ALL controls all of the above:
|
317
|
+
#
|
318
|
+
# BigDecimal.mode(BigDecimal::EXCEPTION_ALL, false) # => 0
|
319
|
+
# BigDecimal.mode(BigDecimal::EXCEPTION_ALL, true) # => 23
|
320
|
+
#
|
321
|
+
# **Rounding**
|
322
|
+
#
|
323
|
+
# Mode BigDecimal::ROUND_MODE controls the way rounding is to be performed; its
|
324
|
+
# `setting` values are:
|
325
|
+
#
|
326
|
+
# * `ROUND_UP`: Round away from zero. Aliased as `:up`.
|
327
|
+
# * `ROUND_DOWN`: Round toward zero. Aliased as `:down` and `:truncate`.
|
328
|
+
# * `ROUND_HALF_UP`: Round toward the nearest neighbor; if the neighbors are
|
329
|
+
# equidistant, round away from zero. Aliased as `:half_up` and `:default`.
|
330
|
+
# * `ROUND_HALF_DOWN`: Round toward the nearest neighbor; if the neighbors are
|
331
|
+
# equidistant, round toward zero. Aliased as `:half_down`.
|
332
|
+
# * `ROUND_HALF_EVEN` (Banker's rounding): Round toward the nearest neighbor;
|
333
|
+
# if the neighbors are equidistant, round toward the even neighbor. Aliased
|
334
|
+
# as `:half_even` and `:banker`.
|
335
|
+
# * `ROUND_CEILING`: Round toward positive infinity. Aliased as `:ceiling` and
|
336
|
+
# `:ceil`.
|
337
|
+
# * `ROUND_FLOOR`: Round toward negative infinity. Aliased as `:floor:`.
|
192
338
|
#
|
193
339
|
def self.mode: (Integer mode, ?Integer? value) -> Integer?
|
194
340
|
|
341
|
+
# <!--
|
342
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
343
|
+
# - BigDecimal.save_exception_mode { ... }
|
344
|
+
# -->
|
195
345
|
# Execute the provided block, but preserve the exception mode
|
196
346
|
#
|
197
347
|
# BigDecimal.save_exception_mode do
|
@@ -209,6 +359,10 @@ class BigDecimal < Numeric
|
|
209
359
|
#
|
210
360
|
def self.save_exception_mode: () { (?nil) -> void } -> void
|
211
361
|
|
362
|
+
# <!--
|
363
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
364
|
+
# - BigDecimal.save_limit { ... }
|
365
|
+
# -->
|
212
366
|
# Execute the provided block, but preserve the precision limit
|
213
367
|
#
|
214
368
|
# BigDecimal.limit(100)
|
@@ -221,6 +375,10 @@ class BigDecimal < Numeric
|
|
221
375
|
#
|
222
376
|
def self.save_limit: () { (?nil) -> void } -> void
|
223
377
|
|
378
|
+
# <!--
|
379
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
380
|
+
# - BigDecimal.save_rounding_mode { ... }
|
381
|
+
# -->
|
224
382
|
# Execute the provided block, but preserve the rounding mode
|
225
383
|
#
|
226
384
|
# BigDecimal.save_rounding_mode do
|
@@ -236,93 +394,154 @@ class BigDecimal < Numeric
|
|
236
394
|
|
237
395
|
public
|
238
396
|
|
397
|
+
# <!--
|
398
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
399
|
+
# - a % b
|
400
|
+
# - a.modulo(b)
|
401
|
+
# -->
|
239
402
|
# Returns the modulus from dividing by b.
|
240
403
|
#
|
241
404
|
# See BigDecimal#divmod.
|
242
405
|
#
|
243
406
|
def %: (Numeric) -> BigDecimal
|
244
407
|
|
245
|
-
#
|
246
|
-
#
|
247
|
-
#
|
248
|
-
#
|
249
|
-
# c = a * b
|
250
|
-
#
|
251
|
-
# digits
|
252
|
-
# : If specified and less than the number of significant digits of the result,
|
253
|
-
# the result is rounded to that number of digits, according to
|
254
|
-
# BigDecimal.mode.
|
408
|
+
# <!--
|
409
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
410
|
+
# - *(p1)
|
411
|
+
# -->
|
255
412
|
#
|
256
413
|
def *: (Numeric) -> BigDecimal
|
257
414
|
|
258
|
-
#
|
415
|
+
# <!--
|
416
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
417
|
+
# - self ** other -> bigdecimal
|
418
|
+
# -->
|
419
|
+
# Returns the BigDecimal value of `self` raised to power `other`:
|
420
|
+
#
|
421
|
+
# b = BigDecimal('3.14')
|
422
|
+
# b ** 2 # => 0.98596e1
|
423
|
+
# b ** 2.0 # => 0.98596e1
|
424
|
+
# b ** Rational(2, 1) # => 0.98596e1
|
259
425
|
#
|
260
|
-
#
|
426
|
+
# Related: BigDecimal#power.
|
261
427
|
#
|
262
428
|
def **: (Numeric) -> BigDecimal
|
263
429
|
|
264
|
-
#
|
430
|
+
# <!--
|
431
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
432
|
+
# - self + value -> bigdecimal
|
433
|
+
# -->
|
434
|
+
# Returns the BigDecimal sum of `self` and `value`:
|
265
435
|
#
|
266
|
-
#
|
267
|
-
#
|
268
|
-
#
|
436
|
+
# b = BigDecimal('111111.111') # => 0.111111111e6
|
437
|
+
# b + 2 # => 0.111113111e6
|
438
|
+
# b + 2.0 # => 0.111113111e6
|
439
|
+
# b + Rational(2, 1) # => 0.111113111e6
|
440
|
+
# b + Complex(2, 0) # => (0.111113111e6+0i)
|
269
441
|
#
|
270
|
-
#
|
271
|
-
#
|
272
|
-
# the result is rounded to that number of digits, according to
|
273
|
-
# BigDecimal.mode.
|
442
|
+
# See the [Note About
|
443
|
+
# Precision](BigDecimal.html#class-BigDecimal-label-A+Note+About+Precision).
|
274
444
|
#
|
275
445
|
def +: (Numeric) -> BigDecimal
|
276
446
|
|
277
|
-
#
|
447
|
+
# <!--
|
448
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
449
|
+
# - +big_decimal -> self
|
450
|
+
# -->
|
451
|
+
# Returns `self`:
|
278
452
|
#
|
279
|
-
# +BigDecimal(
|
453
|
+
# +BigDecimal(5) # => 0.5e1
|
454
|
+
# +BigDecimal(-5) # => -0.5e1
|
280
455
|
#
|
281
456
|
def +@: () -> BigDecimal
|
282
457
|
|
283
|
-
#
|
284
|
-
#
|
285
|
-
#
|
286
|
-
#
|
458
|
+
# <!--
|
459
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
460
|
+
# - self - value -> bigdecimal
|
461
|
+
# -->
|
462
|
+
# Returns the BigDecimal difference of `self` and `value`:
|
287
463
|
#
|
288
|
-
#
|
464
|
+
# b = BigDecimal('333333.333') # => 0.333333333e6
|
465
|
+
# b - 2 # => 0.333331333e6
|
466
|
+
# b - 2.0 # => 0.333331333e6
|
467
|
+
# b - Rational(2, 1) # => 0.333331333e6
|
468
|
+
# b - Complex(2, 0) # => (0.333331333e6+0i)
|
289
469
|
#
|
290
|
-
#
|
291
|
-
#
|
292
|
-
# If `b` is a BigDecimal, the precision of the result is `b`'s precision of
|
293
|
-
# internal representation from platform. So, it's return value is platform
|
294
|
-
# dependent.
|
470
|
+
# See the [Note About
|
471
|
+
# Precision](BigDecimal.html#class-BigDecimal-label-A+Note+About+Precision).
|
295
472
|
#
|
296
473
|
def -: (Numeric) -> BigDecimal
|
297
474
|
|
298
|
-
#
|
475
|
+
# <!--
|
476
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
477
|
+
# - -self -> bigdecimal
|
478
|
+
# -->
|
479
|
+
# Returns the BigDecimal negation of self:
|
299
480
|
#
|
300
|
-
#
|
481
|
+
# b0 = BigDecimal('1.5')
|
482
|
+
# b1 = -b0 # => -0.15e1
|
483
|
+
# b2 = -b1 # => 0.15e1
|
301
484
|
#
|
302
485
|
def -@: () -> BigDecimal
|
303
486
|
|
487
|
+
# <!--
|
488
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
489
|
+
# - a / b -> bigdecimal
|
490
|
+
# -->
|
304
491
|
# Divide by the specified value.
|
305
492
|
#
|
306
|
-
#
|
493
|
+
# The result precision will be the precision of the larger operand, but its
|
494
|
+
# minimum is 2*Float::DIG.
|
495
|
+
#
|
496
|
+
# See BigDecimal#div. See BigDecimal#quo.
|
307
497
|
#
|
308
498
|
def /: (Numeric) -> BigDecimal
|
309
499
|
|
310
|
-
#
|
500
|
+
# <!--
|
501
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
502
|
+
# - self < other -> true or false
|
503
|
+
# -->
|
504
|
+
# Returns `true` if `self` is less than `other`, `false` otherwise:
|
311
505
|
#
|
312
|
-
#
|
506
|
+
# b = BigDecimal('1.5') # => 0.15e1
|
507
|
+
# b < 2 # => true
|
508
|
+
# b < 2.0 # => true
|
509
|
+
# b < Rational(2, 1) # => true
|
510
|
+
# b < 1.5 # => false
|
511
|
+
#
|
512
|
+
# Raises an exception if the comparison cannot be made.
|
313
513
|
#
|
314
514
|
def <: (Numeric) -> bool
|
315
515
|
|
316
|
-
#
|
516
|
+
# <!--
|
517
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
518
|
+
# - self <= other -> true or false
|
519
|
+
# -->
|
520
|
+
# Returns `true` if `self` is less or equal to than `other`, `false` otherwise:
|
521
|
+
#
|
522
|
+
# b = BigDecimal('1.5') # => 0.15e1
|
523
|
+
# b <= 2 # => true
|
524
|
+
# b <= 2.0 # => true
|
525
|
+
# b <= Rational(2, 1) # => true
|
526
|
+
# b <= 1.5 # => true
|
527
|
+
# b < 1 # => false
|
317
528
|
#
|
318
|
-
#
|
529
|
+
# Raises an exception if the comparison cannot be made.
|
319
530
|
#
|
320
531
|
def <=: (Numeric) -> bool
|
321
532
|
|
533
|
+
# <!--
|
534
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
535
|
+
# - <=>(p1)
|
536
|
+
# -->
|
322
537
|
# The comparison operator. a <=> b is 0 if a == b, 1 if a > b, -1 if a < b.
|
323
538
|
#
|
324
539
|
def <=>: (untyped) -> Integer?
|
325
540
|
|
541
|
+
# <!--
|
542
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
543
|
+
# - ==(p1)
|
544
|
+
# -->
|
326
545
|
# Tests for value equality; returns true if the values are equal.
|
327
546
|
#
|
328
547
|
# The == and === operators and the eql? method have the same implementation for
|
@@ -334,6 +553,7 @@ class BigDecimal < Numeric
|
|
334
553
|
#
|
335
554
|
def ==: (untyped) -> bool
|
336
555
|
|
556
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
337
557
|
# Tests for value equality; returns true if the values are equal.
|
338
558
|
#
|
339
559
|
# The == and === operators and the eql? method have the same implementation for
|
@@ -345,49 +565,92 @@ class BigDecimal < Numeric
|
|
345
565
|
#
|
346
566
|
def ===: (untyped) -> bool
|
347
567
|
|
348
|
-
#
|
568
|
+
# <!--
|
569
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
570
|
+
# - self > other -> true or false
|
571
|
+
# -->
|
572
|
+
# Returns `true` if `self` is greater than `other`, `false` otherwise:
|
349
573
|
#
|
350
|
-
#
|
574
|
+
# b = BigDecimal('1.5')
|
575
|
+
# b > 1 # => true
|
576
|
+
# b > 1.0 # => true
|
577
|
+
# b > Rational(1, 1) # => true
|
578
|
+
# b > 2 # => false
|
579
|
+
#
|
580
|
+
# Raises an exception if the comparison cannot be made.
|
351
581
|
#
|
352
582
|
def >: (Numeric) -> bool
|
353
583
|
|
354
|
-
#
|
584
|
+
# <!--
|
585
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
586
|
+
# - self >= other -> true or false
|
587
|
+
# -->
|
588
|
+
# Returns `true` if `self` is greater than or equal to `other`, `false`
|
589
|
+
# otherwise:
|
590
|
+
#
|
591
|
+
# b = BigDecimal('1.5')
|
592
|
+
# b >= 1 # => true
|
593
|
+
# b >= 1.0 # => true
|
594
|
+
# b >= Rational(1, 1) # => true
|
595
|
+
# b >= 1.5 # => true
|
596
|
+
# b > 2 # => false
|
355
597
|
#
|
356
|
-
#
|
598
|
+
# Raises an exception if the comparison cannot be made.
|
357
599
|
#
|
358
600
|
def >=: (Numeric) -> bool
|
359
601
|
|
360
|
-
#
|
361
|
-
#
|
362
|
-
#
|
363
|
-
#
|
364
|
-
#
|
365
|
-
# #=> Infinity
|
602
|
+
# <!--
|
603
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
604
|
+
# - _dump -> string
|
605
|
+
# -->
|
606
|
+
# Returns a string representing the marshalling of `self`. See module Marshal.
|
366
607
|
#
|
367
|
-
#
|
608
|
+
# inf = BigDecimal('Infinity') # => Infinity
|
609
|
+
# dumped = inf._dump # => "9:Infinity"
|
610
|
+
# BigDecimal._load(dumped) # => Infinity
|
368
611
|
#
|
369
612
|
def _dump: (?untyped) -> String
|
370
613
|
|
371
|
-
#
|
614
|
+
# <!--
|
615
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
616
|
+
# - abs -> bigdecimal
|
617
|
+
# -->
|
618
|
+
# Returns the BigDecimal absolute value of `self`:
|
372
619
|
#
|
373
|
-
# BigDecimal('5').abs
|
374
|
-
# BigDecimal('-3').abs
|
620
|
+
# BigDecimal('5').abs # => 0.5e1
|
621
|
+
# BigDecimal('-3').abs # => 0.3e1
|
375
622
|
#
|
376
623
|
def abs: () -> BigDecimal
|
377
624
|
|
378
|
-
#
|
625
|
+
# <!--
|
626
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
627
|
+
# - add(value, ndigits) -> new_bigdecimal
|
628
|
+
# -->
|
629
|
+
# Returns the BigDecimal sum of `self` and `value` with a precision of `ndigits`
|
630
|
+
# decimal digits.
|
379
631
|
#
|
380
|
-
#
|
381
|
-
#
|
382
|
-
#
|
632
|
+
# When `ndigits` is less than the number of significant digits in the sum, the
|
633
|
+
# sum is rounded to that number of digits, according to the current rounding
|
634
|
+
# mode; see BigDecimal.mode.
|
383
635
|
#
|
384
|
-
#
|
385
|
-
#
|
386
|
-
#
|
387
|
-
# BigDecimal.mode
|
636
|
+
# Examples:
|
637
|
+
#
|
638
|
+
# # Set the rounding mode.
|
639
|
+
# BigDecimal.mode(BigDecimal::ROUND_MODE, :half_up)
|
640
|
+
# b = BigDecimal('111111.111')
|
641
|
+
# b.add(1, 0) # => 0.111112111e6
|
642
|
+
# b.add(1, 3) # => 0.111e6
|
643
|
+
# b.add(1, 6) # => 0.111112e6
|
644
|
+
# b.add(1, 15) # => 0.111112111e6
|
645
|
+
# b.add(1.0, 15) # => 0.111112111e6
|
646
|
+
# b.add(Rational(1, 1), 15) # => 0.111112111e6
|
388
647
|
#
|
389
648
|
def add: (Numeric value, Integer digits) -> BigDecimal
|
390
649
|
|
650
|
+
# <!--
|
651
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
652
|
+
# - ceil(n)
|
653
|
+
# -->
|
391
654
|
# Return the smallest integer greater than or equal to the value, as a
|
392
655
|
# BigDecimal.
|
393
656
|
#
|
@@ -406,8 +669,17 @@ class BigDecimal < Numeric
|
|
406
669
|
def ceil: () -> Integer
|
407
670
|
| (int n) -> BigDecimal
|
408
671
|
|
672
|
+
# <!--
|
673
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
674
|
+
# - clone()
|
675
|
+
# -->
|
676
|
+
#
|
409
677
|
def clone: () -> self
|
410
678
|
|
679
|
+
# <!--
|
680
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
681
|
+
# - coerce(p1)
|
682
|
+
# -->
|
411
683
|
# The coerce method provides support for Ruby type coercion. It is not enabled
|
412
684
|
# by default.
|
413
685
|
#
|
@@ -422,8 +694,13 @@ class BigDecimal < Numeric
|
|
422
694
|
# Note that coercing a String to a BigDecimal is not supported by default; it
|
423
695
|
# requires a special compile-time option when building Ruby.
|
424
696
|
#
|
425
|
-
def coerce: (Numeric) -> [BigDecimal, BigDecimal]
|
697
|
+
def coerce: (Numeric) -> [ BigDecimal, BigDecimal ]
|
426
698
|
|
699
|
+
# <!--
|
700
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
701
|
+
# - div(value) -> integer
|
702
|
+
# - div(value, digits) -> bigdecimal or integer
|
703
|
+
# -->
|
427
704
|
# Divide by the specified value.
|
428
705
|
#
|
429
706
|
# digits
|
@@ -437,6 +714,8 @@ class BigDecimal < Numeric
|
|
437
714
|
# Float#div; see also BigDecimal#divmod.
|
438
715
|
#
|
439
716
|
#
|
717
|
+
# See BigDecimal#/. See BigDecimal#quo.
|
718
|
+
#
|
440
719
|
# Examples:
|
441
720
|
#
|
442
721
|
# a = BigDecimal("4")
|
@@ -453,6 +732,10 @@ class BigDecimal < Numeric
|
|
453
732
|
def div: (Numeric value) -> Integer
|
454
733
|
| (Numeric value, int digits) -> BigDecimal
|
455
734
|
|
735
|
+
# <!--
|
736
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
737
|
+
# - divmod(value)
|
738
|
+
# -->
|
456
739
|
# Divides by the specified value, and returns the quotient and modulus as
|
457
740
|
# BigDecimal numbers. The quotient is rounded towards negative infinity.
|
458
741
|
#
|
@@ -472,10 +755,16 @@ class BigDecimal < Numeric
|
|
472
755
|
# The quotient q is (a/b).floor, and the modulus is the amount that must be
|
473
756
|
# added to q * b to get a.
|
474
757
|
#
|
475
|
-
def divmod: (Numeric) -> [BigDecimal, BigDecimal]
|
758
|
+
def divmod: (Numeric) -> [ BigDecimal, BigDecimal ]
|
476
759
|
|
760
|
+
# <!--
|
761
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
762
|
+
# - dup()
|
763
|
+
# -->
|
764
|
+
#
|
477
765
|
def dup: () -> self
|
478
766
|
|
767
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
479
768
|
# Tests for value equality; returns true if the values are equal.
|
480
769
|
#
|
481
770
|
# The == and === operators and the eql? method have the same implementation for
|
@@ -487,6 +776,10 @@ class BigDecimal < Numeric
|
|
487
776
|
#
|
488
777
|
def eql?: (untyped) -> bool
|
489
778
|
|
779
|
+
# <!--
|
780
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
781
|
+
# - exponent()
|
782
|
+
# -->
|
490
783
|
# Returns the exponent of the BigDecimal number, as an Integer.
|
491
784
|
#
|
492
785
|
# If the number can be represented as 0.xxxxxx*10**n where xxxxxx is a string of
|
@@ -494,14 +787,26 @@ class BigDecimal < Numeric
|
|
494
787
|
#
|
495
788
|
def exponent: () -> Integer
|
496
789
|
|
790
|
+
# <!--
|
791
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
792
|
+
# - finite?()
|
793
|
+
# -->
|
497
794
|
# Returns True if the value is finite (not NaN or infinite).
|
498
795
|
#
|
499
796
|
def finite?: () -> bool
|
500
797
|
|
798
|
+
# <!--
|
799
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
800
|
+
# - fix()
|
801
|
+
# -->
|
501
802
|
# Return the integer part of the number, as a BigDecimal.
|
502
803
|
#
|
503
804
|
def fix: () -> BigDecimal
|
504
805
|
|
806
|
+
# <!--
|
807
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
808
|
+
# - floor(n)
|
809
|
+
# -->
|
505
810
|
# Return the largest integer less than or equal to the value, as a BigDecimal.
|
506
811
|
#
|
507
812
|
# BigDecimal('3.14159').floor #=> 3
|
@@ -519,22 +824,42 @@ class BigDecimal < Numeric
|
|
519
824
|
def floor: () -> Integer
|
520
825
|
| (int n) -> BigDecimal
|
521
826
|
|
827
|
+
# <!--
|
828
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
829
|
+
# - frac()
|
830
|
+
# -->
|
522
831
|
# Return the fractional part of the number, as a BigDecimal.
|
523
832
|
#
|
524
833
|
def frac: () -> BigDecimal
|
525
834
|
|
526
|
-
#
|
835
|
+
# <!--
|
836
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
837
|
+
# - hash -> integer
|
838
|
+
# -->
|
839
|
+
# Returns the integer hash value for `self`.
|
840
|
+
#
|
841
|
+
# Two instances of BigDecimal have the same hash value if and only if they have
|
842
|
+
# equal:
|
527
843
|
#
|
528
|
-
#
|
529
|
-
#
|
844
|
+
# * Sign.
|
845
|
+
# * Fractional part.
|
846
|
+
# * Exponent.
|
530
847
|
#
|
531
848
|
def hash: () -> Integer
|
532
849
|
|
850
|
+
# <!--
|
851
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
852
|
+
# - infinite?()
|
853
|
+
# -->
|
533
854
|
# Returns nil, -1, or +1 depending on whether the value is finite, -Infinity, or
|
534
855
|
# +Infinity.
|
535
856
|
#
|
536
857
|
def infinite?: () -> Integer?
|
537
858
|
|
859
|
+
# <!--
|
860
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
861
|
+
# - inspect()
|
862
|
+
# -->
|
538
863
|
# Returns a string representation of self.
|
539
864
|
#
|
540
865
|
# BigDecimal("1234.5678").inspect
|
@@ -542,33 +867,60 @@ class BigDecimal < Numeric
|
|
542
867
|
#
|
543
868
|
def inspect: () -> String
|
544
869
|
|
870
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
545
871
|
# Returns the modulus from dividing by b.
|
546
872
|
#
|
547
873
|
# See BigDecimal#divmod.
|
548
874
|
#
|
549
875
|
def modulo: (Numeric b) -> BigDecimal
|
550
876
|
|
551
|
-
#
|
877
|
+
# <!--
|
878
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
879
|
+
# - mult(other, ndigits) -> bigdecimal
|
880
|
+
# -->
|
881
|
+
# Returns the BigDecimal product of `self` and `value` with a precision of
|
882
|
+
# `ndigits` decimal digits.
|
552
883
|
#
|
553
|
-
#
|
554
|
-
#
|
555
|
-
#
|
884
|
+
# When `ndigits` is less than the number of significant digits in the sum, the
|
885
|
+
# sum is rounded to that number of digits, according to the current rounding
|
886
|
+
# mode; see BigDecimal.mode.
|
556
887
|
#
|
557
|
-
#
|
558
|
-
#
|
559
|
-
#
|
560
|
-
# BigDecimal.mode
|
888
|
+
# Examples:
|
889
|
+
#
|
890
|
+
# # Set the rounding mode.
|
891
|
+
# BigDecimal.mode(BigDecimal::ROUND_MODE, :half_up)
|
892
|
+
# b = BigDecimal('555555.555')
|
893
|
+
# b.mult(3, 0) # => 0.1666666665e7
|
894
|
+
# b.mult(3, 3) # => 0.167e7
|
895
|
+
# b.mult(3, 6) # => 0.166667e7
|
896
|
+
# b.mult(3, 15) # => 0.1666666665e7
|
897
|
+
# b.mult(3.0, 0) # => 0.1666666665e7
|
898
|
+
# b.mult(Rational(3, 1), 0) # => 0.1666666665e7
|
899
|
+
# b.mult(Complex(3, 0), 0) # => (0.1666666665e7+0.0i)
|
561
900
|
#
|
562
901
|
def mult: (Numeric value, int digits) -> BigDecimal
|
563
902
|
|
903
|
+
# <!--
|
904
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
905
|
+
# - nan?()
|
906
|
+
# -->
|
564
907
|
# Returns True if the value is Not a Number.
|
565
908
|
#
|
566
909
|
def nan?: () -> bool
|
567
910
|
|
911
|
+
# <!--
|
912
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
913
|
+
# - nonzero?()
|
914
|
+
# -->
|
568
915
|
# Returns self if the value is non-zero, nil otherwise.
|
569
916
|
#
|
570
917
|
def nonzero?: () -> self?
|
571
918
|
|
919
|
+
# <!--
|
920
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
921
|
+
# - power(n)
|
922
|
+
# - power(n, prec)
|
923
|
+
# -->
|
572
924
|
# Returns the value raised to the power of n.
|
573
925
|
#
|
574
926
|
# Note that n must be an Integer.
|
@@ -577,28 +929,53 @@ class BigDecimal < Numeric
|
|
577
929
|
#
|
578
930
|
def power: (Numeric n, int prec) -> BigDecimal
|
579
931
|
|
580
|
-
#
|
932
|
+
# <!--
|
933
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
934
|
+
# - precs -> array
|
935
|
+
# -->
|
936
|
+
# Returns an Array of two Integer values that represent platform-dependent
|
937
|
+
# internal storage properties.
|
938
|
+
#
|
939
|
+
# This method is deprecated and will be removed in the future. Instead, use
|
940
|
+
# BigDecimal#n_significant_digits for obtaining the number of significant digits
|
941
|
+
# in scientific notation, and BigDecimal#precision for obtaining the number of
|
942
|
+
# digits in decimal notation.
|
943
|
+
#
|
944
|
+
def precs: () -> [ Integer, Integer ]
|
945
|
+
|
946
|
+
# <!--
|
947
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
948
|
+
# - quo(value) -> bigdecimal
|
949
|
+
# - quo(value, digits) -> bigdecimal
|
950
|
+
# -->
|
951
|
+
# Divide by the specified value.
|
581
952
|
#
|
582
|
-
#
|
583
|
-
#
|
584
|
-
#
|
953
|
+
# digits
|
954
|
+
# : If specified and less than the number of significant digits of the result,
|
955
|
+
# the result is rounded to the given number of digits, according to the
|
956
|
+
# rounding mode indicated by BigDecimal.mode.
|
585
957
|
#
|
586
|
-
#
|
958
|
+
# If digits is 0 or omitted, the result is the same as for the / operator.
|
587
959
|
#
|
588
|
-
def precs: () -> [Integer, Integer]
|
589
|
-
|
590
|
-
# Divide by the specified value.
|
591
960
|
#
|
592
|
-
# See BigDecimal#div.
|
961
|
+
# See BigDecimal#/. See BigDecimal#div.
|
593
962
|
#
|
594
963
|
def quo: (Numeric) -> BigDecimal
|
595
964
|
|
965
|
+
# <!--
|
966
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
967
|
+
# - remainder(value)
|
968
|
+
# -->
|
596
969
|
# Returns the remainder from dividing by the value.
|
597
970
|
#
|
598
971
|
# x.remainder(y) means x-y*(x/y).truncate
|
599
972
|
#
|
600
973
|
def remainder: (Numeric) -> BigDecimal
|
601
974
|
|
975
|
+
# <!--
|
976
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
977
|
+
# - round(n, mode)
|
978
|
+
# -->
|
602
979
|
# Round to the nearest integer (by default), returning the result as a
|
603
980
|
# BigDecimal if n is specified, or as an Integer if it isn't.
|
604
981
|
#
|
@@ -613,10 +990,10 @@ class BigDecimal < Numeric
|
|
613
990
|
# than that many digits.
|
614
991
|
#
|
615
992
|
# If n is specified and negative, at least that many digits to the left of the
|
616
|
-
# decimal point will be 0 in the result.
|
993
|
+
# decimal point will be 0 in the result, and return value will be an Integer.
|
617
994
|
#
|
618
995
|
# BigDecimal('3.14159').round(3) #=> 3.142
|
619
|
-
# BigDecimal('13345.234').round(-2) #=> 13300
|
996
|
+
# BigDecimal('13345.234').round(-2) #=> 13300
|
620
997
|
#
|
621
998
|
# The value of the optional mode argument can be used to determine how rounding
|
622
999
|
# is performed; see BigDecimal.mode.
|
@@ -624,6 +1001,10 @@ class BigDecimal < Numeric
|
|
624
1001
|
def round: () -> Integer
|
625
1002
|
| (Numeric n, ?Integer mode) -> BigDecimal
|
626
1003
|
|
1004
|
+
# <!--
|
1005
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
1006
|
+
# - sign()
|
1007
|
+
# -->
|
627
1008
|
# Returns the sign of the value.
|
628
1009
|
#
|
629
1010
|
# Returns a positive value if > 0, a negative value if < 0, and a zero if == 0.
|
@@ -648,6 +1029,10 @@ class BigDecimal < Numeric
|
|
648
1029
|
#
|
649
1030
|
def sign: () -> Integer
|
650
1031
|
|
1032
|
+
# <!--
|
1033
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
1034
|
+
# - split()
|
1035
|
+
# -->
|
651
1036
|
# Splits a BigDecimal number into four parts, returned as an array of values.
|
652
1037
|
#
|
653
1038
|
# The first value represents the sign of the BigDecimal, and is -1 or 1, or 0 if
|
@@ -672,14 +1057,22 @@ class BigDecimal < Numeric
|
|
672
1057
|
# (Note that the to_f method is provided as a more convenient way to translate a
|
673
1058
|
# BigDecimal to a Float.)
|
674
1059
|
#
|
675
|
-
def split: () -> [Integer, String, Integer, Integer]
|
1060
|
+
def split: () -> [ Integer, String, Integer, Integer ]
|
676
1061
|
|
1062
|
+
# <!--
|
1063
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
1064
|
+
# - sqrt(n)
|
1065
|
+
# -->
|
677
1066
|
# Returns the square root of the value.
|
678
1067
|
#
|
679
1068
|
# Result has at least n significant digits.
|
680
1069
|
#
|
681
1070
|
def sqrt: (int n) -> BigDecimal
|
682
1071
|
|
1072
|
+
# <!--
|
1073
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
1074
|
+
# - sub(value, digits) -> bigdecimal
|
1075
|
+
# -->
|
683
1076
|
# Subtract the specified value.
|
684
1077
|
#
|
685
1078
|
# e.g.
|
@@ -692,28 +1085,45 @@ class BigDecimal < Numeric
|
|
692
1085
|
#
|
693
1086
|
def sub: (Numeric value, int digits) -> BigDecimal
|
694
1087
|
|
1088
|
+
# <!--
|
1089
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
1090
|
+
# - to_f()
|
1091
|
+
# -->
|
695
1092
|
# Returns a new Float object having approximately the same value as the
|
696
1093
|
# BigDecimal number. Normal accuracy limits and built-in errors of binary Float
|
697
1094
|
# arithmetic apply.
|
698
1095
|
#
|
699
1096
|
def to_f: () -> Float
|
700
1097
|
|
1098
|
+
# <!--
|
1099
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
1100
|
+
# - to_i()
|
1101
|
+
# -->
|
701
1102
|
# Returns the value as an Integer.
|
702
1103
|
#
|
703
1104
|
# If the BigDecimal is infinity or NaN, raises FloatDomainError.
|
704
1105
|
#
|
705
1106
|
def to_i: () -> Integer
|
706
1107
|
|
1108
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
707
1109
|
# Returns the value as an Integer.
|
708
1110
|
#
|
709
1111
|
# If the BigDecimal is infinity or NaN, raises FloatDomainError.
|
710
1112
|
#
|
711
1113
|
def to_int: () -> Integer
|
712
1114
|
|
1115
|
+
# <!--
|
1116
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
1117
|
+
# - to_r()
|
1118
|
+
# -->
|
713
1119
|
# Converts a BigDecimal to a Rational.
|
714
1120
|
#
|
715
1121
|
def to_r: () -> Rational
|
716
1122
|
|
1123
|
+
# <!--
|
1124
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
1125
|
+
# - to_s(s)
|
1126
|
+
# -->
|
717
1127
|
# Converts the value to a string.
|
718
1128
|
#
|
719
1129
|
# The default format looks like 0.xxxxEnn.
|
@@ -744,8 +1154,12 @@ class BigDecimal < Numeric
|
|
744
1154
|
# BigDecimal('123.45678901234567890').to_s(' F')
|
745
1155
|
# #=> ' 123.4567890123456789'
|
746
1156
|
#
|
747
|
-
def to_s: (?
|
1157
|
+
def to_s: (?String | int s) -> String
|
748
1158
|
|
1159
|
+
# <!--
|
1160
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
1161
|
+
# - truncate(n)
|
1162
|
+
# -->
|
749
1163
|
# Truncate to the nearest integer (by default), returning the result as a
|
750
1164
|
# BigDecimal.
|
751
1165
|
#
|
@@ -765,6 +1179,10 @@ class BigDecimal < Numeric
|
|
765
1179
|
def truncate: () -> Integer
|
766
1180
|
| (int n) -> BigDecimal
|
767
1181
|
|
1182
|
+
# <!--
|
1183
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
1184
|
+
# - zero?()
|
1185
|
+
# -->
|
768
1186
|
# Returns True if the value is zero.
|
769
1187
|
#
|
770
1188
|
def zero?: () -> bool
|
@@ -774,6 +1192,7 @@ class BigDecimal < Numeric
|
|
774
1192
|
def initialize_copy: (self) -> self
|
775
1193
|
end
|
776
1194
|
|
1195
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
777
1196
|
# Base value used in internal calculations. On a 32 bit system, BASE is 10000,
|
778
1197
|
# indicating that calculation is done in groups of 4 digits. (If it were larger,
|
779
1198
|
# BASE**2 wouldn't fit in 32 bits, so you couldn't guarantee that two groups
|
@@ -781,151 +1200,181 @@ end
|
|
781
1200
|
#
|
782
1201
|
BigDecimal::BASE: Integer
|
783
1202
|
|
1203
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
784
1204
|
# Determines whether overflow, underflow or zero divide result in an exception
|
785
1205
|
# being thrown. See BigDecimal.mode.
|
786
1206
|
#
|
787
1207
|
BigDecimal::EXCEPTION_ALL: Integer
|
788
1208
|
|
1209
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
789
1210
|
# Determines what happens when the result of a computation is infinity. See
|
790
1211
|
# BigDecimal.mode.
|
791
1212
|
#
|
792
1213
|
BigDecimal::EXCEPTION_INFINITY: Integer
|
793
1214
|
|
1215
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
794
1216
|
# Determines what happens when the result of a computation is not a number
|
795
1217
|
# (NaN). See BigDecimal.mode.
|
796
1218
|
#
|
797
1219
|
BigDecimal::EXCEPTION_NaN: Integer
|
798
1220
|
|
1221
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
799
1222
|
# Determines what happens when the result of a computation is an overflow (a
|
800
1223
|
# result too large to be represented). See BigDecimal.mode.
|
801
1224
|
#
|
802
1225
|
BigDecimal::EXCEPTION_OVERFLOW: Integer
|
803
1226
|
|
1227
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
804
1228
|
# Determines what happens when the result of a computation is an underflow (a
|
805
1229
|
# result too small to be represented). See BigDecimal.mode.
|
806
1230
|
#
|
807
1231
|
BigDecimal::EXCEPTION_UNDERFLOW: Integer
|
808
1232
|
|
1233
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
809
1234
|
# Determines what happens when a division by zero is performed. See
|
810
1235
|
# BigDecimal.mode.
|
811
1236
|
#
|
812
1237
|
BigDecimal::EXCEPTION_ZERODIVIDE: Integer
|
813
1238
|
|
814
|
-
#
|
1239
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
1240
|
+
# Special value constants
|
815
1241
|
#
|
816
1242
|
BigDecimal::INFINITY: BigDecimal
|
817
1243
|
|
818
|
-
# 'Not a Number' value.
|
819
|
-
#
|
820
1244
|
BigDecimal::NAN: BigDecimal
|
821
1245
|
|
1246
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
822
1247
|
# Round towards +Infinity. See BigDecimal.mode.
|
823
1248
|
#
|
824
1249
|
BigDecimal::ROUND_CEILING: Integer
|
825
1250
|
|
1251
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
826
1252
|
# Indicates that values should be rounded towards zero. See BigDecimal.mode.
|
827
1253
|
#
|
828
1254
|
BigDecimal::ROUND_DOWN: Integer
|
829
1255
|
|
1256
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
830
1257
|
# Round towards -Infinity. See BigDecimal.mode.
|
831
1258
|
#
|
832
1259
|
BigDecimal::ROUND_FLOOR: Integer
|
833
1260
|
|
1261
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
834
1262
|
# Indicates that digits >= 6 should be rounded up, others rounded down. See
|
835
1263
|
# BigDecimal.mode.
|
836
1264
|
#
|
837
1265
|
BigDecimal::ROUND_HALF_DOWN: Integer
|
838
1266
|
|
1267
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
839
1268
|
# Round towards the even neighbor. See BigDecimal.mode.
|
840
1269
|
#
|
841
1270
|
BigDecimal::ROUND_HALF_EVEN: Integer
|
842
1271
|
|
1272
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
843
1273
|
# Indicates that digits >= 5 should be rounded up, others rounded down. See
|
844
1274
|
# BigDecimal.mode.
|
845
1275
|
#
|
846
1276
|
BigDecimal::ROUND_HALF_UP: Integer
|
847
1277
|
|
1278
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
848
1279
|
# Determines what happens when a result must be rounded in order to fit in the
|
849
1280
|
# appropriate number of significant digits. See BigDecimal.mode.
|
850
1281
|
#
|
851
1282
|
BigDecimal::ROUND_MODE: Integer
|
852
1283
|
|
1284
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
853
1285
|
# Indicates that values should be rounded away from zero. See BigDecimal.mode.
|
854
1286
|
#
|
855
1287
|
BigDecimal::ROUND_UP: Integer
|
856
1288
|
|
1289
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
857
1290
|
# Indicates that a value is negative and finite. See BigDecimal.sign.
|
858
1291
|
#
|
859
1292
|
BigDecimal::SIGN_NEGATIVE_FINITE: Integer
|
860
1293
|
|
1294
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
861
1295
|
# Indicates that a value is negative and infinite. See BigDecimal.sign.
|
862
1296
|
#
|
863
1297
|
BigDecimal::SIGN_NEGATIVE_INFINITE: Integer
|
864
1298
|
|
1299
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
865
1300
|
# Indicates that a value is -0. See BigDecimal.sign.
|
866
1301
|
#
|
867
1302
|
BigDecimal::SIGN_NEGATIVE_ZERO: Integer
|
868
1303
|
|
1304
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
869
1305
|
# Indicates that a value is not a number. See BigDecimal.sign.
|
870
1306
|
#
|
871
1307
|
BigDecimal::SIGN_NaN: Integer
|
872
1308
|
|
1309
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
873
1310
|
# Indicates that a value is positive and finite. See BigDecimal.sign.
|
874
1311
|
#
|
875
1312
|
BigDecimal::SIGN_POSITIVE_FINITE: Integer
|
876
1313
|
|
1314
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
877
1315
|
# Indicates that a value is positive and infinite. See BigDecimal.sign.
|
878
1316
|
#
|
879
1317
|
BigDecimal::SIGN_POSITIVE_INFINITE: Integer
|
880
1318
|
|
1319
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
881
1320
|
# Indicates that a value is +0. See BigDecimal.sign.
|
882
1321
|
#
|
883
1322
|
BigDecimal::SIGN_POSITIVE_ZERO: Integer
|
884
1323
|
|
1324
|
+
# <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
|
885
1325
|
# The version of bigdecimal library
|
886
1326
|
#
|
887
1327
|
BigDecimal::VERSION: String
|
888
1328
|
|
1329
|
+
%a{annotate:rdoc:skip}
|
889
1330
|
module Kernel
|
890
1331
|
private
|
891
1332
|
|
892
|
-
#
|
1333
|
+
# <!--
|
1334
|
+
# rdoc-file=ext/bigdecimal/bigdecimal.c
|
1335
|
+
# - BigDecimal(value, exception: true) -> bigdecimal
|
1336
|
+
# - BigDecimal(value, ndigits, exception: true) -> bigdecimal
|
1337
|
+
# -->
|
1338
|
+
# Returns the \BigDecimal converted from +value+
|
1339
|
+
# with a precision of +ndigits+ decimal digits.
|
893
1340
|
#
|
894
|
-
#
|
895
|
-
#
|
896
|
-
#
|
1341
|
+
# When +ndigits+ is less than the number of significant digits
|
1342
|
+
# in the value, the result is rounded to that number of digits,
|
1343
|
+
# according to the current rounding mode; see BigDecimal.mode.
|
897
1344
|
#
|
898
|
-
#
|
899
|
-
# terminate the value.
|
1345
|
+
# Returns `value` converted to a BigDecimal, depending on the type of `value`:
|
900
1346
|
#
|
901
|
-
#
|
902
|
-
#
|
903
|
-
#
|
1347
|
+
# * Integer, Float, Rational, Complex, or BigDecimal: converted directly:
|
1348
|
+
#
|
1349
|
+
# # Integer, Complex, or BigDecimal value does not require ndigits; ignored if given.
|
1350
|
+
# BigDecimal(2) # => 0.2e1
|
1351
|
+
# BigDecimal(Complex(2, 0)) # => 0.2e1
|
1352
|
+
# BigDecimal(BigDecimal(2)) # => 0.2e1
|
1353
|
+
# # Float or Rational value requires ndigits.
|
1354
|
+
# BigDecimal(2.0, 0) # => 0.2e1
|
1355
|
+
# BigDecimal(Rational(2, 1), 0) # => 0.2e1
|
904
1356
|
#
|
905
|
-
#
|
906
|
-
#
|
1357
|
+
# * String: converted by parsing if it contains an integer or floating-point
|
1358
|
+
# literal; leading and trailing whitespace is ignored:
|
907
1359
|
#
|
908
|
-
#
|
909
|
-
#
|
910
|
-
#
|
1360
|
+
# # String does not require ndigits; ignored if given.
|
1361
|
+
# BigDecimal('2') # => 0.2e1
|
1362
|
+
# BigDecimal('2.0') # => 0.2e1
|
1363
|
+
# BigDecimal('0.2e1') # => 0.2e1
|
1364
|
+
# BigDecimal(' 2.0 ') # => 0.2e1
|
911
1365
|
#
|
1366
|
+
# * Other type that responds to method `:to_str`: first converted to a string,
|
1367
|
+
# then converted to a BigDecimal, as above.
|
912
1368
|
#
|
913
|
-
#
|
1369
|
+
# * Other type:
|
914
1370
|
#
|
915
|
-
#
|
916
|
-
#
|
917
|
-
# this exception is raised.
|
1371
|
+
# * Raises an exception if keyword argument `exception` is `true`.
|
1372
|
+
# * Returns `nil` if keyword argument `exception` is `true`.
|
918
1373
|
#
|
919
|
-
# TypeError
|
920
|
-
# : If the `digits` is not an Integer, this exception is raised.
|
921
1374
|
#
|
922
|
-
# ArgumentError
|
923
|
-
# : If `initial` is a Float, and the `digits` is larger than Float::DIG + 1,
|
924
|
-
# this exception is raised.
|
925
1375
|
#
|
926
|
-
#
|
927
|
-
#
|
928
|
-
# omitted, this exception is raised.
|
1376
|
+
# Raises an exception if `value` evaluates to a Float and `digits` is larger
|
1377
|
+
# than Float::DIG + 1.
|
929
1378
|
#
|
930
|
-
def self?.BigDecimal: (
|
1379
|
+
def self?.BigDecimal: (real | string | BigDecimal initial, ?int digits, ?exception: bool) -> BigDecimal
|
931
1380
|
end
|