bigdecimal 4.0.1-java → 4.1.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1502 @@
1
+ class BigDecimal < Numeric
2
+ # BigDecimal::ROUND_MODE
3
+ type round_mode = 256
4
+ type round_mode_integer = 1 | 2 | 3 | 4 | 5 | 6 | 7
5
+ type round_mode_symbol = :up | :down | :half_up | :half_down | :half_even | :ceiling | :floor | :truncate | :banker | :default
6
+
7
+ # <!--
8
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
9
+ # - _load(p1)
10
+ # -->
11
+ # Internal method used to provide marshalling support. See the Marshal module.
12
+ #
13
+ def self._load: (String) -> BigDecimal
14
+
15
+ # <!--
16
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
17
+ # - BigDecimal.double_fig -> integer
18
+ # -->
19
+ # Returns the number of digits a Float object is allowed to have; the result is
20
+ # system-dependent:
21
+ #
22
+ # BigDecimal.double_fig # => 16
23
+ #
24
+ def self.double_fig: () -> Integer
25
+
26
+ # <!--
27
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
28
+ # - interpret_loosely(p1)
29
+ # -->
30
+ #
31
+ def self.interpret_loosely: (string) -> BigDecimal
32
+
33
+ # <!--
34
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
35
+ # - BigDecimal.limit(digits)
36
+ # -->
37
+ # Limit the number of significant digits in newly created BigDecimal numbers to
38
+ # the specified value. Rounding is performed as necessary, as specified by
39
+ # BigDecimal.mode.
40
+ #
41
+ # A limit of 0, the default, means no upper limit.
42
+ #
43
+ # The limit specified by this method takes less priority over any limit
44
+ # specified to instance methods such as ceil, floor, truncate, or round.
45
+ #
46
+ def self.limit: (?Integer? digits) -> Integer
47
+
48
+ # <!--
49
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
50
+ # - BigDecimal.mode(mode, setting = nil) -> integer
51
+ # -->
52
+ # Returns an integer representing the mode settings for exception handling and
53
+ # rounding.
54
+ #
55
+ # These modes control exception handling:
56
+ #
57
+ # * BigDecimal::EXCEPTION_NaN.
58
+ # * BigDecimal::EXCEPTION_INFINITY.
59
+ # * BigDecimal::EXCEPTION_UNDERFLOW.
60
+ # * BigDecimal::EXCEPTION_OVERFLOW.
61
+ # * BigDecimal::EXCEPTION_ZERODIVIDE.
62
+ # * BigDecimal::EXCEPTION_ALL.
63
+ #
64
+ # Values for `setting` for exception handling:
65
+ #
66
+ # * `true`: sets the given `mode` to `true`.
67
+ # * `false`: sets the given `mode` to `false`.
68
+ # * `nil`: does not modify the mode settings.
69
+ #
70
+ # You can use method BigDecimal.save_exception_mode to temporarily change, and
71
+ # then automatically restore, exception modes.
72
+ #
73
+ # For clarity, some examples below begin by setting all exception modes to
74
+ # `false`.
75
+ #
76
+ # This mode controls the way rounding is to be performed:
77
+ #
78
+ # * BigDecimal::ROUND_MODE
79
+ #
80
+ # You can use method BigDecimal.save_rounding_mode to temporarily change, and
81
+ # then automatically restore, the rounding mode.
82
+ #
83
+ # **NaNs**
84
+ #
85
+ # Mode BigDecimal::EXCEPTION_NaN controls behavior when a BigDecimal NaN is
86
+ # created.
87
+ #
88
+ # Settings:
89
+ #
90
+ # * `false` (default): Returns `BigDecimal('NaN')`.
91
+ # * `true`: Raises FloatDomainError.
92
+ #
93
+ # Examples:
94
+ #
95
+ # BigDecimal.mode(BigDecimal::EXCEPTION_ALL, false) # => 0
96
+ # BigDecimal('NaN') # => NaN
97
+ # BigDecimal.mode(BigDecimal::EXCEPTION_NaN, true) # => 2
98
+ # BigDecimal('NaN') # Raises FloatDomainError
99
+ #
100
+ # **Infinities**
101
+ #
102
+ # Mode BigDecimal::EXCEPTION_INFINITY controls behavior when a BigDecimal
103
+ # Infinity or -Infinity is created. Settings:
104
+ #
105
+ # * `false` (default): Returns `BigDecimal('Infinity')` or
106
+ # `BigDecimal('-Infinity')`.
107
+ # * `true`: Raises FloatDomainError.
108
+ #
109
+ # Examples:
110
+ #
111
+ # BigDecimal.mode(BigDecimal::EXCEPTION_ALL, false) # => 0
112
+ # BigDecimal('Infinity') # => Infinity
113
+ # BigDecimal('-Infinity') # => -Infinity
114
+ # BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY, true) # => 1
115
+ # BigDecimal('Infinity') # Raises FloatDomainError
116
+ # BigDecimal('-Infinity') # Raises FloatDomainError
117
+ #
118
+ # **Underflow**
119
+ #
120
+ # Mode BigDecimal::EXCEPTION_UNDERFLOW controls behavior when a BigDecimal
121
+ # underflow occurs. Settings:
122
+ #
123
+ # * `false` (default): Returns `BigDecimal('0')` or `BigDecimal('-Infinity')`.
124
+ # * `true`: Raises FloatDomainError.
125
+ #
126
+ # Examples:
127
+ #
128
+ # BigDecimal.mode(BigDecimal::EXCEPTION_ALL, false) # => 0
129
+ # def flow_under
130
+ # x = BigDecimal('0.1')
131
+ # 100.times { x *= x }
132
+ # end
133
+ # flow_under # => 100
134
+ # BigDecimal.mode(BigDecimal::EXCEPTION_UNDERFLOW, true) # => 4
135
+ # flow_under # Raises FloatDomainError
136
+ #
137
+ # **Overflow**
138
+ #
139
+ # Mode BigDecimal::EXCEPTION_OVERFLOW controls behavior when a BigDecimal
140
+ # overflow occurs. Settings:
141
+ #
142
+ # * `false` (default): Returns `BigDecimal('Infinity')` or
143
+ # `BigDecimal('-Infinity')`.
144
+ # * `true`: Raises FloatDomainError.
145
+ #
146
+ # Examples:
147
+ #
148
+ # BigDecimal.mode(BigDecimal::EXCEPTION_ALL, false) # => 0
149
+ # def flow_over
150
+ # x = BigDecimal('10')
151
+ # 100.times { x *= x }
152
+ # end
153
+ # flow_over # => 100
154
+ # BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW, true) # => 1
155
+ # flow_over # Raises FloatDomainError
156
+ #
157
+ # **Zero Division**
158
+ #
159
+ # Mode BigDecimal::EXCEPTION_ZERODIVIDE controls behavior when a zero-division
160
+ # occurs. Settings:
161
+ #
162
+ # * `false` (default): Returns `BigDecimal('Infinity')` or
163
+ # `BigDecimal('-Infinity')`.
164
+ # * `true`: Raises FloatDomainError.
165
+ #
166
+ # Examples:
167
+ #
168
+ # BigDecimal.mode(BigDecimal::EXCEPTION_ALL, false) # => 0
169
+ # one = BigDecimal('1')
170
+ # zero = BigDecimal('0')
171
+ # one / zero # => Infinity
172
+ # BigDecimal.mode(BigDecimal::EXCEPTION_ZERODIVIDE, true) # => 16
173
+ # one / zero # Raises FloatDomainError
174
+ #
175
+ # **All Exceptions**
176
+ #
177
+ # Mode BigDecimal::EXCEPTION_ALL controls all of the above:
178
+ #
179
+ # BigDecimal.mode(BigDecimal::EXCEPTION_ALL, false) # => 0
180
+ # BigDecimal.mode(BigDecimal::EXCEPTION_ALL, true) # => 23
181
+ #
182
+ # **Rounding**
183
+ #
184
+ # Mode BigDecimal::ROUND_MODE controls the way rounding is to be performed; its
185
+ # `setting` values are:
186
+ #
187
+ # * `ROUND_UP`: Round away from zero. Aliased as `:up`.
188
+ # * `ROUND_DOWN`: Round toward zero. Aliased as `:down` and `:truncate`.
189
+ # * `ROUND_HALF_UP`: Round toward the nearest neighbor; if the neighbors are
190
+ # equidistant, round away from zero. Aliased as `:half_up` and `:default`.
191
+ # * `ROUND_HALF_DOWN`: Round toward the nearest neighbor; if the neighbors are
192
+ # equidistant, round toward zero. Aliased as `:half_down`.
193
+ # * `ROUND_HALF_EVEN` (Banker's rounding): Round toward the nearest neighbor;
194
+ # if the neighbors are equidistant, round toward the even neighbor. Aliased
195
+ # as `:half_even` and `:banker`.
196
+ # * `ROUND_CEILING`: Round toward positive infinity. Aliased as `:ceiling` and
197
+ # `:ceil`.
198
+ # * `ROUND_FLOOR`: Round toward negative infinity. Aliased as `:floor:`.
199
+ #
200
+ def self.mode: (round_mode, ?(round_mode_integer | round_mode_symbol)) -> Integer
201
+ | (Integer exception_mode, ?bool? setting) -> Integer
202
+
203
+ # <!--
204
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
205
+ # - BigDecimal.save_exception_mode { ... }
206
+ # -->
207
+ # Execute the provided block, but preserve the exception mode
208
+ #
209
+ # BigDecimal.save_exception_mode do
210
+ # BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW, false)
211
+ # BigDecimal.mode(BigDecimal::EXCEPTION_NaN, false)
212
+ #
213
+ # BigDecimal(BigDecimal('Infinity'))
214
+ # BigDecimal(BigDecimal('-Infinity'))
215
+ # BigDecimal(BigDecimal('NaN'))
216
+ # end
217
+ #
218
+ # For use with the BigDecimal::EXCEPTION_*
219
+ #
220
+ # See BigDecimal.mode
221
+ #
222
+ def self.save_exception_mode: () { (?nil) -> void } -> void
223
+
224
+ # <!--
225
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
226
+ # - BigDecimal.save_limit { ... }
227
+ # -->
228
+ # Execute the provided block, but preserve the precision limit
229
+ #
230
+ # BigDecimal.limit(100)
231
+ # puts BigDecimal.limit
232
+ # BigDecimal.save_limit do
233
+ # BigDecimal.limit(200)
234
+ # puts BigDecimal.limit
235
+ # end
236
+ # puts BigDecimal.limit
237
+ #
238
+ def self.save_limit: () { (?nil) -> void } -> void
239
+
240
+ # <!--
241
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
242
+ # - BigDecimal.save_rounding_mode { ... }
243
+ # -->
244
+ # Execute the provided block, but preserve the rounding mode
245
+ #
246
+ # BigDecimal.save_rounding_mode do
247
+ # BigDecimal.mode(BigDecimal::ROUND_MODE, :up)
248
+ # puts BigDecimal.mode(BigDecimal::ROUND_MODE)
249
+ # end
250
+ #
251
+ # For use with the BigDecimal::ROUND_*
252
+ #
253
+ # See BigDecimal.mode
254
+ #
255
+ def self.save_rounding_mode: () { (?nil) -> void } -> void
256
+
257
+ # <!--
258
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
259
+ # - a % b
260
+ # - a.modulo(b)
261
+ # -->
262
+ # Returns the modulus from dividing by b.
263
+ #
264
+ # See BigDecimal#divmod.
265
+ #
266
+ def %: (real | BigDecimal) -> BigDecimal
267
+
268
+ # <!--
269
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
270
+ # - *(p1)
271
+ # -->
272
+ #
273
+ def *: (real | BigDecimal) -> BigDecimal
274
+ | (Complex) -> Complex
275
+
276
+ # <!--
277
+ # rdoc-file=lib/bigdecimal.rb
278
+ # - self ** other -> bigdecimal
279
+ # -->
280
+ # Returns the BigDecimal value of `self` raised to power `other`:
281
+ #
282
+ # b = BigDecimal('3.14')
283
+ # b ** 2 # => 0.98596e1
284
+ # b ** 2.0 # => 0.98596e1
285
+ # b ** Rational(2, 1) # => 0.98596e1
286
+ #
287
+ # Related: BigDecimal#power.
288
+ #
289
+ def **: (real | BigDecimal) -> BigDecimal
290
+ | (Complex) -> Complex
291
+
292
+ # <!--
293
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
294
+ # - self + value -> bigdecimal
295
+ # -->
296
+ # Returns the BigDecimal sum of `self` and `value`:
297
+ #
298
+ # b = BigDecimal('111111.111') # => 0.111111111e6
299
+ # b + 2 # => 0.111113111e6
300
+ # b + 2.0 # => 0.111113111e6
301
+ # b + Rational(2, 1) # => 0.111113111e6
302
+ # b + Complex(2, 0) # => (0.111113111e6+0i)
303
+ #
304
+ # See the [Note About
305
+ # Precision](BigDecimal.html#class-BigDecimal-label-A+Note+About+Precision).
306
+ #
307
+ def +: (real | BigDecimal) -> BigDecimal
308
+ | (Complex) -> Complex
309
+
310
+ # <!--
311
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
312
+ # - +big_decimal -> self
313
+ # -->
314
+ # Returns `self`:
315
+ #
316
+ # +BigDecimal(5) # => 0.5e1
317
+ # +BigDecimal(-5) # => -0.5e1
318
+ #
319
+ def +@: () -> BigDecimal
320
+
321
+ # <!--
322
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
323
+ # - self - value -> bigdecimal
324
+ # -->
325
+ # Returns the BigDecimal difference of `self` and `value`:
326
+ #
327
+ # b = BigDecimal('333333.333') # => 0.333333333e6
328
+ # b - 2 # => 0.333331333e6
329
+ # b - 2.0 # => 0.333331333e6
330
+ # b - Rational(2, 1) # => 0.333331333e6
331
+ # b - Complex(2, 0) # => (0.333331333e6+0i)
332
+ #
333
+ # See the [Note About
334
+ # Precision](BigDecimal.html#class-BigDecimal-label-A+Note+About+Precision).
335
+ #
336
+ def -: (real | BigDecimal) -> BigDecimal
337
+ | (Complex) -> Complex
338
+
339
+ # <!--
340
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
341
+ # - -self -> bigdecimal
342
+ # -->
343
+ # Returns the BigDecimal negation of self:
344
+ #
345
+ # b0 = BigDecimal('1.5')
346
+ # b1 = -b0 # => -0.15e1
347
+ # b2 = -b1 # => 0.15e1
348
+ #
349
+ def -@: () -> BigDecimal
350
+
351
+ # <!--
352
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
353
+ # - a / b -> bigdecimal
354
+ # -->
355
+ # Divide by the specified value.
356
+ #
357
+ # The result precision will be the precision of the larger operand, but its
358
+ # minimum is 2*Float::DIG.
359
+ #
360
+ # See BigDecimal#div. See BigDecimal#quo.
361
+ #
362
+ def /: (real | BigDecimal) -> BigDecimal
363
+ | (Complex) -> Complex
364
+
365
+ # <!--
366
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
367
+ # - self < other -> true or false
368
+ # -->
369
+ # Returns `true` if `self` is less than `other`, `false` otherwise:
370
+ #
371
+ # b = BigDecimal('1.5') # => 0.15e1
372
+ # b < 2 # => true
373
+ # b < 2.0 # => true
374
+ # b < Rational(2, 1) # => true
375
+ # b < 1.5 # => false
376
+ #
377
+ # Raises an exception if the comparison cannot be made.
378
+ #
379
+ def <: (real | BigDecimal) -> bool
380
+
381
+ # <!--
382
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
383
+ # - self <= other -> true or false
384
+ # -->
385
+ # Returns `true` if `self` is less or equal to than `other`, `false` otherwise:
386
+ #
387
+ # b = BigDecimal('1.5') # => 0.15e1
388
+ # b <= 2 # => true
389
+ # b <= 2.0 # => true
390
+ # b <= Rational(2, 1) # => true
391
+ # b <= 1.5 # => true
392
+ # b < 1 # => false
393
+ #
394
+ # Raises an exception if the comparison cannot be made.
395
+ #
396
+ def <=: (real | BigDecimal) -> bool
397
+
398
+ # <!--
399
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
400
+ # - <=>(p1)
401
+ # -->
402
+ # The comparison operator. a <=> b is 0 if a == b, 1 if a > b, -1 if a < b.
403
+ #
404
+ def <=>: (untyped) -> Integer?
405
+
406
+ # <!--
407
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
408
+ # - ==(p1)
409
+ # -->
410
+ # Tests for value equality; returns true if the values are equal.
411
+ #
412
+ # The == and === operators and the eql? method have the same implementation for
413
+ # BigDecimal.
414
+ #
415
+ # Values may be coerced to perform the comparison:
416
+ #
417
+ # BigDecimal('1.0') == 1.0 #=> true
418
+ #
419
+ def ==: (untyped) -> bool
420
+
421
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
422
+ # Tests for value equality; returns true if the values are equal.
423
+ #
424
+ # The == and === operators and the eql? method have the same implementation for
425
+ # BigDecimal.
426
+ #
427
+ # Values may be coerced to perform the comparison:
428
+ #
429
+ # BigDecimal('1.0') == 1.0 #=> true
430
+ #
431
+ def ===: (untyped) -> bool
432
+
433
+ # <!--
434
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
435
+ # - self > other -> true or false
436
+ # -->
437
+ # Returns `true` if `self` is greater than `other`, `false` otherwise:
438
+ #
439
+ # b = BigDecimal('1.5')
440
+ # b > 1 # => true
441
+ # b > 1.0 # => true
442
+ # b > Rational(1, 1) # => true
443
+ # b > 2 # => false
444
+ #
445
+ # Raises an exception if the comparison cannot be made.
446
+ #
447
+ def >: (real | BigDecimal) -> bool
448
+
449
+ # <!--
450
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
451
+ # - self >= other -> true or false
452
+ # -->
453
+ # Returns `true` if `self` is greater than or equal to `other`, `false`
454
+ # otherwise:
455
+ #
456
+ # b = BigDecimal('1.5')
457
+ # b >= 1 # => true
458
+ # b >= 1.0 # => true
459
+ # b >= Rational(1, 1) # => true
460
+ # b >= 1.5 # => true
461
+ # b > 2 # => false
462
+ #
463
+ # Raises an exception if the comparison cannot be made.
464
+ #
465
+ def >=: (real | BigDecimal) -> bool
466
+
467
+ # <!--
468
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
469
+ # - _dump -> string
470
+ # -->
471
+ # Returns a string representing the marshalling of `self`. See module Marshal.
472
+ #
473
+ # inf = BigDecimal('Infinity') # => Infinity
474
+ # dumped = inf._dump # => "9:Infinity"
475
+ # BigDecimal._load(dumped) # => Infinity
476
+ #
477
+ def _dump: (?untyped) -> String
478
+
479
+ # <!--
480
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
481
+ # - abs -> bigdecimal
482
+ # -->
483
+ # Returns the BigDecimal absolute value of `self`:
484
+ #
485
+ # BigDecimal('5').abs # => 0.5e1
486
+ # BigDecimal('-3').abs # => 0.3e1
487
+ #
488
+ def abs: () -> BigDecimal
489
+
490
+ # <!--
491
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
492
+ # - add(value, ndigits) -> new_bigdecimal
493
+ # -->
494
+ # Returns the BigDecimal sum of `self` and `value` with a precision of `ndigits`
495
+ # decimal digits.
496
+ #
497
+ # When `ndigits` is less than the number of significant digits in the sum, the
498
+ # sum is rounded to that number of digits, according to the current rounding
499
+ # mode; see BigDecimal.mode.
500
+ #
501
+ # Examples:
502
+ #
503
+ # # Set the rounding mode.
504
+ # BigDecimal.mode(BigDecimal::ROUND_MODE, :half_up)
505
+ # b = BigDecimal('111111.111')
506
+ # b.add(1, 0) # => 0.111112111e6
507
+ # b.add(1, 3) # => 0.111e6
508
+ # b.add(1, 6) # => 0.111112e6
509
+ # b.add(1, 15) # => 0.111112111e6
510
+ # b.add(1.0, 15) # => 0.111112111e6
511
+ # b.add(Rational(1, 1), 15) # => 0.111112111e6
512
+ #
513
+ def add: (real | BigDecimal value, Integer digits) -> BigDecimal
514
+
515
+ # <!--
516
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
517
+ # - ceil(n)
518
+ # -->
519
+ # Return the smallest integer greater than or equal to the value, as a
520
+ # BigDecimal.
521
+ #
522
+ # BigDecimal('3.14159').ceil #=> 4
523
+ # BigDecimal('-9.1').ceil #=> -9
524
+ #
525
+ # If n is specified and positive, the fractional part of the result has no more
526
+ # than that many digits.
527
+ #
528
+ # If n is specified and negative, at least that many digits to the left of the
529
+ # decimal point will be 0 in the result.
530
+ #
531
+ # BigDecimal('3.14159').ceil(3) #=> 3.142
532
+ # BigDecimal('13345.234').ceil(-2) #=> 13400.0
533
+ #
534
+ def ceil: () -> Integer
535
+ | (int n) -> BigDecimal
536
+
537
+ # <!--
538
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
539
+ # - clone()
540
+ # -->
541
+ #
542
+ def clone: () -> self
543
+
544
+ # <!--
545
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
546
+ # - coerce(p1)
547
+ # -->
548
+ # The coerce method provides support for Ruby type coercion. It is not enabled
549
+ # by default.
550
+ #
551
+ # This means that binary operations like + * / or - can often be performed on a
552
+ # BigDecimal and an object of another type, if the other object can be coerced
553
+ # into a BigDecimal value.
554
+ #
555
+ # e.g.
556
+ # a = BigDecimal("1.0")
557
+ # b = a / 2.0 #=> 0.5
558
+ #
559
+ # Note that coercing a String to a BigDecimal is not supported by default; it
560
+ # requires a special compile-time option when building Ruby.
561
+ #
562
+ def coerce: (Numeric) -> [ BigDecimal, BigDecimal ]
563
+
564
+ # <!--
565
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
566
+ # - div(value) -> integer
567
+ # - div(value, digits) -> bigdecimal or integer
568
+ # -->
569
+ # Divide by the specified value.
570
+ #
571
+ # digits
572
+ # : If specified and less than the number of significant digits of the result,
573
+ # the result is rounded to that number of digits, according to
574
+ # BigDecimal.mode.
575
+ #
576
+ # If digits is 0, the result is the same as for the / operator or #quo.
577
+ #
578
+ # If digits is not specified, the result is an integer, by analogy with
579
+ # Float#div; see also BigDecimal#divmod.
580
+ #
581
+ #
582
+ # See BigDecimal#/. See BigDecimal#quo.
583
+ #
584
+ # Examples:
585
+ #
586
+ # a = BigDecimal("4")
587
+ # b = BigDecimal("3")
588
+ #
589
+ # a.div(b, 3) # => 0.133e1
590
+ #
591
+ # a.div(b, 0) # => 0.1333333333333333333e1
592
+ # a / b # => 0.1333333333333333333e1
593
+ # a.quo(b) # => 0.1333333333333333333e1
594
+ #
595
+ # a.div(b) # => 1
596
+ #
597
+ def div: (real | BigDecimal value) -> Integer
598
+ | (real | BigDecimal value, int digits) -> BigDecimal
599
+
600
+ # <!--
601
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
602
+ # - divmod(value)
603
+ # -->
604
+ # Divides by the specified value, and returns the quotient and modulus as
605
+ # BigDecimal numbers. The quotient is rounded towards negative infinity.
606
+ #
607
+ # For example:
608
+ #
609
+ # require 'bigdecimal'
610
+ #
611
+ # a = BigDecimal("42")
612
+ # b = BigDecimal("9")
613
+ #
614
+ # q, m = a.divmod(b)
615
+ #
616
+ # c = q * b + m
617
+ #
618
+ # a == c #=> true
619
+ #
620
+ # The quotient q is (a/b).floor, and the modulus is the amount that must be
621
+ # added to q * b to get a.
622
+ #
623
+ def divmod: (real | BigDecimal) -> [ Integer, BigDecimal ]
624
+
625
+ # <!--
626
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
627
+ # - dup()
628
+ # -->
629
+ #
630
+ def dup: () -> self
631
+
632
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
633
+ # Tests for value equality; returns true if the values are equal.
634
+ #
635
+ # The == and === operators and the eql? method have the same implementation for
636
+ # BigDecimal.
637
+ #
638
+ # Values may be coerced to perform the comparison:
639
+ #
640
+ # BigDecimal('1.0') == 1.0 #=> true
641
+ #
642
+ def eql?: (untyped) -> bool
643
+
644
+ # <!--
645
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
646
+ # - exponent()
647
+ # -->
648
+ # Returns the exponent of the BigDecimal number, as an Integer.
649
+ #
650
+ # If the number can be represented as 0.xxxxxx*10**n where xxxxxx is a string of
651
+ # digits with no leading zeros, then n is the exponent.
652
+ #
653
+ def exponent: () -> Integer
654
+
655
+ # <!--
656
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
657
+ # - finite?()
658
+ # -->
659
+ # Returns True if the value is finite (not NaN or infinite).
660
+ #
661
+ def finite?: () -> bool
662
+
663
+ # <!--
664
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
665
+ # - fix()
666
+ # -->
667
+ # Return the integer part of the number, as a BigDecimal.
668
+ #
669
+ def fix: () -> BigDecimal
670
+
671
+ # <!--
672
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
673
+ # - floor(n)
674
+ # -->
675
+ # Return the largest integer less than or equal to the value, as a BigDecimal.
676
+ #
677
+ # BigDecimal('3.14159').floor #=> 3
678
+ # BigDecimal('-9.1').floor #=> -10
679
+ #
680
+ # If n is specified and positive, the fractional part of the result has no more
681
+ # than that many digits.
682
+ #
683
+ # If n is specified and negative, at least that many digits to the left of the
684
+ # decimal point will be 0 in the result.
685
+ #
686
+ # BigDecimal('3.14159').floor(3) #=> 3.141
687
+ # BigDecimal('13345.234').floor(-2) #=> 13300.0
688
+ #
689
+ def floor: () -> Integer
690
+ | (int n) -> BigDecimal
691
+
692
+ # <!--
693
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
694
+ # - frac()
695
+ # -->
696
+ # Return the fractional part of the number, as a BigDecimal.
697
+ #
698
+ def frac: () -> BigDecimal
699
+
700
+ # <!--
701
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
702
+ # - hash -> integer
703
+ # -->
704
+ # Returns the integer hash value for `self`.
705
+ #
706
+ # Two instances of BigDecimal have the same hash value if and only if they have
707
+ # equal:
708
+ #
709
+ # * Sign.
710
+ # * Fractional part.
711
+ # * Exponent.
712
+ #
713
+ def hash: () -> Integer
714
+
715
+ # <!--
716
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
717
+ # - infinite?()
718
+ # -->
719
+ # Returns nil, -1, or +1 depending on whether the value is finite, -Infinity, or
720
+ # +Infinity.
721
+ #
722
+ def infinite?: () -> Integer?
723
+
724
+ # <!--
725
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
726
+ # - inspect()
727
+ # -->
728
+ # Returns a string representation of self.
729
+ #
730
+ # BigDecimal("1234.5678").inspect
731
+ # #=> "0.12345678e4"
732
+ #
733
+ def inspect: () -> String
734
+
735
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
736
+ # Returns the modulus from dividing by b.
737
+ #
738
+ # See BigDecimal#divmod.
739
+ #
740
+ def modulo: (real | BigDecimal b) -> BigDecimal
741
+
742
+ # <!--
743
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
744
+ # - mult(other, ndigits) -> bigdecimal
745
+ # -->
746
+ # Returns the BigDecimal product of `self` and `value` with a precision of
747
+ # `ndigits` decimal digits.
748
+ #
749
+ # When `ndigits` is less than the number of significant digits in the sum, the
750
+ # sum is rounded to that number of digits, according to the current rounding
751
+ # mode; see BigDecimal.mode.
752
+ #
753
+ # Examples:
754
+ #
755
+ # # Set the rounding mode.
756
+ # BigDecimal.mode(BigDecimal::ROUND_MODE, :half_up)
757
+ # b = BigDecimal('555555.555')
758
+ # b.mult(3, 0) # => 0.1666666665e7
759
+ # b.mult(3, 3) # => 0.167e7
760
+ # b.mult(3, 6) # => 0.166667e7
761
+ # b.mult(3, 15) # => 0.1666666665e7
762
+ # b.mult(3.0, 0) # => 0.1666666665e7
763
+ # b.mult(Rational(3, 1), 0) # => 0.1666666665e7
764
+ # b.mult(Complex(3, 0), 0) # => (0.1666666665e7+0.0i)
765
+ #
766
+ def mult: (real | BigDecimal value, int digits) -> BigDecimal
767
+
768
+ # <!--
769
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
770
+ # - nan?()
771
+ # -->
772
+ # Returns True if the value is Not a Number.
773
+ #
774
+ def nan?: () -> bool
775
+
776
+ # <!--
777
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
778
+ # - nonzero?()
779
+ # -->
780
+ # Returns self if the value is non-zero, nil otherwise.
781
+ #
782
+ def nonzero?: () -> self?
783
+
784
+ # <!--
785
+ # rdoc-file=lib/bigdecimal.rb
786
+ # - power(n)
787
+ # - power(n, prec)
788
+ # -->
789
+ # Returns the value raised to the power of n.
790
+ #
791
+ # Also available as the operator **.
792
+ #
793
+ def power: (real | BigDecimal n, ?int prec) -> BigDecimal
794
+
795
+ # <!--
796
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
797
+ # - quo(value) -> bigdecimal
798
+ # - quo(value, digits) -> bigdecimal
799
+ # -->
800
+ # Divide by the specified value.
801
+ #
802
+ # digits
803
+ # : If specified and less than the number of significant digits of the result,
804
+ # the result is rounded to the given number of digits, according to the
805
+ # rounding mode indicated by BigDecimal.mode.
806
+ #
807
+ # If digits is 0 or omitted, the result is the same as for the / operator.
808
+ #
809
+ #
810
+ # See BigDecimal#/. See BigDecimal#div.
811
+ #
812
+ def quo: (real | BigDecimal) -> BigDecimal
813
+ | (Complex) -> Complex
814
+
815
+ # <!--
816
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
817
+ # - remainder(value)
818
+ # -->
819
+ # Returns the remainder from dividing by the value.
820
+ #
821
+ # x.remainder(y) means x-y*(x/y).truncate
822
+ #
823
+ def remainder: (real | BigDecimal) -> BigDecimal
824
+
825
+ # <!--
826
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
827
+ # - round(n, mode)
828
+ # -->
829
+ # Round to the nearest integer (by default), returning the result as a
830
+ # BigDecimal if n is specified, or as an Integer if it isn't.
831
+ #
832
+ # BigDecimal('3.14159').round #=> 3
833
+ # BigDecimal('8.7').round #=> 9
834
+ # BigDecimal('-9.9').round #=> -10
835
+ #
836
+ # BigDecimal('3.14159').round(2).class.name #=> "BigDecimal"
837
+ # BigDecimal('3.14159').round.class.name #=> "Integer"
838
+ #
839
+ # If n is specified and positive, the fractional part of the result has no more
840
+ # than that many digits.
841
+ #
842
+ # If n is specified and negative, at least that many digits to the left of the
843
+ # decimal point will be 0 in the result, and return value will be an Integer.
844
+ #
845
+ # BigDecimal('3.14159').round(3) #=> 3.142
846
+ # BigDecimal('13345.234').round(-2) #=> 13300
847
+ #
848
+ # The value of the optional mode argument can be used to determine how rounding
849
+ # is performed; see BigDecimal.mode.
850
+ #
851
+ def round: () -> Integer
852
+ | (int n) -> (Integer | BigDecimal)
853
+ | (int n, round_mode_integer | round_mode_symbol) -> BigDecimal
854
+ | (?int n, half: :up | :down | :even) -> BigDecimal
855
+
856
+ # <!--
857
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
858
+ # - sign()
859
+ # -->
860
+ # Returns the sign of the value.
861
+ #
862
+ # Returns a positive value if > 0, a negative value if < 0. It behaves the same
863
+ # with zeros - it returns a positive value for a positive zero (BigDecimal('0'))
864
+ # and a negative value for a negative zero (BigDecimal('-0')).
865
+ #
866
+ # The specific value returned indicates the type and sign of the BigDecimal, as
867
+ # follows:
868
+ #
869
+ # BigDecimal::SIGN_NaN
870
+ # : value is Not a Number
871
+ #
872
+ # BigDecimal::SIGN_POSITIVE_ZERO
873
+ # : value is +0
874
+ #
875
+ # BigDecimal::SIGN_NEGATIVE_ZERO
876
+ # : value is -0
877
+ #
878
+ # BigDecimal::SIGN_POSITIVE_INFINITE
879
+ # : value is +Infinity
880
+ #
881
+ # BigDecimal::SIGN_NEGATIVE_INFINITE
882
+ # : value is -Infinity
883
+ #
884
+ # BigDecimal::SIGN_POSITIVE_FINITE
885
+ # : value is positive
886
+ #
887
+ # BigDecimal::SIGN_NEGATIVE_FINITE
888
+ # : value is negative
889
+ #
890
+ def sign: () -> Integer
891
+
892
+ # <!--
893
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
894
+ # - split()
895
+ # -->
896
+ # Splits a BigDecimal number into four parts, returned as an array of values.
897
+ #
898
+ # The first value represents the sign of the BigDecimal, and is -1 or 1, or 0 if
899
+ # the BigDecimal is Not a Number.
900
+ #
901
+ # The second value is a string representing the significant digits of the
902
+ # BigDecimal, with no leading zeros.
903
+ #
904
+ # The third value is the base used for arithmetic (currently always 10) as an
905
+ # Integer.
906
+ #
907
+ # The fourth value is an Integer exponent.
908
+ #
909
+ # If the BigDecimal can be represented as 0.xxxxxx*10**n, then xxxxxx is the
910
+ # string of significant digits with no leading zeros, and n is the exponent.
911
+ #
912
+ # From these values, you can translate a BigDecimal to a float as follows:
913
+ #
914
+ # sign, significant_digits, base, exponent = a.split
915
+ # f = sign * "0.#{significant_digits}".to_f * (base ** exponent)
916
+ #
917
+ # (Note that the to_f method is provided as a more convenient way to translate a
918
+ # BigDecimal to a Float.)
919
+ #
920
+ def split: () -> [ Integer, String, Integer, Integer ]
921
+
922
+ # <!--
923
+ # rdoc-file=lib/bigdecimal.rb
924
+ # - sqrt(prec)
925
+ # -->
926
+ # Returns the square root of the value.
927
+ #
928
+ # Result has at least prec significant digits.
929
+ #
930
+ def sqrt: (int n) -> BigDecimal
931
+
932
+ # <!--
933
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
934
+ # - sub(value, digits) -> bigdecimal
935
+ # -->
936
+ # Subtract the specified value.
937
+ #
938
+ # e.g.
939
+ # c = a.sub(b,n)
940
+ #
941
+ # digits
942
+ # : If specified and less than the number of significant digits of the result,
943
+ # the result is rounded to that number of digits, according to
944
+ # BigDecimal.mode.
945
+ #
946
+ def sub: (real | BigDecimal value, int digits) -> BigDecimal
947
+
948
+ # <!--
949
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
950
+ # - to_f()
951
+ # -->
952
+ # Returns a new Float object having approximately the same value as the
953
+ # BigDecimal number. Normal accuracy limits and built-in errors of binary Float
954
+ # arithmetic apply.
955
+ #
956
+ def to_f: () -> Float
957
+
958
+ # <!--
959
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
960
+ # - to_i()
961
+ # -->
962
+ # Returns the value as an Integer.
963
+ #
964
+ # If the BigDecimal is infinity or NaN, raises FloatDomainError.
965
+ #
966
+ def to_i: () -> Integer
967
+
968
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
969
+ # Returns the value as an Integer.
970
+ #
971
+ # If the BigDecimal is infinity or NaN, raises FloatDomainError.
972
+ #
973
+ def to_int: () -> Integer
974
+
975
+ # <!--
976
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
977
+ # - to_r()
978
+ # -->
979
+ # Converts a BigDecimal to a Rational.
980
+ #
981
+ def to_r: () -> Rational
982
+
983
+ # <!--
984
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
985
+ # - to_s(s)
986
+ # -->
987
+ # Converts the value to a string.
988
+ #
989
+ # The default format looks like 0.xxxxEnn.
990
+ #
991
+ # The optional parameter s consists of either an integer; or an optional '+' or
992
+ # ' ', followed by an optional number, followed by an optional 'E' or 'F'.
993
+ #
994
+ # If there is a '+' at the start of s, positive values are returned with a
995
+ # leading '+'.
996
+ #
997
+ # A space at the start of s returns positive values with a leading space.
998
+ #
999
+ # If s contains a number, a space is inserted after each group of that many
1000
+ # digits, starting from '.' and counting outwards.
1001
+ #
1002
+ # If s ends with an 'E', engineering notation (0.xxxxEnn) is used.
1003
+ #
1004
+ # If s ends with an 'F', conventional floating point notation is used.
1005
+ #
1006
+ # Examples:
1007
+ #
1008
+ # BigDecimal('-1234567890123.45678901234567890').to_s('5F')
1009
+ # #=> '-123 45678 90123.45678 90123 45678 9'
1010
+ #
1011
+ # BigDecimal('1234567890123.45678901234567890').to_s('+8F')
1012
+ # #=> '+12345 67890123.45678901 23456789'
1013
+ #
1014
+ # BigDecimal('1234567890123.45678901234567890').to_s(' F')
1015
+ # #=> ' 1234567890123.4567890123456789'
1016
+ #
1017
+ def to_s: (?String | int s) -> String
1018
+
1019
+ # <!--
1020
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
1021
+ # - truncate(n)
1022
+ # -->
1023
+ # Truncate to the nearest integer (by default), returning the result as a
1024
+ # BigDecimal.
1025
+ #
1026
+ # BigDecimal('3.14159').truncate #=> 3
1027
+ # BigDecimal('8.7').truncate #=> 8
1028
+ # BigDecimal('-9.9').truncate #=> -9
1029
+ #
1030
+ # If n is specified and positive, the fractional part of the result has no more
1031
+ # than that many digits.
1032
+ #
1033
+ # If n is specified and negative, at least that many digits to the left of the
1034
+ # decimal point will be 0 in the result.
1035
+ #
1036
+ # BigDecimal('3.14159').truncate(3) #=> 3.141
1037
+ # BigDecimal('13345.234').truncate(-2) #=> 13300.0
1038
+ #
1039
+ def truncate: () -> Integer
1040
+ | (int n) -> BigDecimal
1041
+
1042
+ # <!--
1043
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
1044
+ # - zero?()
1045
+ # -->
1046
+ # Returns True if the value is zero.
1047
+ #
1048
+ def zero?: () -> bool
1049
+
1050
+ private
1051
+
1052
+ def initialize_copy: (self) -> self
1053
+
1054
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
1055
+ # Base value used in internal calculations. On a 32 bit system, BASE is 10000,
1056
+ # indicating that calculation is done in groups of 4 digits. (If it were larger,
1057
+ # BASE**2 wouldn't fit in 32 bits, so you couldn't guarantee that two groups
1058
+ # could always be multiplied together without overflow.)
1059
+ #
1060
+ BASE: Integer
1061
+
1062
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
1063
+ # Determines whether overflow, underflow or zero divide result in an exception
1064
+ # being thrown. See BigDecimal.mode.
1065
+ #
1066
+ EXCEPTION_ALL: Integer
1067
+
1068
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
1069
+ # Determines what happens when the result of a computation is infinity. See
1070
+ # BigDecimal.mode.
1071
+ #
1072
+ EXCEPTION_INFINITY: Integer
1073
+
1074
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
1075
+ # Determines what happens when the result of a computation is not a number
1076
+ # (NaN). See BigDecimal.mode.
1077
+ #
1078
+ EXCEPTION_NaN: Integer
1079
+
1080
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
1081
+ # Determines what happens when the result of a computation is an overflow (a
1082
+ # result too large to be represented). See BigDecimal.mode.
1083
+ #
1084
+ EXCEPTION_OVERFLOW: Integer
1085
+
1086
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
1087
+ # Determines what happens when the result of a computation is an underflow (a
1088
+ # result too small to be represented). See BigDecimal.mode.
1089
+ #
1090
+ EXCEPTION_UNDERFLOW: Integer
1091
+
1092
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
1093
+ # Determines what happens when a division by zero is performed. See
1094
+ # BigDecimal.mode.
1095
+ #
1096
+ EXCEPTION_ZERODIVIDE: Integer
1097
+
1098
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
1099
+ # Special value constants
1100
+ #
1101
+ INFINITY: BigDecimal
1102
+
1103
+ NAN: BigDecimal
1104
+
1105
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
1106
+ # Round towards +Infinity. See BigDecimal.mode.
1107
+ #
1108
+ ROUND_CEILING: Integer
1109
+
1110
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
1111
+ # Indicates that values should be rounded towards zero. See BigDecimal.mode.
1112
+ #
1113
+ ROUND_DOWN: Integer
1114
+
1115
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
1116
+ # Round towards -Infinity. See BigDecimal.mode.
1117
+ #
1118
+ ROUND_FLOOR: Integer
1119
+
1120
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
1121
+ # Indicates that digits >= 6 should be rounded up, others rounded down. See
1122
+ # BigDecimal.mode.
1123
+ #
1124
+ ROUND_HALF_DOWN: Integer
1125
+
1126
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
1127
+ # Round towards the even neighbor. See BigDecimal.mode.
1128
+ #
1129
+ ROUND_HALF_EVEN: Integer
1130
+
1131
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
1132
+ # Indicates that digits >= 5 should be rounded up, others rounded down. See
1133
+ # BigDecimal.mode.
1134
+ #
1135
+ ROUND_HALF_UP: Integer
1136
+
1137
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
1138
+ # Determines what happens when a result must be rounded in order to fit in the
1139
+ # appropriate number of significant digits. See BigDecimal.mode.
1140
+ #
1141
+ ROUND_MODE: round_mode
1142
+
1143
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
1144
+ # Indicates that values should be rounded away from zero. See BigDecimal.mode.
1145
+ #
1146
+ ROUND_UP: Integer
1147
+
1148
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
1149
+ # Indicates that a value is negative and finite. See BigDecimal.sign.
1150
+ #
1151
+ SIGN_NEGATIVE_FINITE: Integer
1152
+
1153
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
1154
+ # Indicates that a value is negative and infinite. See BigDecimal.sign.
1155
+ #
1156
+ SIGN_NEGATIVE_INFINITE: Integer
1157
+
1158
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
1159
+ # Indicates that a value is -0. See BigDecimal.sign.
1160
+ #
1161
+ SIGN_NEGATIVE_ZERO: Integer
1162
+
1163
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
1164
+ # Indicates that a value is not a number. See BigDecimal.sign.
1165
+ #
1166
+ SIGN_NaN: Integer
1167
+
1168
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
1169
+ # Indicates that a value is positive and finite. See BigDecimal.sign.
1170
+ #
1171
+ SIGN_POSITIVE_FINITE: Integer
1172
+
1173
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
1174
+ # Indicates that a value is positive and infinite. See BigDecimal.sign.
1175
+ #
1176
+ SIGN_POSITIVE_INFINITE: Integer
1177
+
1178
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
1179
+ # Indicates that a value is +0. See BigDecimal.sign.
1180
+ #
1181
+ SIGN_POSITIVE_ZERO: Integer
1182
+
1183
+ # <!-- rdoc-file=ext/bigdecimal/bigdecimal.c -->
1184
+ # The version of bigdecimal library
1185
+ #
1186
+ VERSION: String
1187
+ end
1188
+
1189
+ %a{annotate:rdoc:skip}
1190
+ module Kernel
1191
+ private
1192
+
1193
+ # <!--
1194
+ # rdoc-file=ext/bigdecimal/bigdecimal.c
1195
+ # - BigDecimal(value, exception: true) -> bigdecimal
1196
+ # - BigDecimal(value, ndigits, exception: true) -> bigdecimal
1197
+ # -->
1198
+ # Returns the BigDecimal converted from `value` with a precision of `ndigits`
1199
+ # decimal digits.
1200
+ #
1201
+ # When `ndigits` is less than the number of significant digits in the value, the
1202
+ # result is rounded to that number of digits, according to the current rounding
1203
+ # mode; see BigDecimal.mode.
1204
+ #
1205
+ # When `ndigits` is 0, the number of digits to correctly represent a float
1206
+ # number is determined automatically.
1207
+ #
1208
+ # Returns `value` converted to a BigDecimal, depending on the type of `value`:
1209
+ #
1210
+ # * Integer, Float, Rational, Complex, or BigDecimal: converted directly:
1211
+ #
1212
+ # # Integer, Complex, or BigDecimal value does not require ndigits; ignored if given.
1213
+ # BigDecimal(2) # => 0.2e1
1214
+ # BigDecimal(Complex(2, 0)) # => 0.2e1
1215
+ # BigDecimal(BigDecimal(2)) # => 0.2e1
1216
+ # # Float or Rational value requires ndigits.
1217
+ # BigDecimal(2.0, 0) # => 0.2e1
1218
+ # BigDecimal(Rational(2, 1), 0) # => 0.2e1
1219
+ #
1220
+ # * String: converted by parsing if it contains an integer or floating-point
1221
+ # literal; leading and trailing whitespace is ignored:
1222
+ #
1223
+ # # String does not require ndigits; ignored if given.
1224
+ # BigDecimal('2') # => 0.2e1
1225
+ # BigDecimal('2.0') # => 0.2e1
1226
+ # BigDecimal('0.2e1') # => 0.2e1
1227
+ # BigDecimal(' 2.0 ') # => 0.2e1
1228
+ #
1229
+ # * Other type that responds to method `:to_str`: first converted to a string,
1230
+ # then converted to a BigDecimal, as above.
1231
+ #
1232
+ # * Other type:
1233
+ #
1234
+ # * Raises an exception if keyword argument `exception` is `true`.
1235
+ # * Returns `nil` if keyword argument `exception` is `false`.
1236
+ #
1237
+ # Raises an exception if `value` evaluates to a Float and `digits` is larger
1238
+ # than Float::DIG + 1.
1239
+ #
1240
+ def self?.BigDecimal: (real | string | BigDecimal initial, ?int digits, ?exception: bool) -> BigDecimal
1241
+ end
1242
+
1243
+ %a{annotate:rdoc:skip}
1244
+ class Integer
1245
+ # <!--
1246
+ # rdoc-file=numeric.c
1247
+ # - self / numeric -> numeric_result
1248
+ # -->
1249
+ # Performs division; for integer `numeric`, truncates the result to an integer:
1250
+ #
1251
+ # 4 / 3 # => 1
1252
+ # 4 / -3 # => -2
1253
+ # -4 / 3 # => -2
1254
+ # -4 / -3 # => 1
1255
+ #
1256
+ # For other +numeric+, returns non-integer result:
1257
+ #
1258
+ # 4 / 3.0 # => 1.3333333333333333
1259
+ # 4 / Rational(3, 1) # => (4/3)
1260
+ # 4 / Complex(3, 0) # => ((4/3)+0i)
1261
+ #
1262
+ def /: (BigDecimal) -> BigDecimal
1263
+ | ...
1264
+
1265
+ # <!--
1266
+ # rdoc-file=numeric.c
1267
+ # - self * numeric -> numeric_result
1268
+ # -->
1269
+ # Performs multiplication:
1270
+ #
1271
+ # 4 * 2 # => 8
1272
+ # 4 * -2 # => -8
1273
+ # -4 * 2 # => -8
1274
+ # 4 * 2.0 # => 8.0
1275
+ # 4 * Rational(1, 3) # => (4/3)
1276
+ # 4 * Complex(2, 0) # => (8+0i)
1277
+ #
1278
+ def *: (BigDecimal) -> BigDecimal
1279
+ | ...
1280
+
1281
+ # <!--
1282
+ # rdoc-file=numeric.c
1283
+ # - self + numeric -> numeric_result
1284
+ # -->
1285
+ # Performs addition:
1286
+ #
1287
+ # 2 + 2 # => 4
1288
+ # -2 + 2 # => 0
1289
+ # -2 + -2 # => -4
1290
+ # 2 + 2.0 # => 4.0
1291
+ # 2 + Rational(2, 1) # => (4/1)
1292
+ # 2 + Complex(2, 0) # => (4+0i)
1293
+ #
1294
+ def +: (BigDecimal) -> BigDecimal
1295
+ | ...
1296
+
1297
+ # <!--
1298
+ # rdoc-file=numeric.c
1299
+ # - self - numeric -> numeric_result
1300
+ # -->
1301
+ # Performs subtraction:
1302
+ #
1303
+ # 4 - 2 # => 2
1304
+ # -4 - 2 # => -6
1305
+ # -4 - -2 # => -2
1306
+ # 4 - 2.0 # => 2.0
1307
+ # 4 - Rational(2, 1) # => (2/1)
1308
+ # 4 - Complex(2, 0) # => (2+0i)
1309
+ #
1310
+ def -: (BigDecimal) -> BigDecimal
1311
+ | ...
1312
+ end
1313
+
1314
+ %a{annotate:rdoc:skip}
1315
+ class Float
1316
+ # <!--
1317
+ # rdoc-file=numeric.c
1318
+ # - self / other -> numeric
1319
+ # -->
1320
+ # Returns a new Float which is the result of dividing `self` by `other`:
1321
+ #
1322
+ # f = 3.14
1323
+ # f / 2 # => 1.57
1324
+ # f / 2.0 # => 1.57
1325
+ # f / Rational(2, 1) # => 1.57
1326
+ # f / Complex(2, 0) # => (1.57+0.0i)
1327
+ #
1328
+ def /: (BigDecimal) -> BigDecimal
1329
+ | ...
1330
+
1331
+ # <!--
1332
+ # rdoc-file=numeric.c
1333
+ # - self * other -> numeric
1334
+ # -->
1335
+ # Returns a new Float which is the product of `self` and `other`:
1336
+ #
1337
+ # f = 3.14
1338
+ # f * 2 # => 6.28
1339
+ # f * 2.0 # => 6.28
1340
+ # f * Rational(1, 2) # => 1.57
1341
+ # f * Complex(2, 0) # => (6.28+0.0i)
1342
+ #
1343
+ def *: (BigDecimal) -> BigDecimal
1344
+ | ...
1345
+
1346
+ # <!--
1347
+ # rdoc-file=numeric.c
1348
+ # - self + other -> numeric
1349
+ # -->
1350
+ # Returns a new Float which is the sum of `self` and `other`:
1351
+ #
1352
+ # f = 3.14
1353
+ # f + 1 # => 4.140000000000001
1354
+ # f + 1.0 # => 4.140000000000001
1355
+ # f + Rational(1, 1) # => 4.140000000000001
1356
+ # f + Complex(1, 0) # => (4.140000000000001+0i)
1357
+ #
1358
+ def +: (BigDecimal) -> BigDecimal
1359
+ | ...
1360
+
1361
+ # <!--
1362
+ # rdoc-file=numeric.c
1363
+ # - self - other -> numeric
1364
+ # -->
1365
+ # Returns a new Float which is the difference of `self` and `other`:
1366
+ #
1367
+ # f = 3.14
1368
+ # f - 1 # => 2.14
1369
+ # f - 1.0 # => 2.14
1370
+ # f - Rational(1, 1) # => 2.14
1371
+ # f - Complex(1, 0) # => (2.14+0i)
1372
+ #
1373
+ def -: (BigDecimal) -> BigDecimal
1374
+ | ...
1375
+ end
1376
+
1377
+ %a{annotate:rdoc:skip}
1378
+ class Rational
1379
+ # <!--
1380
+ # rdoc-file=rational.c
1381
+ # - rat / numeric -> numeric
1382
+ # - rat.quo(numeric) -> numeric
1383
+ # -->
1384
+ # Performs division.
1385
+ #
1386
+ # Rational(2, 3) / Rational(2, 3) #=> (1/1)
1387
+ # Rational(900) / Rational(1) #=> (900/1)
1388
+ # Rational(-2, 9) / Rational(-9, 2) #=> (4/81)
1389
+ # Rational(9, 8) / 4 #=> (9/32)
1390
+ # Rational(20, 9) / 9.8 #=> 0.22675736961451246
1391
+ #
1392
+ def /: (BigDecimal) -> BigDecimal
1393
+ | ...
1394
+
1395
+ # <!--
1396
+ # rdoc-file=rational.c
1397
+ # - rat * numeric -> numeric
1398
+ # -->
1399
+ # Performs multiplication.
1400
+ #
1401
+ # Rational(2, 3) * Rational(2, 3) #=> (4/9)
1402
+ # Rational(900) * Rational(1) #=> (900/1)
1403
+ # Rational(-2, 9) * Rational(-9, 2) #=> (1/1)
1404
+ # Rational(9, 8) * 4 #=> (9/2)
1405
+ # Rational(20, 9) * 9.8 #=> 21.77777777777778
1406
+ #
1407
+ def *: (BigDecimal) -> BigDecimal
1408
+ | ...
1409
+
1410
+ # <!--
1411
+ # rdoc-file=rational.c
1412
+ # - rat + numeric -> numeric
1413
+ # -->
1414
+ # Performs addition.
1415
+ #
1416
+ # Rational(2, 3) + Rational(2, 3) #=> (4/3)
1417
+ # Rational(900) + Rational(1) #=> (901/1)
1418
+ # Rational(-2, 9) + Rational(-9, 2) #=> (-85/18)
1419
+ # Rational(9, 8) + 4 #=> (41/8)
1420
+ # Rational(20, 9) + 9.8 #=> 12.022222222222222
1421
+ #
1422
+ def +: (BigDecimal) -> BigDecimal
1423
+ | ...
1424
+
1425
+ # <!--
1426
+ # rdoc-file=rational.c
1427
+ # - rat - numeric -> numeric
1428
+ # -->
1429
+ # Performs subtraction.
1430
+ #
1431
+ # Rational(2, 3) - Rational(2, 3) #=> (0/1)
1432
+ # Rational(900) - Rational(1) #=> (899/1)
1433
+ # Rational(-2, 9) - Rational(-9, 2) #=> (77/18)
1434
+ # Rational(9, 8) - 4 #=> (-23/8)
1435
+ # Rational(20, 9) - 9.8 #=> -7.577777777777778
1436
+ #
1437
+ def -: (BigDecimal) -> BigDecimal
1438
+ | ...
1439
+ end
1440
+
1441
+ %a{annotate:rdoc:skip}
1442
+ class Complex
1443
+ # <!--
1444
+ # rdoc-file=complex.c
1445
+ # - complex / numeric -> new_complex
1446
+ # -->
1447
+ # Returns the quotient of `self` and `numeric`:
1448
+ #
1449
+ # Complex.rect(2, 3) / Complex.rect(2, 3) # => (1+0i)
1450
+ # Complex.rect(900) / Complex.rect(1) # => (900+0i)
1451
+ # Complex.rect(-2, 9) / Complex.rect(-9, 2) # => ((36/85)-(77/85)*i)
1452
+ # Complex.rect(9, 8) / 4 # => ((9/4)+2i)
1453
+ # Complex.rect(20, 9) / 9.8 # => (2.0408163265306123+0.9183673469387754i)
1454
+ #
1455
+ def /: (BigDecimal) -> Complex
1456
+ | ...
1457
+
1458
+ # <!--
1459
+ # rdoc-file=complex.c
1460
+ # - complex * numeric -> new_complex
1461
+ # -->
1462
+ # Returns the product of `self` and `numeric`:
1463
+ #
1464
+ # Complex.rect(2, 3) * Complex.rect(2, 3) # => (-5+12i)
1465
+ # Complex.rect(900) * Complex.rect(1) # => (900+0i)
1466
+ # Complex.rect(-2, 9) * Complex.rect(-9, 2) # => (0-85i)
1467
+ # Complex.rect(9, 8) * 4 # => (36+32i)
1468
+ # Complex.rect(20, 9) * 9.8 # => (196.0+88.2i)
1469
+ #
1470
+ def *: (BigDecimal) -> Complex
1471
+ | ...
1472
+
1473
+ # <!--
1474
+ # rdoc-file=complex.c
1475
+ # - complex + numeric -> new_complex
1476
+ # -->
1477
+ # Returns the sum of `self` and `numeric`:
1478
+ #
1479
+ # Complex.rect(2, 3) + Complex.rect(2, 3) # => (4+6i)
1480
+ # Complex.rect(900) + Complex.rect(1) # => (901+0i)
1481
+ # Complex.rect(-2, 9) + Complex.rect(-9, 2) # => (-11+11i)
1482
+ # Complex.rect(9, 8) + 4 # => (13+8i)
1483
+ # Complex.rect(20, 9) + 9.8 # => (29.8+9i)
1484
+ #
1485
+ def +: (BigDecimal) -> Complex
1486
+ | ...
1487
+
1488
+ # <!--
1489
+ # rdoc-file=complex.c
1490
+ # - complex - numeric -> new_complex
1491
+ # -->
1492
+ # Returns the difference of `self` and `numeric`:
1493
+ #
1494
+ # Complex.rect(2, 3) - Complex.rect(2, 3) # => (0+0i)
1495
+ # Complex.rect(900) - Complex.rect(1) # => (899+0i)
1496
+ # Complex.rect(-2, 9) - Complex.rect(-9, 2) # => (7+7i)
1497
+ # Complex.rect(9, 8) - 4 # => (5+8i)
1498
+ # Complex.rect(20, 9) - 9.8 # => (10.2+9i)
1499
+ #
1500
+ def -: (BigDecimal) -> Complex
1501
+ | ...
1502
+ end