rbs 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Rakefile +9 -4
- data/Steepfile +28 -0
- data/bin/steep +4 -0
- data/bin/test_runner.rb +10 -5
- data/lib/rbs/ast/comment.rb +7 -1
- data/lib/rbs/ast/declarations.rb +15 -9
- data/lib/rbs/buffer.rb +1 -1
- data/lib/rbs/definition.rb +22 -13
- data/lib/rbs/definition_builder.rb +79 -55
- data/lib/rbs/environment.rb +24 -10
- data/lib/rbs/location.rb +1 -5
- data/lib/rbs/method_type.rb +5 -5
- data/lib/rbs/namespace.rb +14 -3
- data/lib/rbs/parser.y +0 -8
- data/lib/rbs/prototype/rb.rb +3 -4
- data/lib/rbs/prototype/rbi.rb +1 -2
- data/lib/rbs/substitution.rb +4 -3
- data/lib/rbs/type_name.rb +18 -1
- data/lib/rbs/type_name_resolver.rb +10 -3
- data/lib/rbs/types.rb +27 -21
- data/lib/rbs/variance_calculator.rb +8 -5
- data/lib/rbs/version.rb +1 -1
- data/sig/annotation.rbs +26 -0
- data/sig/buffer.rbs +28 -0
- data/sig/builtin_names.rbs +41 -0
- data/sig/comment.rbs +26 -0
- data/sig/declarations.rbs +202 -0
- data/sig/definition.rbs +129 -0
- data/sig/definition_builder.rbs +95 -0
- data/sig/environment.rbs +94 -0
- data/sig/environment_loader.rbs +4 -0
- data/sig/location.rbs +52 -0
- data/sig/members.rbs +160 -0
- data/sig/method_types.rbs +40 -0
- data/sig/namespace.rbs +124 -0
- data/sig/polyfill.rbs +3 -0
- data/sig/rbs.rbs +3 -0
- data/sig/substitution.rbs +39 -0
- data/sig/type_name_resolver.rbs +24 -0
- data/sig/typename.rbs +70 -0
- data/sig/types.rbs +361 -0
- data/sig/util.rbs +13 -0
- data/sig/variance_calculator.rbs +35 -0
- data/stdlib/bigdecimal/big_decimal.rbs +887 -0
- data/stdlib/bigdecimal/math/big_math.rbs +142 -0
- data/stdlib/builtin/builtin.rbs +0 -3
- data/stdlib/builtin/math.rbs +26 -26
- data/stdlib/builtin/struct.rbs +9 -10
- data/stdlib/forwardable/forwardable.rbs +204 -0
- data/stdlib/set/set.rbs +1 -1
- data/stdlib/uri/file.rbs +167 -0
- data/stdlib/uri/generic.rbs +875 -0
- data/steep/Gemfile +3 -0
- data/steep/Gemfile.lock +55 -0
- metadata +36 -6
data/sig/util.rbs
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module RBS
|
2
|
+
class VarianceCalculator
|
3
|
+
type variance = :unused | :covariant | :contravariant | :invariant
|
4
|
+
|
5
|
+
class Result
|
6
|
+
attr_reader result: Hash[Symbol, variance]
|
7
|
+
|
8
|
+
def initialize: (variables: Array[Symbol]) -> void
|
9
|
+
|
10
|
+
def covariant: (Symbol) -> void
|
11
|
+
|
12
|
+
def contravariant: (Symbol) -> void
|
13
|
+
|
14
|
+
def invariant: (Symbol) -> void
|
15
|
+
|
16
|
+
def each: () { ([Symbol, variance]) -> void } -> void
|
17
|
+
|
18
|
+
def include?: (Symbol) -> bool
|
19
|
+
|
20
|
+
def compatible?: (Symbol, with_annotation: variance) -> bool
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_reader builder: DefinitionBuilder
|
24
|
+
|
25
|
+
def initialize: (builder: DefinitionBuilder) -> void
|
26
|
+
|
27
|
+
def env: () -> Environment
|
28
|
+
|
29
|
+
def in_method_type: (method_type: MethodType, variables: Array[Symbol]) -> Result
|
30
|
+
|
31
|
+
def in_inherit: (name: TypeName, args: Array[Types::t], variables: Array[Symbol]) -> Result
|
32
|
+
|
33
|
+
def type: (Types::t, result: Result, context: variance) -> void
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,887 @@
|
|
1
|
+
# BigDecimal provides arbitrary-precision floating point decimal arithmetic.
|
2
|
+
#
|
3
|
+
# ## Introduction
|
4
|
+
#
|
5
|
+
# Ruby provides built-in support for arbitrary precision integer arithmetic.
|
6
|
+
#
|
7
|
+
# For example:
|
8
|
+
#
|
9
|
+
# 42**13 #=> 1265437718438866624512
|
10
|
+
#
|
11
|
+
# BigDecimal provides similar support for very large or very accurate floating
|
12
|
+
# point numbers.
|
13
|
+
#
|
14
|
+
# Decimal arithmetic is also useful for general calculation, because it provides
|
15
|
+
# the correct answers people expect--whereas normal binary floating point
|
16
|
+
# arithmetic often introduces subtle errors because of the conversion between
|
17
|
+
# base 10 and base 2.
|
18
|
+
#
|
19
|
+
# For example, try:
|
20
|
+
#
|
21
|
+
# sum = 0
|
22
|
+
# 10_000.times do
|
23
|
+
# sum = sum + 0.0001
|
24
|
+
# end
|
25
|
+
# print sum #=> 0.9999999999999062
|
26
|
+
#
|
27
|
+
# and contrast with the output from:
|
28
|
+
#
|
29
|
+
# require 'bigdecimal'
|
30
|
+
#
|
31
|
+
# sum = BigDecimal("0")
|
32
|
+
# 10_000.times do
|
33
|
+
# sum = sum + BigDecimal("0.0001")
|
34
|
+
# end
|
35
|
+
# print sum #=> 0.1E1
|
36
|
+
#
|
37
|
+
# Similarly:
|
38
|
+
#
|
39
|
+
# (BigDecimal("1.2") - BigDecimal("1.0")) == BigDecimal("0.2") #=> true
|
40
|
+
#
|
41
|
+
# (1.2 - 1.0) == 0.2 #=> false
|
42
|
+
#
|
43
|
+
# ## Special features of accurate decimal arithmetic
|
44
|
+
#
|
45
|
+
# Because BigDecimal is more accurate than normal binary floating point
|
46
|
+
# arithmetic, it requires some special values.
|
47
|
+
#
|
48
|
+
# ### Infinity
|
49
|
+
#
|
50
|
+
# BigDecimal sometimes needs to return infinity, for example if you divide a
|
51
|
+
# value by zero.
|
52
|
+
#
|
53
|
+
# BigDecimal("1.0") / BigDecimal("0.0") #=> Infinity
|
54
|
+
# BigDecimal("-1.0") / BigDecimal("0.0") #=> -Infinity
|
55
|
+
#
|
56
|
+
# You can represent infinite numbers to BigDecimal using the strings
|
57
|
+
# `'Infinity'`, `'+Infinity'` and `'-Infinity'` (case-sensitive)
|
58
|
+
#
|
59
|
+
# ### Not a Number
|
60
|
+
#
|
61
|
+
# When a computation results in an undefined value, the special value `NaN` (for
|
62
|
+
# 'not a number') is returned.
|
63
|
+
#
|
64
|
+
# Example:
|
65
|
+
#
|
66
|
+
# BigDecimal("0.0") / BigDecimal("0.0") #=> NaN
|
67
|
+
#
|
68
|
+
# You can also create undefined values.
|
69
|
+
#
|
70
|
+
# NaN is never considered to be the same as any other value, even NaN itself:
|
71
|
+
#
|
72
|
+
# n = BigDecimal('NaN')
|
73
|
+
# n == 0.0 #=> false
|
74
|
+
# n == n #=> false
|
75
|
+
#
|
76
|
+
# ### Positive and negative zero
|
77
|
+
#
|
78
|
+
# If a computation results in a value which is too small to be represented as a
|
79
|
+
# BigDecimal within the currently specified limits of precision, zero must be
|
80
|
+
# returned.
|
81
|
+
#
|
82
|
+
# If the value which is too small to be represented is negative, a BigDecimal
|
83
|
+
# value of negative zero is returned.
|
84
|
+
#
|
85
|
+
# BigDecimal("1.0") / BigDecimal("-Infinity") #=> -0.0
|
86
|
+
#
|
87
|
+
# If the value is positive, a value of positive zero is returned.
|
88
|
+
#
|
89
|
+
# BigDecimal("1.0") / BigDecimal("Infinity") #=> 0.0
|
90
|
+
#
|
91
|
+
# (See BigDecimal.mode for how to specify limits of precision.)
|
92
|
+
#
|
93
|
+
# Note that `-0.0` and `0.0` are considered to be the same for the purposes of
|
94
|
+
# comparison.
|
95
|
+
#
|
96
|
+
# Note also that in mathematics, there is no particular concept of negative or
|
97
|
+
# positive zero; true mathematical zero has no sign.
|
98
|
+
#
|
99
|
+
# ## bigdecimal/util
|
100
|
+
#
|
101
|
+
# When you require `bigdecimal/util`, the #to_d method will be available on
|
102
|
+
# BigDecimal and the native Integer, Float, Rational, and String classes:
|
103
|
+
#
|
104
|
+
# require 'bigdecimal/util'
|
105
|
+
#
|
106
|
+
# 42.to_d # => 0.42e2
|
107
|
+
# 0.5.to_d # => 0.5e0
|
108
|
+
# (2/3r).to_d(3) # => 0.667e0
|
109
|
+
# "0.5".to_d # => 0.5e0
|
110
|
+
#
|
111
|
+
# ## License
|
112
|
+
#
|
113
|
+
# Copyright (C) 2002 by Shigeo Kobayashi <shigeo@tinyforest.gr.jp>.
|
114
|
+
#
|
115
|
+
# BigDecimal is released under the Ruby and 2-clause BSD licenses. See
|
116
|
+
# LICENSE.txt for details.
|
117
|
+
#
|
118
|
+
# Maintained by mrkn <mrkn@mrkn.jp> and ruby-core members.
|
119
|
+
#
|
120
|
+
# Documented by zzak <zachary@zacharyscott.net>, mathew <meta@pobox.com>, and
|
121
|
+
# many other contributors.
|
122
|
+
#
|
123
|
+
class BigDecimal < Numeric
|
124
|
+
# Internal method used to provide marshalling support. See the Marshal module.
|
125
|
+
#
|
126
|
+
def self._load: (String) -> BigDecimal
|
127
|
+
|
128
|
+
# The BigDecimal.double_fig class method returns the number of digits a Float
|
129
|
+
# number is allowed to have. The result depends upon the CPU and OS in use.
|
130
|
+
#
|
131
|
+
def self.double_fig: () -> Integer
|
132
|
+
|
133
|
+
def self.interpret_loosely: (string) -> BigDecimal
|
134
|
+
|
135
|
+
# Limit the number of significant digits in newly created BigDecimal numbers to
|
136
|
+
# the specified value. Rounding is performed as necessary, as specified by
|
137
|
+
# BigDecimal.mode.
|
138
|
+
#
|
139
|
+
# A limit of 0, the default, means no upper limit.
|
140
|
+
#
|
141
|
+
# The limit specified by this method takes less priority over any limit
|
142
|
+
# specified to instance methods such as ceil, floor, truncate, or round.
|
143
|
+
#
|
144
|
+
def self.limit: (?Integer? digits) -> Integer
|
145
|
+
|
146
|
+
# Controls handling of arithmetic exceptions and rounding. If no value is
|
147
|
+
# supplied, the current value is returned.
|
148
|
+
#
|
149
|
+
# Six values of the mode parameter control the handling of arithmetic
|
150
|
+
# exceptions:
|
151
|
+
#
|
152
|
+
# BigDecimal::EXCEPTION_NaN BigDecimal::EXCEPTION_INFINITY
|
153
|
+
# BigDecimal::EXCEPTION_UNDERFLOW BigDecimal::EXCEPTION_OVERFLOW
|
154
|
+
# BigDecimal::EXCEPTION_ZERODIVIDE BigDecimal::EXCEPTION_ALL
|
155
|
+
#
|
156
|
+
# For each mode parameter above, if the value set is false, computation
|
157
|
+
# continues after an arithmetic exception of the appropriate type. When
|
158
|
+
# computation continues, results are as follows:
|
159
|
+
#
|
160
|
+
# EXCEPTION_NaN
|
161
|
+
# : NaN
|
162
|
+
# EXCEPTION_INFINITY
|
163
|
+
# : +Infinity or -Infinity
|
164
|
+
# EXCEPTION_UNDERFLOW
|
165
|
+
# : 0
|
166
|
+
# EXCEPTION_OVERFLOW
|
167
|
+
# : +Infinity or -Infinity
|
168
|
+
# EXCEPTION_ZERODIVIDE
|
169
|
+
# : +Infinity or -Infinity
|
170
|
+
#
|
171
|
+
#
|
172
|
+
# One value of the mode parameter controls the rounding of numeric values:
|
173
|
+
# BigDecimal::ROUND_MODE. The values it can take are:
|
174
|
+
#
|
175
|
+
# ROUND_UP, :up
|
176
|
+
# : round away from zero
|
177
|
+
# ROUND_DOWN, :down, :truncate
|
178
|
+
# : round towards zero (truncate)
|
179
|
+
# ROUND_HALF_UP, :half_up, :default
|
180
|
+
# : round towards the nearest neighbor, unless both neighbors are equidistant,
|
181
|
+
# in which case round away from zero. (default)
|
182
|
+
# ROUND_HALF_DOWN, :half_down
|
183
|
+
# : round towards the nearest neighbor, unless both neighbors are equidistant,
|
184
|
+
# in which case round towards zero.
|
185
|
+
# ROUND_HALF_EVEN, :half_even, :banker
|
186
|
+
# : round towards the nearest neighbor, unless both neighbors are equidistant,
|
187
|
+
# in which case round towards the even neighbor (Banker's rounding)
|
188
|
+
# ROUND_CEILING, :ceiling, :ceil
|
189
|
+
# : round towards positive infinity (ceil)
|
190
|
+
# ROUND_FLOOR, :floor
|
191
|
+
# : round towards negative infinity (floor)
|
192
|
+
#
|
193
|
+
def self.mode: (Integer mode, ?Integer? value) -> Integer?
|
194
|
+
|
195
|
+
# Execute the provided block, but preserve the exception mode
|
196
|
+
#
|
197
|
+
# BigDecimal.save_exception_mode do
|
198
|
+
# BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW, false)
|
199
|
+
# BigDecimal.mode(BigDecimal::EXCEPTION_NaN, false)
|
200
|
+
#
|
201
|
+
# BigDecimal(BigDecimal('Infinity'))
|
202
|
+
# BigDecimal(BigDecimal('-Infinity'))
|
203
|
+
# BigDecimal(BigDecimal('NaN'))
|
204
|
+
# end
|
205
|
+
#
|
206
|
+
# For use with the BigDecimal::EXCEPTION_*
|
207
|
+
#
|
208
|
+
# See BigDecimal.mode
|
209
|
+
#
|
210
|
+
def self.save_exception_mode: () { (?nil) -> void } -> void
|
211
|
+
|
212
|
+
# Execute the provided block, but preserve the precision limit
|
213
|
+
#
|
214
|
+
# BigDecimal.limit(100)
|
215
|
+
# puts BigDecimal.limit
|
216
|
+
# BigDecimal.save_limit do
|
217
|
+
# BigDecimal.limit(200)
|
218
|
+
# puts BigDecimal.limit
|
219
|
+
# end
|
220
|
+
# puts BigDecimal.limit
|
221
|
+
#
|
222
|
+
def self.save_limit: () { (?nil) -> void } -> void
|
223
|
+
|
224
|
+
# Execute the provided block, but preserve the rounding mode
|
225
|
+
#
|
226
|
+
# BigDecimal.save_rounding_mode do
|
227
|
+
# BigDecimal.mode(BigDecimal::ROUND_MODE, :up)
|
228
|
+
# puts BigDecimal.mode(BigDecimal::ROUND_MODE)
|
229
|
+
# end
|
230
|
+
#
|
231
|
+
# For use with the BigDecimal::ROUND_*
|
232
|
+
#
|
233
|
+
# See BigDecimal.mode
|
234
|
+
#
|
235
|
+
def self.save_rounding_mode: () { (?nil) -> void } -> void
|
236
|
+
|
237
|
+
public
|
238
|
+
|
239
|
+
# Returns the modulus from dividing by b.
|
240
|
+
#
|
241
|
+
# See BigDecimal#divmod.
|
242
|
+
#
|
243
|
+
def %: (Numeric) -> BigDecimal
|
244
|
+
|
245
|
+
# Multiply by the specified value.
|
246
|
+
#
|
247
|
+
# e.g.
|
248
|
+
# c = a.mult(b,n)
|
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.
|
255
|
+
#
|
256
|
+
def *: (Numeric) -> BigDecimal
|
257
|
+
|
258
|
+
# Returns the value raised to the power of n.
|
259
|
+
#
|
260
|
+
# See BigDecimal#power.
|
261
|
+
#
|
262
|
+
def **: (Numeric) -> BigDecimal
|
263
|
+
|
264
|
+
# Add the specified value.
|
265
|
+
#
|
266
|
+
# e.g.
|
267
|
+
# c = a.add(b,n)
|
268
|
+
# c = a + b
|
269
|
+
#
|
270
|
+
# digits
|
271
|
+
# : If specified and less than the number of significant digits of the result,
|
272
|
+
# the result is rounded to that number of digits, according to
|
273
|
+
# BigDecimal.mode.
|
274
|
+
#
|
275
|
+
def +: (Numeric) -> BigDecimal
|
276
|
+
|
277
|
+
# Return self.
|
278
|
+
#
|
279
|
+
# +BigDecimal('5') #=> 0.5e1
|
280
|
+
#
|
281
|
+
def +@: () -> BigDecimal
|
282
|
+
|
283
|
+
# Subtract the specified value.
|
284
|
+
#
|
285
|
+
# e.g.
|
286
|
+
# c = a - b
|
287
|
+
#
|
288
|
+
# The precision of the result value depends on the type of `b`.
|
289
|
+
#
|
290
|
+
# If `b` is a Float, the precision of the result is Float::DIG+1.
|
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.
|
295
|
+
#
|
296
|
+
def -: (Numeric) -> BigDecimal
|
297
|
+
|
298
|
+
# Return the negation of self.
|
299
|
+
#
|
300
|
+
# -BigDecimal('5') #=> -0.5e1
|
301
|
+
#
|
302
|
+
def -@: () -> BigDecimal
|
303
|
+
|
304
|
+
# Divide by the specified value.
|
305
|
+
#
|
306
|
+
# See BigDecimal#div.
|
307
|
+
#
|
308
|
+
def /: (Numeric) -> BigDecimal
|
309
|
+
|
310
|
+
# Returns true if a is less than b.
|
311
|
+
#
|
312
|
+
# Values may be coerced to perform the comparison (see ==, BigDecimal#coerce).
|
313
|
+
#
|
314
|
+
def <: (Numeric) -> bool
|
315
|
+
|
316
|
+
# Returns true if a is less than or equal to b.
|
317
|
+
#
|
318
|
+
# Values may be coerced to perform the comparison (see ==, BigDecimal#coerce).
|
319
|
+
#
|
320
|
+
def <=: (Numeric) -> bool
|
321
|
+
|
322
|
+
# The comparison operator. a <=> b is 0 if a == b, 1 if a > b, -1 if a < b.
|
323
|
+
#
|
324
|
+
def <=>: (Numeric) -> Integer?
|
325
|
+
|
326
|
+
# Tests for value equality; returns true if the values are equal.
|
327
|
+
#
|
328
|
+
# The == and === operators and the eql? method have the same implementation for
|
329
|
+
# BigDecimal.
|
330
|
+
#
|
331
|
+
# Values may be coerced to perform the comparison:
|
332
|
+
#
|
333
|
+
# BigDecimal('1.0') == 1.0 #=> true
|
334
|
+
#
|
335
|
+
def ==: (untyped) -> bool
|
336
|
+
|
337
|
+
# Tests for value equality; returns true if the values are equal.
|
338
|
+
#
|
339
|
+
# The == and === operators and the eql? method have the same implementation for
|
340
|
+
# BigDecimal.
|
341
|
+
#
|
342
|
+
# Values may be coerced to perform the comparison:
|
343
|
+
#
|
344
|
+
# BigDecimal('1.0') == 1.0 #=> true
|
345
|
+
#
|
346
|
+
def ===: (untyped) -> bool
|
347
|
+
|
348
|
+
# Returns true if a is greater than b.
|
349
|
+
#
|
350
|
+
# Values may be coerced to perform the comparison (see ==, BigDecimal#coerce).
|
351
|
+
#
|
352
|
+
def >: (Numeric) -> bool
|
353
|
+
|
354
|
+
# Returns true if a is greater than or equal to b.
|
355
|
+
#
|
356
|
+
# Values may be coerced to perform the comparison (see ==, BigDecimal#coerce)
|
357
|
+
#
|
358
|
+
def >=: (Numeric) -> bool
|
359
|
+
|
360
|
+
# Method used to provide marshalling support.
|
361
|
+
#
|
362
|
+
# inf = BigDecimal('Infinity')
|
363
|
+
# #=> Infinity
|
364
|
+
# BigDecimal._load(inf._dump)
|
365
|
+
# #=> Infinity
|
366
|
+
#
|
367
|
+
# See the Marshal module.
|
368
|
+
#
|
369
|
+
def _dump: (?untyped) -> String
|
370
|
+
|
371
|
+
# Returns the absolute value, as a BigDecimal.
|
372
|
+
#
|
373
|
+
# BigDecimal('5').abs #=> 0.5e1
|
374
|
+
# BigDecimal('-3').abs #=> 0.3e1
|
375
|
+
#
|
376
|
+
def abs: () -> BigDecimal
|
377
|
+
|
378
|
+
# Add the specified value.
|
379
|
+
#
|
380
|
+
# e.g.
|
381
|
+
# c = a.add(b,n)
|
382
|
+
# c = a + b
|
383
|
+
#
|
384
|
+
# digits
|
385
|
+
# : If specified and less than the number of significant digits of the result,
|
386
|
+
# the result is rounded to that number of digits, according to
|
387
|
+
# BigDecimal.mode.
|
388
|
+
#
|
389
|
+
def add: (Numeric value, Integer digits) -> BigDecimal
|
390
|
+
|
391
|
+
# Return the smallest integer greater than or equal to the value, as a
|
392
|
+
# BigDecimal.
|
393
|
+
#
|
394
|
+
# BigDecimal('3.14159').ceil #=> 4
|
395
|
+
# BigDecimal('-9.1').ceil #=> -9
|
396
|
+
#
|
397
|
+
# If n is specified and positive, the fractional part of the result has no more
|
398
|
+
# than that many digits.
|
399
|
+
#
|
400
|
+
# If n is specified and negative, at least that many digits to the left of the
|
401
|
+
# decimal point will be 0 in the result.
|
402
|
+
#
|
403
|
+
# BigDecimal('3.14159').ceil(3) #=> 3.142
|
404
|
+
# BigDecimal('13345.234').ceil(-2) #=> 13400.0
|
405
|
+
#
|
406
|
+
def ceil: () -> Integer
|
407
|
+
| (int n) -> BigDecimal
|
408
|
+
|
409
|
+
def clone: () -> self
|
410
|
+
|
411
|
+
# The coerce method provides support for Ruby type coercion. It is not enabled
|
412
|
+
# by default.
|
413
|
+
#
|
414
|
+
# This means that binary operations like + * / or - can often be performed on a
|
415
|
+
# BigDecimal and an object of another type, if the other object can be coerced
|
416
|
+
# into a BigDecimal value.
|
417
|
+
#
|
418
|
+
# e.g.
|
419
|
+
# a = BigDecimal("1.0")
|
420
|
+
# b = a / 2.0 #=> 0.5
|
421
|
+
#
|
422
|
+
# Note that coercing a String to a BigDecimal is not supported by default; it
|
423
|
+
# requires a special compile-time option when building Ruby.
|
424
|
+
#
|
425
|
+
def coerce: (Numeric) -> [BigDecimal, BigDecimal]
|
426
|
+
|
427
|
+
# Divide by the specified value.
|
428
|
+
#
|
429
|
+
# digits
|
430
|
+
# : If specified and less than the number of significant digits of the result,
|
431
|
+
# the result is rounded to that number of digits, according to
|
432
|
+
# BigDecimal.mode.
|
433
|
+
#
|
434
|
+
# If digits is 0, the result is the same as for the / operator or #quo.
|
435
|
+
#
|
436
|
+
# If digits is not specified, the result is an integer, by analogy with
|
437
|
+
# Float#div; see also BigDecimal#divmod.
|
438
|
+
#
|
439
|
+
#
|
440
|
+
# Examples:
|
441
|
+
#
|
442
|
+
# a = BigDecimal("4")
|
443
|
+
# b = BigDecimal("3")
|
444
|
+
#
|
445
|
+
# a.div(b, 3) # => 0.133e1
|
446
|
+
#
|
447
|
+
# a.div(b, 0) # => 0.1333333333333333333e1
|
448
|
+
# a / b # => 0.1333333333333333333e1
|
449
|
+
# a.quo(b) # => 0.1333333333333333333e1
|
450
|
+
#
|
451
|
+
# a.div(b) # => 1
|
452
|
+
#
|
453
|
+
def div: (Numeric value) -> Integer
|
454
|
+
| (Numeric value, int digits) -> BigDecimal
|
455
|
+
|
456
|
+
# Divides by the specified value, and returns the quotient and modulus as
|
457
|
+
# BigDecimal numbers. The quotient is rounded towards negative infinity.
|
458
|
+
#
|
459
|
+
# For example:
|
460
|
+
#
|
461
|
+
# require 'bigdecimal'
|
462
|
+
#
|
463
|
+
# a = BigDecimal("42")
|
464
|
+
# b = BigDecimal("9")
|
465
|
+
#
|
466
|
+
# q, m = a.divmod(b)
|
467
|
+
#
|
468
|
+
# c = q * b + m
|
469
|
+
#
|
470
|
+
# a == c #=> true
|
471
|
+
#
|
472
|
+
# The quotient q is (a/b).floor, and the modulus is the amount that must be
|
473
|
+
# added to q * b to get a.
|
474
|
+
#
|
475
|
+
def divmod: (Numeric) -> [BigDecimal, BigDecimal]
|
476
|
+
|
477
|
+
def dup: () -> self
|
478
|
+
|
479
|
+
# Tests for value equality; returns true if the values are equal.
|
480
|
+
#
|
481
|
+
# The == and === operators and the eql? method have the same implementation for
|
482
|
+
# BigDecimal.
|
483
|
+
#
|
484
|
+
# Values may be coerced to perform the comparison:
|
485
|
+
#
|
486
|
+
# BigDecimal('1.0') == 1.0 #=> true
|
487
|
+
#
|
488
|
+
def eql?: (untyped) -> bool
|
489
|
+
|
490
|
+
# Returns the exponent of the BigDecimal number, as an Integer.
|
491
|
+
#
|
492
|
+
# If the number can be represented as 0.xxxxxx*10**n where xxxxxx is a string of
|
493
|
+
# digits with no leading zeros, then n is the exponent.
|
494
|
+
#
|
495
|
+
def exponent: () -> Integer
|
496
|
+
|
497
|
+
# Returns True if the value is finite (not NaN or infinite).
|
498
|
+
#
|
499
|
+
def finite?: () -> bool
|
500
|
+
|
501
|
+
# Return the integer part of the number, as a BigDecimal.
|
502
|
+
#
|
503
|
+
def fix: () -> BigDecimal
|
504
|
+
|
505
|
+
# Return the largest integer less than or equal to the value, as a BigDecimal.
|
506
|
+
#
|
507
|
+
# BigDecimal('3.14159').floor #=> 3
|
508
|
+
# BigDecimal('-9.1').floor #=> -10
|
509
|
+
#
|
510
|
+
# If n is specified and positive, the fractional part of the result has no more
|
511
|
+
# than that many digits.
|
512
|
+
#
|
513
|
+
# If n is specified and negative, at least that many digits to the left of the
|
514
|
+
# decimal point will be 0 in the result.
|
515
|
+
#
|
516
|
+
# BigDecimal('3.14159').floor(3) #=> 3.141
|
517
|
+
# BigDecimal('13345.234').floor(-2) #=> 13300.0
|
518
|
+
#
|
519
|
+
def floor: () -> Integer
|
520
|
+
| (int n) -> BigDecimal
|
521
|
+
|
522
|
+
# Return the fractional part of the number, as a BigDecimal.
|
523
|
+
#
|
524
|
+
def frac: () -> BigDecimal
|
525
|
+
|
526
|
+
# Creates a hash for this BigDecimal.
|
527
|
+
#
|
528
|
+
# Two BigDecimals with equal sign, fractional part and exponent have the same
|
529
|
+
# hash.
|
530
|
+
#
|
531
|
+
def hash: () -> Integer
|
532
|
+
|
533
|
+
# Returns nil, -1, or +1 depending on whether the value is finite, -Infinity, or
|
534
|
+
# +Infinity.
|
535
|
+
#
|
536
|
+
def infinite?: () -> Integer?
|
537
|
+
|
538
|
+
# Returns a string representation of self.
|
539
|
+
#
|
540
|
+
# BigDecimal("1234.5678").inspect
|
541
|
+
# #=> "0.12345678e4"
|
542
|
+
#
|
543
|
+
def inspect: () -> String
|
544
|
+
|
545
|
+
# Returns the modulus from dividing by b.
|
546
|
+
#
|
547
|
+
# See BigDecimal#divmod.
|
548
|
+
#
|
549
|
+
def modulo: (Numeric b) -> BigDecimal
|
550
|
+
|
551
|
+
# Multiply by the specified value.
|
552
|
+
#
|
553
|
+
# e.g.
|
554
|
+
# c = a.mult(b,n)
|
555
|
+
# c = a * b
|
556
|
+
#
|
557
|
+
# digits
|
558
|
+
# : If specified and less than the number of significant digits of the result,
|
559
|
+
# the result is rounded to that number of digits, according to
|
560
|
+
# BigDecimal.mode.
|
561
|
+
#
|
562
|
+
def mult: (Numeric value, int digits) -> BigDecimal
|
563
|
+
|
564
|
+
# Returns True if the value is Not a Number.
|
565
|
+
#
|
566
|
+
def nan?: () -> bool
|
567
|
+
|
568
|
+
# Returns self if the value is non-zero, nil otherwise.
|
569
|
+
#
|
570
|
+
def nonzero?: () -> self?
|
571
|
+
|
572
|
+
# Returns the value raised to the power of n.
|
573
|
+
#
|
574
|
+
# Note that n must be an Integer.
|
575
|
+
#
|
576
|
+
# Also available as the operator **.
|
577
|
+
#
|
578
|
+
def power: (Numeric n, int prec) -> BigDecimal
|
579
|
+
|
580
|
+
# Returns an Array of two Integer values.
|
581
|
+
#
|
582
|
+
# The first value is the current number of significant digits in the BigDecimal.
|
583
|
+
# The second value is the maximum number of significant digits for the
|
584
|
+
# BigDecimal.
|
585
|
+
#
|
586
|
+
# BigDecimal('5').precs #=> [9, 18]
|
587
|
+
#
|
588
|
+
def precs: () -> [Integer, Integer]
|
589
|
+
|
590
|
+
# Divide by the specified value.
|
591
|
+
#
|
592
|
+
# See BigDecimal#div.
|
593
|
+
#
|
594
|
+
def quo: (Numeric) -> BigDecimal
|
595
|
+
|
596
|
+
# Returns the remainder from dividing by the value.
|
597
|
+
#
|
598
|
+
# x.remainder(y) means x-y*(x/y).truncate
|
599
|
+
#
|
600
|
+
def remainder: (Numeric) -> BigDecimal
|
601
|
+
|
602
|
+
# Round to the nearest integer (by default), returning the result as a
|
603
|
+
# BigDecimal if n is specified, or as an Integer if it isn't.
|
604
|
+
#
|
605
|
+
# BigDecimal('3.14159').round #=> 3
|
606
|
+
# BigDecimal('8.7').round #=> 9
|
607
|
+
# BigDecimal('-9.9').round #=> -10
|
608
|
+
#
|
609
|
+
# BigDecimal('3.14159').round(2).class.name #=> "BigDecimal"
|
610
|
+
# BigDecimal('3.14159').round.class.name #=> "Integer"
|
611
|
+
#
|
612
|
+
# If n is specified and positive, the fractional part of the result has no more
|
613
|
+
# than that many digits.
|
614
|
+
#
|
615
|
+
# 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.
|
617
|
+
#
|
618
|
+
# BigDecimal('3.14159').round(3) #=> 3.142
|
619
|
+
# BigDecimal('13345.234').round(-2) #=> 13300.0
|
620
|
+
#
|
621
|
+
# The value of the optional mode argument can be used to determine how rounding
|
622
|
+
# is performed; see BigDecimal.mode.
|
623
|
+
#
|
624
|
+
def round: () -> Integer
|
625
|
+
| (Numeric n, ?Integer mode) -> BigDecimal
|
626
|
+
|
627
|
+
# Returns the sign of the value.
|
628
|
+
#
|
629
|
+
# Returns a positive value if > 0, a negative value if < 0, and a zero if == 0.
|
630
|
+
#
|
631
|
+
# The specific value returned indicates the type and sign of the BigDecimal, as
|
632
|
+
# follows:
|
633
|
+
#
|
634
|
+
# BigDecimal::SIGN_NaN
|
635
|
+
# : value is Not a Number
|
636
|
+
# BigDecimal::SIGN_POSITIVE_ZERO
|
637
|
+
# : value is +0
|
638
|
+
# BigDecimal::SIGN_NEGATIVE_ZERO
|
639
|
+
# : value is -0
|
640
|
+
# BigDecimal::SIGN_POSITIVE_INFINITE
|
641
|
+
# : value is +Infinity
|
642
|
+
# BigDecimal::SIGN_NEGATIVE_INFINITE
|
643
|
+
# : value is -Infinity
|
644
|
+
# BigDecimal::SIGN_POSITIVE_FINITE
|
645
|
+
# : value is positive
|
646
|
+
# BigDecimal::SIGN_NEGATIVE_FINITE
|
647
|
+
# : value is negative
|
648
|
+
#
|
649
|
+
def sign: () -> Integer
|
650
|
+
|
651
|
+
# Splits a BigDecimal number into four parts, returned as an array of values.
|
652
|
+
#
|
653
|
+
# The first value represents the sign of the BigDecimal, and is -1 or 1, or 0 if
|
654
|
+
# the BigDecimal is Not a Number.
|
655
|
+
#
|
656
|
+
# The second value is a string representing the significant digits of the
|
657
|
+
# BigDecimal, with no leading zeros.
|
658
|
+
#
|
659
|
+
# The third value is the base used for arithmetic (currently always 10) as an
|
660
|
+
# Integer.
|
661
|
+
#
|
662
|
+
# The fourth value is an Integer exponent.
|
663
|
+
#
|
664
|
+
# If the BigDecimal can be represented as 0.xxxxxx*10**n, then xxxxxx is the
|
665
|
+
# string of significant digits with no leading zeros, and n is the exponent.
|
666
|
+
#
|
667
|
+
# From these values, you can translate a BigDecimal to a float as follows:
|
668
|
+
#
|
669
|
+
# sign, significant_digits, base, exponent = a.split
|
670
|
+
# f = sign * "0.#{significant_digits}".to_f * (base ** exponent)
|
671
|
+
#
|
672
|
+
# (Note that the to_f method is provided as a more convenient way to translate a
|
673
|
+
# BigDecimal to a Float.)
|
674
|
+
#
|
675
|
+
def split: () -> [Integer, String, Integer, Integer]
|
676
|
+
|
677
|
+
# Returns the square root of the value.
|
678
|
+
#
|
679
|
+
# Result has at least n significant digits.
|
680
|
+
#
|
681
|
+
def sqrt: (int n) -> BigDecimal
|
682
|
+
|
683
|
+
# Subtract the specified value.
|
684
|
+
#
|
685
|
+
# e.g.
|
686
|
+
# c = a.sub(b,n)
|
687
|
+
#
|
688
|
+
# digits
|
689
|
+
# : If specified and less than the number of significant digits of the result,
|
690
|
+
# the result is rounded to that number of digits, according to
|
691
|
+
# BigDecimal.mode.
|
692
|
+
#
|
693
|
+
def sub: (Numeric value, int digits) -> BigDecimal
|
694
|
+
|
695
|
+
# Returns a new Float object having approximately the same value as the
|
696
|
+
# BigDecimal number. Normal accuracy limits and built-in errors of binary Float
|
697
|
+
# arithmetic apply.
|
698
|
+
#
|
699
|
+
def to_f: () -> Float
|
700
|
+
|
701
|
+
# Returns the value as an Integer.
|
702
|
+
#
|
703
|
+
# If the BigDecimal is infinity or NaN, raises FloatDomainError.
|
704
|
+
#
|
705
|
+
def to_i: () -> Integer
|
706
|
+
|
707
|
+
# Returns the value as an Integer.
|
708
|
+
#
|
709
|
+
# If the BigDecimal is infinity or NaN, raises FloatDomainError.
|
710
|
+
#
|
711
|
+
def to_int: () -> Integer
|
712
|
+
|
713
|
+
# Converts a BigDecimal to a Rational.
|
714
|
+
#
|
715
|
+
def to_r: () -> Rational
|
716
|
+
|
717
|
+
# Converts the value to a string.
|
718
|
+
#
|
719
|
+
# The default format looks like 0.xxxxEnn.
|
720
|
+
#
|
721
|
+
# The optional parameter s consists of either an integer; or an optional '+' or
|
722
|
+
# ' ', followed by an optional number, followed by an optional 'E' or 'F'.
|
723
|
+
#
|
724
|
+
# If there is a '+' at the start of s, positive values are returned with a
|
725
|
+
# leading '+'.
|
726
|
+
#
|
727
|
+
# A space at the start of s returns positive values with a leading space.
|
728
|
+
#
|
729
|
+
# If s contains a number, a space is inserted after each group of that many
|
730
|
+
# fractional digits.
|
731
|
+
#
|
732
|
+
# If s ends with an 'E', engineering notation (0.xxxxEnn) is used.
|
733
|
+
#
|
734
|
+
# If s ends with an 'F', conventional floating point notation is used.
|
735
|
+
#
|
736
|
+
# Examples:
|
737
|
+
#
|
738
|
+
# BigDecimal('-123.45678901234567890').to_s('5F')
|
739
|
+
# #=> '-123.45678 90123 45678 9'
|
740
|
+
#
|
741
|
+
# BigDecimal('123.45678901234567890').to_s('+8F')
|
742
|
+
# #=> '+123.45678901 23456789'
|
743
|
+
#
|
744
|
+
# BigDecimal('123.45678901234567890').to_s(' F')
|
745
|
+
# #=> ' 123.4567890123456789'
|
746
|
+
#
|
747
|
+
def to_s: (?(String | int) s) -> String
|
748
|
+
|
749
|
+
# Truncate to the nearest integer (by default), returning the result as a
|
750
|
+
# BigDecimal.
|
751
|
+
#
|
752
|
+
# BigDecimal('3.14159').truncate #=> 3
|
753
|
+
# BigDecimal('8.7').truncate #=> 8
|
754
|
+
# BigDecimal('-9.9').truncate #=> -9
|
755
|
+
#
|
756
|
+
# If n is specified and positive, the fractional part of the result has no more
|
757
|
+
# than that many digits.
|
758
|
+
#
|
759
|
+
# If n is specified and negative, at least that many digits to the left of the
|
760
|
+
# decimal point will be 0 in the result.
|
761
|
+
#
|
762
|
+
# BigDecimal('3.14159').truncate(3) #=> 3.141
|
763
|
+
# BigDecimal('13345.234').truncate(-2) #=> 13300.0
|
764
|
+
#
|
765
|
+
def truncate: () -> Integer
|
766
|
+
| (int n) -> BigDecimal
|
767
|
+
|
768
|
+
# Returns True if the value is zero.
|
769
|
+
#
|
770
|
+
def zero?: () -> bool
|
771
|
+
|
772
|
+
private
|
773
|
+
|
774
|
+
def initialize_copy: (self) -> self
|
775
|
+
end
|
776
|
+
|
777
|
+
# Base value used in internal calculations. On a 32 bit system, BASE is 10000,
|
778
|
+
# indicating that calculation is done in groups of 4 digits. (If it were larger,
|
779
|
+
# BASE**2 wouldn't fit in 32 bits, so you couldn't guarantee that two groups
|
780
|
+
# could always be multiplied together without overflow.)
|
781
|
+
#
|
782
|
+
BigDecimal::BASE: Integer
|
783
|
+
|
784
|
+
# Determines whether overflow, underflow or zero divide result in an exception
|
785
|
+
# being thrown. See BigDecimal.mode.
|
786
|
+
#
|
787
|
+
BigDecimal::EXCEPTION_ALL: Integer
|
788
|
+
|
789
|
+
# Determines what happens when the result of a computation is infinity. See
|
790
|
+
# BigDecimal.mode.
|
791
|
+
#
|
792
|
+
BigDecimal::EXCEPTION_INFINITY: Integer
|
793
|
+
|
794
|
+
# Determines what happens when the result of a computation is not a number
|
795
|
+
# (NaN). See BigDecimal.mode.
|
796
|
+
#
|
797
|
+
BigDecimal::EXCEPTION_NaN: Integer
|
798
|
+
|
799
|
+
# Determines what happens when the result of a computation is an overflow (a
|
800
|
+
# result too large to be represented). See BigDecimal.mode.
|
801
|
+
#
|
802
|
+
BigDecimal::EXCEPTION_OVERFLOW: Integer
|
803
|
+
|
804
|
+
# Determines what happens when the result of a computation is an underflow (a
|
805
|
+
# result too small to be represented). See BigDecimal.mode.
|
806
|
+
#
|
807
|
+
BigDecimal::EXCEPTION_UNDERFLOW: Integer
|
808
|
+
|
809
|
+
# Determines what happens when a division by zero is performed. See
|
810
|
+
# BigDecimal.mode.
|
811
|
+
#
|
812
|
+
BigDecimal::EXCEPTION_ZERODIVIDE: Integer
|
813
|
+
|
814
|
+
# Positive infinity value.
|
815
|
+
#
|
816
|
+
BigDecimal::INFINITY: BigDecimal
|
817
|
+
|
818
|
+
# 'Not a Number' value.
|
819
|
+
#
|
820
|
+
BigDecimal::NAN: BigDecimal
|
821
|
+
|
822
|
+
# Round towards +Infinity. See BigDecimal.mode.
|
823
|
+
#
|
824
|
+
BigDecimal::ROUND_CEILING: Integer
|
825
|
+
|
826
|
+
# Indicates that values should be rounded towards zero. See BigDecimal.mode.
|
827
|
+
#
|
828
|
+
BigDecimal::ROUND_DOWN: Integer
|
829
|
+
|
830
|
+
# Round towards -Infinity. See BigDecimal.mode.
|
831
|
+
#
|
832
|
+
BigDecimal::ROUND_FLOOR: Integer
|
833
|
+
|
834
|
+
# Indicates that digits >= 6 should be rounded up, others rounded down. See
|
835
|
+
# BigDecimal.mode.
|
836
|
+
#
|
837
|
+
BigDecimal::ROUND_HALF_DOWN: Integer
|
838
|
+
|
839
|
+
# Round towards the even neighbor. See BigDecimal.mode.
|
840
|
+
#
|
841
|
+
BigDecimal::ROUND_HALF_EVEN: Integer
|
842
|
+
|
843
|
+
# Indicates that digits >= 5 should be rounded up, others rounded down. See
|
844
|
+
# BigDecimal.mode.
|
845
|
+
#
|
846
|
+
BigDecimal::ROUND_HALF_UP: Integer
|
847
|
+
|
848
|
+
# Determines what happens when a result must be rounded in order to fit in the
|
849
|
+
# appropriate number of significant digits. See BigDecimal.mode.
|
850
|
+
#
|
851
|
+
BigDecimal::ROUND_MODE: Integer
|
852
|
+
|
853
|
+
# Indicates that values should be rounded away from zero. See BigDecimal.mode.
|
854
|
+
#
|
855
|
+
BigDecimal::ROUND_UP: Integer
|
856
|
+
|
857
|
+
# Indicates that a value is negative and finite. See BigDecimal.sign.
|
858
|
+
#
|
859
|
+
BigDecimal::SIGN_NEGATIVE_FINITE: Integer
|
860
|
+
|
861
|
+
# Indicates that a value is negative and infinite. See BigDecimal.sign.
|
862
|
+
#
|
863
|
+
BigDecimal::SIGN_NEGATIVE_INFINITE: Integer
|
864
|
+
|
865
|
+
# Indicates that a value is -0. See BigDecimal.sign.
|
866
|
+
#
|
867
|
+
BigDecimal::SIGN_NEGATIVE_ZERO: Integer
|
868
|
+
|
869
|
+
# Indicates that a value is not a number. See BigDecimal.sign.
|
870
|
+
#
|
871
|
+
BigDecimal::SIGN_NaN: Integer
|
872
|
+
|
873
|
+
# Indicates that a value is positive and finite. See BigDecimal.sign.
|
874
|
+
#
|
875
|
+
BigDecimal::SIGN_POSITIVE_FINITE: Integer
|
876
|
+
|
877
|
+
# Indicates that a value is positive and infinite. See BigDecimal.sign.
|
878
|
+
#
|
879
|
+
BigDecimal::SIGN_POSITIVE_INFINITE: Integer
|
880
|
+
|
881
|
+
# Indicates that a value is +0. See BigDecimal.sign.
|
882
|
+
#
|
883
|
+
BigDecimal::SIGN_POSITIVE_ZERO: Integer
|
884
|
+
|
885
|
+
# The version of bigdecimal library
|
886
|
+
#
|
887
|
+
BigDecimal::VERSION: String
|