-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteger.rbs
More file actions
1366 lines (1294 loc) · 39.4 KB
/
integer.rbs
File metadata and controls
1366 lines (1294 loc) · 39.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# <!-- rdoc-file=numeric.c -->
# An Integer object represents an integer value.
#
# You can create an Integer object explicitly with:
#
# * An [integer literal](rdoc-ref:syntax/literals.rdoc@Integer+Literals).
#
# You can convert certain objects to Integers with:
#
# * Method #Integer.
#
# An attempt to add a singleton method to an instance of this class causes an
# exception to be raised.
#
# ## What's Here
#
# First, what's elsewhere. Class Integer:
#
# * Inherits from [class Numeric](rdoc-ref:Numeric@What-27s+Here) and [class
# Object](rdoc-ref:Object@What-27s+Here).
# * Includes [module Comparable](rdoc-ref:Comparable@What-27s+Here).
#
# Here, class Integer provides methods for:
#
# * [Querying](rdoc-ref:Integer@Querying)
# * [Comparing](rdoc-ref:Integer@Comparing)
# * [Converting](rdoc-ref:Integer@Converting)
# * [Other](rdoc-ref:Integer@Other)
#
# ### Querying
#
# * #allbits?: Returns whether all bits in `self` are set.
# * #anybits?: Returns whether any bits in `self` are set.
# * #nobits?: Returns whether no bits in `self` are set.
#
# ### Comparing
#
# * #<: Returns whether `self` is less than the given value.
# * #<=: Returns whether `self` is less than or equal to the given value.
# * #<=>: Returns a number indicating whether `self` is less than, equal to,
# or greater than the given value.
# * #== (aliased as #===): Returns whether `self` is equal to the given
# value.
#
# * #>: Returns whether `self` is greater than the given value.
# * #>=: Returns whether `self` is greater than or equal to the given value.
#
# ### Converting
#
# * ::sqrt: Returns the integer square root of the given value.
# * ::try_convert: Returns the given value converted to an Integer.
# * #% (aliased as #modulo): Returns `self` modulo the given value.
# * #&: Returns the bitwise AND of `self` and the given value.
# * #*: Returns the product of `self` and the given value.
# * #**: Returns the value of `self` raised to the power of the given value.
# * #+: Returns the sum of `self` and the given value.
# * #-: Returns the difference of `self` and the given value.
# * #/: Returns the quotient of `self` and the given value.
# * #<<: Returns the value of `self` after a leftward bit-shift.
# * #>>: Returns the value of `self` after a rightward bit-shift.
# * #[]: Returns a slice of bits from `self`.
# * #^: Returns the bitwise EXCLUSIVE OR of `self` and the given value.
# * #|: Returns the bitwise OR of `self` and the given value.
# * #ceil: Returns the smallest number greater than or equal to `self`.
# * #chr: Returns a 1-character string containing the character represented by
# the value of `self`.
# * #digits: Returns an array of integers representing the base-radix digits
# of `self`.
# * #div: Returns the integer result of dividing `self` by the given value.
# * #divmod: Returns a 2-element array containing the quotient and remainder
# results of dividing `self` by the given value.
# * #fdiv: Returns the Float result of dividing `self` by the given value.
# * #floor: Returns the greatest number smaller than or equal to `self`.
# * #pow: Returns the modular exponentiation of `self`.
# * #pred: Returns the integer predecessor of `self`.
# * #remainder: Returns the remainder after dividing `self` by the given
# value.
# * #round: Returns `self` rounded to the nearest value with the given
# precision.
# * #succ (aliased as #next): Returns the integer successor of `self`.
# * #to_f: Returns `self` converted to a Float.
# * #to_s (aliased as #inspect): Returns a string containing the place-value
# representation of `self` in the given radix.
# * #truncate: Returns `self` truncated to the given precision.
#
# ### Other
#
# * #downto: Calls the given block with each integer value from `self` down to
# the given value.
# * #times: Calls the given block `self` times with each integer in
# `(0..self-1)`.
# * #upto: Calls the given block with each integer value from `self` up to the
# given value.
#
class Integer < Numeric
# <!--
# rdoc-file=numeric.c
# - Integer.sqrt(numeric) -> integer
# -->
# Returns the integer square root of the non-negative integer `n`, which is the
# largest non-negative integer less than or equal to the square root of
# `numeric`.
#
# Integer.sqrt(0) # => 0
# Integer.sqrt(1) # => 1
# Integer.sqrt(24) # => 4
# Integer.sqrt(25) # => 5
# Integer.sqrt(10**400) # => 10**200
#
# If `numeric` is not an Integer, it is converted to an Integer:
#
# Integer.sqrt(Complex(4, 0)) # => 2
# Integer.sqrt(Rational(4, 1)) # => 2
# Integer.sqrt(4.0) # => 2
# Integer.sqrt(3.14159) # => 1
#
# This method is equivalent to `Math.sqrt(numeric).floor`, except that the
# result of the latter code may differ from the true value due to the limited
# precision of floating point arithmetic.
#
# Integer.sqrt(10**46) # => 100000000000000000000000
# Math.sqrt(10**46).floor # => 99999999999999991611392
#
# Raises an exception if `numeric` is negative.
#
def self.sqrt: (int n) -> Integer
# <!--
# rdoc-file=numeric.c
# - Integer.try_convert(object) -> object, integer, or nil
# -->
# If `object` is an Integer object, returns `object`.
# Integer.try_convert(1) # => 1
#
# Otherwise if `object` responds to `:to_int`, calls `object.to_int` and returns
# the result.
# Integer.try_convert(1.25) # => 1
#
# Returns `nil` if `object` does not respond to `:to_int`
# Integer.try_convert([]) # => nil
#
# Raises an exception unless `object.to_int` returns an Integer object.
#
def self.try_convert: (int) -> Integer
| (untyped) -> Integer?
# <!--
# rdoc-file=numeric.c
# - self % other -> real_number
# -->
# Returns `self` modulo `other` as a real number.
#
# For integer `n` and real number `r`, these expressions are equivalent:
#
# n % r
# n-r*(n/r).floor
# n.divmod(r)[1]
#
# See Numeric#divmod.
#
# Examples:
#
# 10 % 2 # => 0
# 10 % 3 # => 1
# 10 % 4 # => 2
#
# 10 % -2 # => 0
# 10 % -3 # => -2
# 10 % -4 # => -2
#
# 10 % 3.0 # => 1.0
# 10 % Rational(3, 1) # => (1/1)
#
def %: (Float) -> Float
| (Rational) -> Rational
| (Integer) -> Integer
| (Numeric) -> Numeric
# <!--
# rdoc-file=numeric.c
# - self & other -> integer
# -->
# Bitwise AND; each bit in the result is 1 if both corresponding bits in `self`
# and `other` are 1, 0 otherwise:
#
# "%04b" % (0b0101 & 0b0110) # => "0100"
#
# Raises an exception if `other` is not an Integer.
#
# Related: Integer#| (bitwise OR), Integer#^ (bitwise EXCLUSIVE OR).
#
def &: (Integer) -> Integer
# <!--
# rdoc-file=numeric.c
# - self * numeric -> numeric_result
# -->
# Performs multiplication:
#
# 4 * 2 # => 8
# 4 * -2 # => -8
# -4 * 2 # => -8
# 4 * 2.0 # => 8.0
# 4 * Rational(1, 3) # => (4/3)
# 4 * Complex(2, 0) # => (8+0i)
#
def *: (Float) -> Float
| (Rational) -> Rational
| (Complex) -> Complex
| (Integer) -> Integer
# <!--
# rdoc-file=numeric.c
# - self ** numeric -> numeric_result
# -->
# Raises `self` to the power of `numeric`:
#
# 2 ** 3 # => 8
# 2 ** -3 # => (1/8)
# -2 ** 3 # => -8
# -2 ** -3 # => (-1/8)
# 2 ** 3.3 # => 9.849155306759329
# 2 ** Rational(3, 1) # => (8/1)
# 2 ** Complex(3, 0) # => (8+0i)
#
def **: (Integer) -> Numeric
| (Float) -> Numeric
| (Rational) -> Numeric
| (Complex) -> Complex
# <!--
# rdoc-file=numeric.c
# - self + numeric -> numeric_result
# -->
# Performs addition:
#
# 2 + 2 # => 4
# -2 + 2 # => 0
# -2 + -2 # => -4
# 2 + 2.0 # => 4.0
# 2 + Rational(2, 1) # => (4/1)
# 2 + Complex(2, 0) # => (4+0i)
#
def +: (Integer) -> Integer
| (Float) -> Float
| (Rational) -> Rational
| (Complex) -> Complex
# <!--
# rdoc-file=numeric.c
# - self - numeric -> numeric_result
# -->
# Performs subtraction:
#
# 4 - 2 # => 2
# -4 - 2 # => -6
# -4 - -2 # => -2
# 4 - 2.0 # => 2.0
# 4 - Rational(2, 1) # => (2/1)
# 4 - Complex(2, 0) # => (2+0i)
#
def -: (Integer) -> Integer
| (Float) -> Float
| (Rational) -> Rational
| (Complex) -> Complex
# <!--
# rdoc-file=numeric.rb
# - -int -> integer
# -->
# Returns `self`, negated.
#
def -@: () -> Integer
# <!--
# rdoc-file=numeric.c
# - self / numeric -> numeric_result
# -->
# Performs division; for integer `numeric`, truncates the result to an integer:
#
# 4 / 3 # => 1
# 4 / -3 # => -2
# -4 / 3 # => -2
# -4 / -3 # => 1
#
# For other +numeric+, returns non-integer result:
#
# 4 / 3.0 # => 1.3333333333333333
# 4 / Rational(3, 1) # => (4/3)
# 4 / Complex(3, 0) # => ((4/3)+0i)
#
def /: (Integer) -> Integer
| (Float) -> Float
| (Rational) -> Rational
| (Complex) -> Complex
# <!--
# rdoc-file=numeric.c
# - self < other -> true or false
# -->
# Returns `true` if the value of `self` is less than that of `other`:
#
# 1 < 0 # => false
# 1 < 1 # => false
# 1 < 2 # => true
# 1 < 0.5 # => false
# 1 < Rational(1, 2) # => false
#
# Raises an exception if the comparison cannot be made.
#
def <: (Numeric) -> bool
# <!--
# rdoc-file=numeric.c
# - self << count -> integer
# -->
# Returns `self` with bits shifted `count` positions to the left, or to the
# right if `count` is negative:
#
# n = 0b11110000
# "%08b" % (n << 1) # => "111100000"
# "%08b" % (n << 3) # => "11110000000"
# "%08b" % (n << -1) # => "01111000"
# "%08b" % (n << -3) # => "00011110"
#
# Related: Integer#>>.
#
def <<: (int) -> Integer
# <!--
# rdoc-file=numeric.c
# - self <= real -> true or false
# -->
# Returns `true` if the value of `self` is less than or equal to that of
# `other`:
#
# 1 <= 0 # => false
# 1 <= 1 # => true
# 1 <= 2 # => true
# 1 <= 0.5 # => false
# 1 <= Rational(1, 2) # => false
#
# Raises an exception if the comparison cannot be made.
#
def <=: (Numeric) -> bool
# <!--
# rdoc-file=numeric.c
# - self <=> other -> -1, 0, +1, or nil
# -->
# Returns:
#
# * -1, if `self` is less than `other`.
# * 0, if `self` is equal to `other`.
# * 1, if `self` is greater then `other`.
# * `nil`, if `self` and `other` are incomparable.
#
# Examples:
#
# 1 <=> 2 # => -1
# 1 <=> 1 # => 0
# 1 <=> 0 # => 1
# 1 <=> 'foo' # => nil
#
# 1 <=> 1.0 # => 0
# 1 <=> Rational(1, 1) # => 0
# 1 <=> Complex(1, 0) # => 0
#
# This method is the basis for comparisons in module Comparable.
#
def <=>: (Integer | Rational) -> Integer
| (untyped) -> Integer?
# <!-- rdoc-file=numeric.c -->
# Returns `true` if `self` is numerically equal to `other`; `false` otherwise.
#
# 1 == 2 #=> false
# 1 == 1.0 #=> true
#
# Related: Integer#eql? (requires `other` to be an Integer).
#
def ==: (untyped) -> bool
# <!--
# rdoc-file=numeric.c
# - self == other -> true or false
# -->
# Returns `true` if `self` is numerically equal to `other`; `false` otherwise.
#
# 1 == 2 #=> false
# 1 == 1.0 #=> true
#
# Related: Integer#eql? (requires `other` to be an Integer).
#
def ===: (untyped) -> bool
# <!--
# rdoc-file=numeric.c
# - self > other -> true or false
# -->
# Returns `true` if the value of `self` is greater than that of `other`:
#
# 1 > 0 # => true
# 1 > 1 # => false
# 1 > 2 # => false
# 1 > 0.5 # => true
# 1 > Rational(1, 2) # => true
#
# Raises an exception if the comparison cannot be made.
#
def >: (Numeric) -> bool
# <!--
# rdoc-file=numeric.c
# - self >= real -> true or false
# -->
# Returns `true` if the value of `self` is greater than or equal to that of
# `other`:
#
# 1 >= 0 # => true
# 1 >= 1 # => true
# 1 >= 2 # => false
# 1 >= 0.5 # => true
# 1 >= Rational(1, 2) # => true
#
# Raises an exception if the comparison cannot be made.
#
def >=: (Numeric) -> bool
# <!--
# rdoc-file=numeric.c
# - self >> count -> integer
# -->
# Returns `self` with bits shifted `count` positions to the right, or to the
# left if `count` is negative:
#
# n = 0b11110000
# "%08b" % (n >> 1) # => "01111000"
# "%08b" % (n >> 3) # => "00011110"
# "%08b" % (n >> -1) # => "111100000"
# "%08b" % (n >> -3) # => "11110000000"
#
# Related: Integer#<<.
#
def >>: (int) -> Integer
# <!--
# rdoc-file=numeric.c
# - self[offset] -> 0 or 1
# - self[offset, size] -> integer
# - self[range] -> integer
# -->
# Returns a slice of bits from `self`.
#
# With argument `offset`, returns the bit at the given offset, where offset 0
# refers to the least significant bit:
#
# n = 0b10 # => 2
# n[0] # => 0
# n[1] # => 1
# n[2] # => 0
# n[3] # => 0
#
# In principle, `n[i]` is equivalent to `(n >> i) & 1`. Thus, negative index
# always returns zero:
#
# 255[-1] # => 0
#
# With arguments `offset` and `size`, returns `size` bits from `self`, beginning
# at `offset` and including bits of greater significance:
#
# n = 0b111000 # => 56
# "%010b" % n[0, 10] # => "0000111000"
# "%010b" % n[4, 10] # => "0000000011"
#
# With argument `range`, returns `range.size` bits from `self`, beginning at
# `range.begin` and including bits of greater significance:
#
# n = 0b111000 # => 56
# "%010b" % n[0..9] # => "0000111000"
# "%010b" % n[4..9] # => "0000000011"
#
# Raises an exception if the slice cannot be constructed.
#
def []: (int) -> Integer
| (int i, int len) -> Integer
| (Range[int]) -> Integer
# <!--
# rdoc-file=numeric.c
# - self ^ other -> integer
# -->
# Bitwise EXCLUSIVE OR; each bit in the result is 1 if the corresponding bits in
# `self` and `other` are different, 0 otherwise:
#
# "%04b" % (0b0101 ^ 0b0110) # => "0011"
#
# Raises an exception if `other` is not an Integer.
#
# Related: Integer#& (bitwise AND), Integer#| (bitwise OR).
#
def ^: (Integer) -> Integer
# <!--
# rdoc-file=numeric.rb
# - abs -> integer
# -->
# Returns the absolute value of `self`.
#
# (-12345).abs # => 12345
# -12345.abs # => 12345
# 12345.abs # => 12345
#
def abs: () -> Integer
# <!--
# rdoc-file=numeric.c
# - allbits?(mask) -> true or false
# -->
# Returns `true` if all bits that are set (=1) in `mask` are also set in `self`;
# returns `false` otherwise.
#
# Example values:
#
# 0b1010101 self
# 0b1010100 mask
# 0b1010100 self & mask
# true self.allbits?(mask)
#
# 0b1010100 self
# 0b1010101 mask
# 0b1010100 self & mask
# false self.allbits?(mask)
#
# Related: Integer#anybits?, Integer#nobits?.
#
def allbits?: (int mask) -> bool
# <!--
# rdoc-file=numeric.c
# - anybits?(mask) -> true or false
# -->
# Returns `true` if any bit that is set (=1) in `mask` is also set in `self`;
# returns `false` otherwise.
#
# Example values:
#
# 0b10000010 self
# 0b11111111 mask
# 0b10000010 self & mask
# true self.anybits?(mask)
#
# 0b00000000 self
# 0b11111111 mask
# 0b00000000 self & mask
# false self.anybits?(mask)
#
# Related: Integer#allbits?, Integer#nobits?.
#
def anybits?: (int mask) -> bool
alias arg angle
# <!--
# rdoc-file=numeric.rb
# - bit_length -> integer
# -->
# Returns the number of bits of the value of `self`, which is the bit position
# of the highest-order bit that is different from the sign bit (where the least
# significant bit has bit position 1). If there is no such bit (zero or minus
# one), returns zero.
#
# This method returns `ceil(log2(self < 0 ? -self : self + 1))`>.
#
# (-2**1000-1).bit_length # => 1001
# (-2**1000).bit_length # => 1000
# (-2**1000+1).bit_length # => 1000
# (-2**12-1).bit_length # => 13
# (-2**12).bit_length # => 12
# (-2**12+1).bit_length # => 12
# -0x101.bit_length # => 9
# -0x100.bit_length # => 8
# -0xff.bit_length # => 8
# -2.bit_length # => 1
# -1.bit_length # => 0
# 0.bit_length # => 0
# 1.bit_length # => 1
# 0xff.bit_length # => 8
# 0x100.bit_length # => 9
# (2**12-1).bit_length # => 12
# (2**12).bit_length # => 13
# (2**12+1).bit_length # => 13
# (2**1000-1).bit_length # => 1000
# (2**1000).bit_length # => 1001
# (2**1000+1).bit_length # => 1001
#
# For Integer *n*, this method can be used to detect overflow in Array#pack:
#
# if n.bit_length < 32
# [n].pack('l') # No overflow.
# else
# raise 'Overflow'
# end
#
def bit_length: () -> Integer
# <!--
# rdoc-file=numeric.c
# - ceil(ndigits = 0) -> integer
# -->
# Returns an integer that is a "ceiling" value for `self`,
# as specified by the given `ndigits`,
# which must be an
# [integer-convertible
# object](rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects).
# * When `self` is zero, returns zero (regardless of the value of `ndigits`):
# 0.ceil(2) # => 0
# 0.ceil(-2) # => 0
#
# * When `self` is non-zero and `ndigits` is non-negative, returns `self`:
# 555.ceil # => 555
# 555.ceil(50) # => 555
#
# * When `self` is non-zero and `ndigits` is negative,
# returns a value based on a computed granularity:
# * The granularity is `10 ** ndigits.abs`.
# * The returned value is the smallest multiple of the granularity
# that is greater than or equal to `self`.
# Examples with positive `self`:
# ndigits|Granularity|1234.ceil(ndigits)
# -------|-----------|------------------
# -1| 10| 1240
# -2| 100| 1300
# -3| 1000| 2000
# -4| 10000| 10000
# -5| 100000| 100000
# Examples with negative `self`:
# ndigits|Granularity|-1234.ceil(ndigits)
# -------|-----------|-------------------
# -1| 10| -1230
# -2| 100| -1200
# -3| 1000| -1000
# -4| 10000| 0
# -5| 100000| 0
# Related: Integer#floor.
#
def ceil: () -> Integer
| (int digits) -> (Integer | Float)
# <!--
# rdoc-file=numeric.rb
# - ceildiv(numeric) -> integer
# -->
# Returns the result of division `self` by `numeric`. rounded up to the nearest
# integer.
#
# 3.ceildiv(3) # => 1
# 4.ceildiv(3) # => 2
#
# 4.ceildiv(-3) # => -1
# -4.ceildiv(3) # => -1
# -4.ceildiv(-3) # => 2
#
# 3.ceildiv(1.2) # => 3
#
def ceildiv: (Numeric other) -> Integer
# <!--
# rdoc-file=numeric.c
# - chr -> string
# - chr(encoding) -> string
# -->
# Returns a 1-character string containing the character represented by the value
# of `self`, according to the given `encoding`.
#
# 65.chr # => "A"
# 0.chr # => "\x00"
# 255.chr # => "\xFF"
# string = 255.chr(Encoding::UTF_8)
# string.encoding # => Encoding::UTF_8
#
# Raises an exception if `self` is negative.
#
# Related: Integer#ord.
#
def chr: (?encoding) -> String
# <!--
# rdoc-file=bignum.c
# - int.coerce(numeric) -> array
# -->
# Returns an array with both a `numeric` and a `int` represented as Integer
# objects or Float objects.
#
# This is achieved by converting `numeric` to an Integer or a Float.
#
# A TypeError is raised if the `numeric` is not an Integer or a Float type.
#
# (0x3FFFFFFFFFFFFFFF+1).coerce(42) #=> [42, 4611686018427387904]
#
def coerce: (Numeric) -> [ Numeric, Numeric ]
# <!--
# rdoc-file=numeric.rb
# - denominator -> 1
# -->
# Returns `1`.
#
def denominator: () -> Integer
# <!--
# rdoc-file=numeric.c
# - digits(base = 10) -> array_of_integers
# -->
# Returns an array of integers representing the `base`-radix digits of `self`;
# the first element of the array represents the least significant digit:
#
# 12345.digits # => [5, 4, 3, 2, 1]
# 12345.digits(7) # => [4, 6, 6, 0, 5]
# 12345.digits(100) # => [45, 23, 1]
#
# Raises an exception if `self` is negative or `base` is less than 2.
#
def digits: (?int base) -> ::Array[Integer]
# <!--
# rdoc-file=numeric.c
# - div(numeric) -> integer
# -->
# Performs integer division; returns the integer result of dividing `self` by
# `numeric`:
#
# 4.div(3) # => 1
# 4.div(-3) # => -2
# -4.div(3) # => -2
# -4.div(-3) # => 1
# 4.div(3.0) # => 1
# 4.div(Rational(3, 1)) # => 1
#
# Raises an exception if `numeric` does not have method `div`.
#
def div: (Numeric) -> Integer
# <!--
# rdoc-file=numeric.c
# - divmod(other) -> array
# -->
# Returns a 2-element array `[q, r]`, where
#
# q = (self/other).floor # Quotient
# r = self % other # Remainder
#
# Examples:
#
# 11.divmod(4) # => [2, 3]
# 11.divmod(-4) # => [-3, -1]
# -11.divmod(4) # => [-3, 1]
# -11.divmod(-4) # => [2, -3]
#
# 12.divmod(4) # => [3, 0]
# 12.divmod(-4) # => [-3, 0]
# -12.divmod(4) # => [-3, 0]
# -12.divmod(-4) # => [3, 0]
#
# 13.divmod(4.0) # => [3, 1.0]
# 13.divmod(Rational(4, 1)) # => [3, (1/1)]
#
def divmod: (Integer) -> [ Integer, Integer ]
| (Float) -> [ Integer, Float ]
| (Rational) -> [ Integer, Rational ]
| (Numeric) -> [ Numeric, Numeric ]
# <!--
# rdoc-file=numeric.c
# - downto(limit) {|i| ... } -> self
# - downto(limit) -> enumerator
# -->
# Calls the given block with each integer value from `self` down to `limit`;
# returns `self`:
#
# a = []
# 10.downto(5) {|i| a << i } # => 10
# a # => [10, 9, 8, 7, 6, 5]
# a = []
# 0.downto(-5) {|i| a << i } # => 0
# a # => [0, -1, -2, -3, -4, -5]
# 4.downto(5) {|i| fail 'Cannot happen' } # => 4
#
# With no block given, returns an Enumerator.
#
def downto: (Numeric limit) { (Integer) -> void } -> Integer
| (Numeric limit) -> ::Enumerator[Integer, self]
# <!--
# rdoc-file=numeric.rb
# - even? -> true or false
# -->
# Returns `true` if `self` is an even number, `false` otherwise.
#
def even?: () -> bool
# <!--
# rdoc-file=numeric.c
# - fdiv(numeric) -> float
# -->
# Returns the Float result of dividing `self` by `numeric`:
#
# 4.fdiv(2) # => 2.0
# 4.fdiv(-2) # => -2.0
# -4.fdiv(2) # => -2.0
# 4.fdiv(2.0) # => 2.0
# 4.fdiv(Rational(3, 4)) # => 5.333333333333333
#
# Raises an exception if `numeric` cannot be converted to a Float.
#
def fdiv: (Numeric) -> Float
# <!--
# rdoc-file=numeric.c
# - floor(ndigits = 0) -> integer
# -->
# Returns an integer that is a "floor" value for `self`,
# as specified by the given `ndigits`,
# which must be an
# [integer-convertible
# object](rdoc-ref:implicit_conversion.rdoc@Integer-Convertible+Objects).
# * When `self` is zero, returns zero (regardless of the value of `ndigits`):
# 0.floor(2) # => 0
# 0.floor(-2) # => 0
#
# * When `self` is non-zero and `ndigits` is non-negative, returns `self`:
# 555.floor # => 555
# 555.floor(50) # => 555
#
# * When `self` is non-zero and `ndigits` is negative,
# returns a value based on a computed granularity:
# * The granularity is `10 ** ndigits.abs`.
# * The returned value is the largest multiple of the granularity
# that is less than or equal to `self`.
# Examples with positive `self`:
# ndigits|Granularity|1234.floor(ndigits)
# -------|-----------|-------------------
# -1| 10| 1230
# -2| 100| 1200
# -3| 1000| 1000
# -4| 10000| 0
# -5| 100000| 0
# Examples with negative `self`:
# ndigits|Granularity|-1234.floor(ndigits)
# -------|-----------|--------------------
# -1| 10| -1240
# -2| 100| -1300
# -3| 1000| -2000
# -4| 10000| -10000
# -5| 100000| -100000
# Related: Integer#ceil.
#
def floor: (?int digits) -> Integer
# <!--
# rdoc-file=rational.c
# - int.gcd(other_int) -> integer
# -->
# Returns the greatest common divisor of the two integers. The result is always
# positive. 0.gcd(x) and x.gcd(0) return x.abs.
#
# 36.gcd(60) #=> 12
# 2.gcd(2) #=> 2
# 3.gcd(-7) #=> 1
# ((1<<31)-1).gcd((1<<61)-1) #=> 1
#
def gcd: (Integer) -> Integer
# <!--
# rdoc-file=rational.c
# - int.gcdlcm(other_int) -> array
# -->
# Returns an array with the greatest common divisor and the least common
# multiple of the two integers, [gcd, lcm].
#
# 36.gcdlcm(60) #=> [12, 180]
# 2.gcdlcm(2) #=> [2, 2]
# 3.gcdlcm(-7) #=> [1, 21]
# ((1<<31)-1).gcdlcm((1<<61)-1) #=> [1, 4951760154835678088235319297]
#
def gcdlcm: (Integer) -> [ Integer, Integer ]
# <!-- rdoc-file=numeric.c -->
# Returns a string containing the place-value representation of `self` in radix
# `base` (in 2..36).
#
# 12345.to_s # => "12345"
# 12345.to_s(2) # => "11000000111001"
# 12345.to_s(8) # => "30071"
# 12345.to_s(10) # => "12345"
# 12345.to_s(16) # => "3039"
# 12345.to_s(36) # => "9ix"
# 78546939656932.to_s(36) # => "rubyrules"
#
# Raises an exception if `base` is out of range.
#
alias inspect to_s
# <!--
# rdoc-file=numeric.rb
# - integer? -> true
# -->
# Since `self` is already an Integer, always returns `true`.
#
def integer?: () -> true
# <!--
# rdoc-file=rational.c
# - int.lcm(other_int) -> integer
# -->
# Returns the least common multiple of the two integers. The result is always
# positive. 0.lcm(x) and x.lcm(0) return zero.
#
# 36.lcm(60) #=> 180
# 2.lcm(2) #=> 2
# 3.lcm(-7) #=> 21
# ((1<<31)-1).lcm((1<<61)-1) #=> 4951760154835678088235319297
#
def lcm: (Integer) -> Integer
# <!--
# rdoc-file=numeric.rb
# - magnitude()
# -->
#
def magnitude: () -> Integer
# <!-- rdoc-file=numeric.c -->
# Returns `self` modulo `other` as a real number.
#
# For integer `n` and real number `r`, these expressions are equivalent:
#
# n % r
# n-r*(n/r).floor
# n.divmod(r)[1]
#
# See Numeric#divmod.
#
# Examples:
#
# 10 % 2 # => 0
# 10 % 3 # => 1
# 10 % 4 # => 2
#
# 10 % -2 # => 0
# 10 % -3 # => -2
# 10 % -4 # => -2
#
# 10 % 3.0 # => 1.0
# 10 % Rational(3, 1) # => (1/1)
#
alias modulo %
def negative?: () -> bool
# <!-- rdoc-file=numeric.c -->
# Returns the successor integer of `self` (equivalent to `self + 1`):
#
# 1.succ #=> 2
# -1.succ #=> 0
#
# Related: Integer#pred (predecessor value).
#
def next: () -> Integer
# <!--
# rdoc-file=numeric.c
# - nobits?(mask) -> true or false
# -->
# Returns `true` if no bit that is set (=1) in `mask` is also set in `self`;
# returns `false` otherwise.
#
# Example values:
#
# 0b11110000 self
# 0b00001111 mask
# 0b00000000 self & mask
# true self.nobits?(mask)
#
# 0b00000001 self
# 0b11111111 mask
# 0b00000001 self & mask
# false self.nobits?(mask)
#
# Related: Integer#allbits?, Integer#anybits?.
#
def nobits?: (int mask) -> bool
# <!--
# rdoc-file=numeric.rb
# - numerator -> self
# -->
# Returns `self`.
#
def numerator: () -> Integer