-
Notifications
You must be signed in to change notification settings - Fork 242
Expand file tree
/
Copy pathfloat.rbs
More file actions
1102 lines (1022 loc) · 30.1 KB
/
float.rbs
File metadata and controls
1102 lines (1022 loc) · 30.1 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 -->
# A Float object represents a sometimes-inexact real number using the native
# architecture's double-precision floating point representation.
#
# Floating point has a different arithmetic and is an inexact number. So you
# should know its esoteric system. See following:
#
# * https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
# * https://github.com/rdp/ruby_tutorials_core/wiki/Ruby-Talk-FAQ#-why-are-rub
# ys-floats-imprecise
# * https://en.wikipedia.org/wiki/Floating_point#Accuracy_problems
#
#
# You can create a Float object explicitly with:
#
# * A [floating-point literal](rdoc-ref:syntax/literals.rdoc@Float+Literals).
#
#
# You can convert certain objects to Floats with:
#
# * Method #Float.
#
#
# ## What's Here
#
# First, what's elsewhere. Class Float:
#
# * Inherits from [class Numeric](rdoc-ref:Numeric@What-27s+Here).
#
#
# Here, class Float provides methods for:
#
# * [Querying](rdoc-ref:Float@Querying)
# * [Comparing](rdoc-ref:Float@Comparing)
# * [Converting](rdoc-ref:Float@Converting)
#
#
# ### Querying
#
# * #finite?: Returns whether `self` is finite.
# * #hash: Returns the integer hash code for `self`.
# * #infinite?: Returns whether `self` is infinite.
# * #nan?: Returns whether `self` is a NaN (not-a-number).
#
#
# ### 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 #=== and #eql?): 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
#
# * #% (aliased as #modulo): Returns `self` modulo 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.
# * #ceil: Returns the smallest number greater than or equal to `self`.
# * #coerce: Returns a 2-element array containing the given value converted to
# a Float and `self`
# * #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`.
# * #next_float: Returns the next-larger representable Float.
# * #prev_float: Returns the next-smaller representable Float.
# * #quo: Returns the quotient from dividing `self` by the given value.
# * #round: Returns `self` rounded to the nearest value, to a given precision.
# * #to_i (aliased as #to_int): Returns `self` truncated to an Integer.
# * #to_s (aliased as #inspect): Returns a string containing the place-value
# representation of `self` in the given radix.
# * #truncate: Returns `self` truncated to a given precision.
#
class Float < Numeric
public
# <!--
# rdoc-file=numeric.c
# - self % other -> float
# -->
# Returns `self` modulo `other` as a float.
#
# For float `f` and real number `r`, these expressions are equivalent:
#
# f % r
# f-r*(f/r).floor
# f.divmod(r)[1]
#
# See Numeric#divmod.
#
# Examples:
#
# 10.0 % 2 # => 0.0
# 10.0 % 3 # => 1.0
# 10.0 % 4 # => 2.0
#
# 10.0 % -2 # => 0.0
# 10.0 % -3 # => -2.0
# 10.0 % -4 # => -2.0
#
# 10.0 % 4.0 # => 2.0
# 10.0 % Rational(4, 1) # => 2.0
#
def %: (Integer) -> Float
| (Float) -> Float
| (Rational) -> Float
| (Numeric) -> Numeric
# <!--
# rdoc-file=numeric.c
# - self * other -> numeric
# -->
# Returns a new Float which is the product of `self` and `other`:
#
# f = 3.14
# f * 2 # => 6.28
# f * 2.0 # => 6.28
# f * Rational(1, 2) # => 1.57
# f * Complex(2, 0) # => (6.28+0.0i)
#
def *: (Complex) -> Complex
| (Numeric) -> Float
# <!--
# rdoc-file=numeric.c
# - self ** other -> numeric
# -->
# Raises `self` to the power of `other`:
#
# f = 3.14
# f ** 2 # => 9.8596
# f ** -2 # => 0.1014239928597509
# f ** 2.1 # => 11.054834900588839
# f ** Rational(2, 1) # => 9.8596
# f ** Complex(2, 0) # => (9.8596+0i)
#
def **: (Integer) -> Float
| (Float) -> (Float | Complex)
| (Rational) -> (Float | Complex)
| (Complex) -> Complex
# <!--
# rdoc-file=numeric.c
# - self + other -> numeric
# -->
# Returns a new Float which is the sum of `self` and `other`:
#
# f = 3.14
# f + 1 # => 4.140000000000001
# f + 1.0 # => 4.140000000000001
# f + Rational(1, 1) # => 4.140000000000001
# f + Complex(1, 0) # => (4.140000000000001+0i)
#
def +: (Complex) -> Complex
| (Numeric) -> Float
def +@: () -> Float
# <!--
# rdoc-file=numeric.c
# - self - other -> numeric
# -->
# Returns a new Float which is the difference of `self` and `other`:
#
# f = 3.14
# f - 1 # => 2.14
# f - 1.0 # => 2.14
# f - Rational(1, 1) # => 2.14
# f - Complex(1, 0) # => (2.14+0i)
#
def -: (Complex) -> Complex
| (Numeric) -> Float
# <!--
# rdoc-file=numeric.rb
# - -float -> float
# -->
# Returns `self`, negated.
#
def -@: () -> Float
# <!--
# rdoc-file=numeric.c
# - self / other -> numeric
# -->
# Returns a new Float which is the result of dividing `self` by `other`:
#
# f = 3.14
# f / 2 # => 1.57
# f / 2.0 # => 1.57
# f / Rational(2, 1) # => 1.57
# f / Complex(2, 0) # => (1.57+0.0i)
#
def /: (Complex) -> Complex
| (Numeric) -> Float
# <!--
# rdoc-file=numeric.c
# - self < other -> true or false
# -->
# Returns `true` if `self` is numerically less than `other`:
#
# 2.0 < 3 # => true
# 2.0 < 3.0 # => true
# 2.0 < Rational(3, 1) # => true
# 2.0 < 2.0 # => false
#
# `Float::NAN < Float::NAN` returns an implementation-dependent value.
#
def <: (Numeric) -> bool
# <!--
# rdoc-file=numeric.c
# - self <= other -> true or false
# -->
# Returns `true` if `self` is numerically less than or equal to `other`:
#
# 2.0 <= 3 # => true
# 2.0 <= 3.0 # => true
# 2.0 <= Rational(3, 1) # => true
# 2.0 <= 2.0 # => true
# 2.0 <= 1.0 # => false
#
# `Float::NAN <= Float::NAN` returns an implementation-dependent value.
#
def <=: (Numeric) -> bool
# <!--
# rdoc-file=numeric.c
# - self <=> other -> -1, 0, +1, or nil
# -->
# Returns a value that depends on the numeric relation between `self` and
# `other`:
#
# * -1, if `self` is less than `other`.
# * 0, if `self` is equal to `other`.
# * 1, if `self` is greater than `other`.
# * `nil`, if the two values are incommensurate.
#
#
# Examples:
#
# 2.0 <=> 2 # => 0
# 2.0 <=> 2.0 # => 0
# 2.0 <=> Rational(2, 1) # => 0
# 2.0 <=> Complex(2, 0) # => 0
# 2.0 <=> 1.9 # => 1
# 2.0 <=> 2.1 # => -1
# 2.0 <=> 'foo' # => nil
#
# This is the basis for the tests in the Comparable module.
#
# `Float::NAN <=> Float::NAN` returns an implementation-dependent value.
#
def <=>: (Numeric) -> Integer?
# <!--
# rdoc-file=numeric.c
# - self == other -> true or false
# -->
# Returns `true` if `other` has the same value as `self`, `false` otherwise:
#
# 2.0 == 2 # => true
# 2.0 == 2.0 # => true
# 2.0 == Rational(2, 1) # => true
# 2.0 == Complex(2, 0) # => true
#
# `Float::NAN == Float::NAN` returns an implementation-dependent value.
#
# Related: Float#eql? (requires `other` to be a Float).
#
def ==: (untyped) -> bool
# <!-- rdoc-file=numeric.c -->
# Returns `true` if `other` has the same value as `self`, `false` otherwise:
#
# 2.0 == 2 # => true
# 2.0 == 2.0 # => true
# 2.0 == Rational(2, 1) # => true
# 2.0 == Complex(2, 0) # => true
#
# `Float::NAN == Float::NAN` returns an implementation-dependent value.
#
# Related: Float#eql? (requires `other` to be a Float).
#
def ===: (untyped) -> bool
# <!--
# rdoc-file=numeric.c
# - self > other -> true or false
# -->
# Returns `true` if `self` is numerically greater than `other`:
#
# 2.0 > 1 # => true
# 2.0 > 1.0 # => true
# 2.0 > Rational(1, 2) # => true
# 2.0 > 2.0 # => false
#
# `Float::NAN > Float::NAN` returns an implementation-dependent value.
#
def >: (Numeric) -> bool
# <!--
# rdoc-file=numeric.c
# - self >= other -> true or false
# -->
# Returns `true` if `self` is numerically greater than or equal to `other`:
#
# 2.0 >= 1 # => true
# 2.0 >= 1.0 # => true
# 2.0 >= Rational(1, 2) # => true
# 2.0 >= 2.0 # => true
# 2.0 >= 2.1 # => false
#
# `Float::NAN >= Float::NAN` returns an implementation-dependent value.
#
def >=: (Numeric) -> bool
# <!--
# rdoc-file=numeric.rb
# - float.abs -> float
# -->
# Returns the absolute value of `self`:
#
# (-34.56).abs # => 34.56
# -34.56.abs # => 34.56
# 34.56.abs # => 34.56
#
def abs: () -> Float
def abs2: () -> Float
# <!-- rdoc-file=complex.c -->
# Returns 0 if `self` is positive, Math::PI otherwise.
#
def angle: () -> (Integer | Float)
# <!--
# rdoc-file=complex.c
# - arg -> 0 or Math::PI
# -->
# Returns 0 if `self` is positive, Math::PI otherwise.
#
alias arg angle
# <!--
# rdoc-file=numeric.c
# - ceil(ndigits = 0) -> float or integer
# -->
# Returns the smallest number greater than or equal to `self` with a precision
# of `ndigits` decimal digits.
#
# When `ndigits` is positive, returns a float with `ndigits` digits after the
# decimal point (as available):
#
# f = 12345.6789
# f.ceil(1) # => 12345.7
# f.ceil(3) # => 12345.679
# f = -12345.6789
# f.ceil(1) # => -12345.6
# f.ceil(3) # => -12345.678
#
# When `ndigits` is non-positive, returns an integer with at least `ndigits.abs`
# trailing zeros:
#
# f = 12345.6789
# f.ceil(0) # => 12346
# f.ceil(-3) # => 13000
# f = -12345.6789
# f.ceil(0) # => -12345
# f.ceil(-3) # => -12000
#
# Note that the limited precision of floating-point arithmetic may lead to
# surprising results:
#
# (2.1 / 0.7).ceil #=> 4 (!)
#
# Related: Float#floor.
#
def ceil: () -> Integer
| (int digits) -> (Integer | Float)
# <!--
# rdoc-file=numeric.c
# - coerce(other) -> array
# -->
# Returns a 2-element array containing `other` converted to a Float and `self`:
#
# f = 3.14 # => 3.14
# f.coerce(2) # => [2.0, 3.14]
# f.coerce(2.0) # => [2.0, 3.14]
# f.coerce(Rational(1, 2)) # => [0.5, 3.14]
# f.coerce(Complex(1, 0)) # => [1.0, 3.14]
#
# Raises an exception if a type conversion fails.
#
def coerce: (Numeric) -> [ Float, Float ]
def conj: () -> Float
def conjugate: () -> Float
# <!--
# rdoc-file=rational.c
# - flo.denominator -> integer
# -->
# Returns the denominator (always positive). The result is machine dependent.
#
# See also Float#numerator.
#
def denominator: () -> Integer
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.0.divmod(4) # => [2, 3.0]
# 11.0.divmod(-4) # => [-3, -1.0]
# -11.0.divmod(4) # => [-3, 1.0]
# -11.0.divmod(-4) # => [2, -3.0]
#
# 12.0.divmod(4) # => [3, 0.0]
# 12.0.divmod(-4) # => [-3, 0.0]
# -12.0.divmod(4) # => [-3, -0.0]
# -12.0.divmod(-4) # => [3, -0.0]
#
# 13.0.divmod(4.0) # => [3, 1.0]
# 13.0.divmod(Rational(4, 1)) # => [3, 1.0]
#
def divmod: (Integer | Float | Rational) -> [ Integer, Float ]
| (Numeric) -> [ Numeric, Numeric ]
def dup: () -> self
# <!--
# rdoc-file=numeric.c
# - eql?(other) -> true or false
# -->
# Returns `true` if `other` is a Float with the same value as `self`, `false`
# otherwise:
#
# 2.0.eql?(2.0) # => true
# 2.0.eql?(1.0) # => false
# 2.0.eql?(1) # => false
# 2.0.eql?(Rational(2, 1)) # => false
# 2.0.eql?(Complex(2, 0)) # => false
#
# `Float::NAN.eql?(Float::NAN)` returns an implementation-dependent value.
#
# Related: Float#== (performs type conversions).
#
def eql?: (untyped) -> bool
# <!-- rdoc-file=numeric.c -->
# Returns the quotient from dividing `self` by `other`:
#
# f = 3.14
# f.quo(2) # => 1.57
# f.quo(-2) # => -1.57
# f.quo(Rational(2, 1)) # => 1.57
# f.quo(Complex(2, 0)) # => (1.57+0.0i)
#
def fdiv: (Complex) -> Complex
| (Numeric) -> Float
# <!--
# rdoc-file=numeric.c
# - finite? -> true or false
# -->
# Returns `true` if `self` is not `Infinity`, `-Infinity`, or `NaN`, `false`
# otherwise:
#
# f = 2.0 # => 2.0
# f.finite? # => true
# f = 1.0/0.0 # => Infinity
# f.finite? # => false
# f = -1.0/0.0 # => -Infinity
# f.finite? # => false
# f = 0.0/0.0 # => NaN
# f.finite? # => false
#
def finite?: () -> bool
# <!--
# rdoc-file=numeric.c
# - floor(ndigits = 0) -> float or integer
# -->
# Returns the largest number less than or equal to `self` with a precision of
# `ndigits` decimal digits.
#
# When `ndigits` is positive, returns a float with `ndigits` digits after the
# decimal point (as available):
#
# f = 12345.6789
# f.floor(1) # => 12345.6
# f.floor(3) # => 12345.678
# f = -12345.6789
# f.floor(1) # => -12345.7
# f.floor(3) # => -12345.679
#
# When `ndigits` is non-positive, returns an integer with at least `ndigits.abs`
# trailing zeros:
#
# f = 12345.6789
# f.floor(0) # => 12345
# f.floor(-3) # => 12000
# f = -12345.6789
# f.floor(0) # => -12346
# f.floor(-3) # => -13000
#
# Note that the limited precision of floating-point arithmetic may lead to
# surprising results:
#
# (0.3 / 0.1).floor #=> 2 (!)
#
# Related: Float#ceil.
#
def floor: () -> Integer
| (int digits) -> (Integer | Numeric)
# <!--
# rdoc-file=numeric.c
# - hash -> integer
# -->
# Returns the integer hash value for `self`.
#
# See also Object#hash.
#
def hash: () -> Integer
def i: () -> Complex
def imag: () -> Integer
def imaginary: () -> Integer
# <!--
# rdoc-file=numeric.c
# - infinite? -> -1, 1, or nil
# -->
# Returns:
#
# * 1, if `self` is `Infinity`.
# * -1 if `self` is `-Infinity`.
# * `nil`, otherwise.
#
#
# Examples:
#
# f = 1.0/0.0 # => Infinity
# f.infinite? # => 1
# f = -1.0/0.0 # => -Infinity
# f.infinite? # => -1
# f = 1.0 # => 1.0
# f.infinite? # => nil
# f = 0.0/0.0 # => NaN
# f.infinite? # => nil
#
def infinite?: () -> Integer?
# <!-- rdoc-file=numeric.c -->
# Returns a string containing a representation of `self`; depending of the value
# of `self`, the string representation may contain:
#
# * A fixed-point number.
# * A number in "scientific notation" (containing an exponent).
# * 'Infinity'.
# * '-Infinity'.
# * 'NaN' (indicating not-a-number).
#
# 3.14.to_s # => "3.14" (10.1**50).to_s # =>
# "1.644631821843879e+50" (10.1**500).to_s # => "Infinity"
# (-10.1**500).to_s # => "-Infinity" (0.0/0.0).to_s # => "NaN"
#
alias inspect to_s
def integer?: () -> bool
# <!--
# rdoc-file=numeric.rb
# - magnitude()
# -->
#
alias magnitude abs
# <!-- rdoc-file=numeric.c -->
# Returns `self` modulo `other` as a float.
#
# For float `f` and real number `r`, these expressions are equivalent:
#
# f % r
# f-r*(f/r).floor
# f.divmod(r)[1]
#
# See Numeric#divmod.
#
# Examples:
#
# 10.0 % 2 # => 0.0
# 10.0 % 3 # => 1.0
# 10.0 % 4 # => 2.0
#
# 10.0 % -2 # => 0.0
# 10.0 % -3 # => -2.0
# 10.0 % -4 # => -2.0
#
# 10.0 % 4.0 # => 2.0
# 10.0 % Rational(4, 1) # => 2.0
#
def modulo: (Numeric) -> Float
# <!--
# rdoc-file=numeric.c
# - nan? -> true or false
# -->
# Returns `true` if `self` is a NaN, `false` otherwise.
#
# f = -1.0 #=> -1.0
# f.nan? #=> false
# f = 0.0/0.0 #=> NaN
# f.nan? #=> true
#
def nan?: () -> bool
# <!--
# rdoc-file=numeric.rb
# - negative? -> true or false
# -->
# Returns `true` if `self` is less than 0, `false` otherwise.
#
def negative?: () -> bool
# <!--
# rdoc-file=numeric.c
# - next_float -> float
# -->
# Returns the next-larger representable Float.
#
# These examples show the internally stored values (64-bit hexadecimal) for each
# Float `f` and for the corresponding `f.next_float`:
#
# f = 0.0 # 0x0000000000000000
# f.next_float # 0x0000000000000001
#
# f = 0.01 # 0x3f847ae147ae147b
# f.next_float # 0x3f847ae147ae147c
#
# In the remaining examples here, the output is shown in the usual way (result
# `to_s`):
#
# 0.01.next_float # => 0.010000000000000002
# 1.0.next_float # => 1.0000000000000002
# 100.0.next_float # => 100.00000000000001
#
# f = 0.01
# (0..3).each_with_index {|i| printf "%2d %-20a %s\n", i, f, f.to_s; f = f.next_float }
#
# Output:
#
# 0 0x1.47ae147ae147bp-7 0.01
# 1 0x1.47ae147ae147cp-7 0.010000000000000002
# 2 0x1.47ae147ae147dp-7 0.010000000000000004
# 3 0x1.47ae147ae147ep-7 0.010000000000000005
#
# f = 0.0; 100.times { f += 0.1 }
# f # => 9.99999999999998 # should be 10.0 in the ideal world.
# 10-f # => 1.9539925233402755e-14 # the floating point error.
# 10.0.next_float-10 # => 1.7763568394002505e-15 # 1 ulp (unit in the last place).
# (10-f)/(10.0.next_float-10) # => 11.0 # the error is 11 ulp.
# (10-f)/(10*Float::EPSILON) # => 8.8 # approximation of the above.
# "%a" % 10 # => "0x1.4p+3"
# "%a" % f # => "0x1.3fffffffffff5p+3" # the last hex digit is 5. 16 - 5 = 11 ulp.
#
# Related: Float#prev_float
#
def next_float: () -> Float
def nonzero?: () -> self?
# <!--
# rdoc-file=rational.c
# - flo.numerator -> integer
# -->
# Returns the numerator. The result is machine dependent.
#
# n = 0.3.numerator #=> 5404319552844595
# d = 0.3.denominator #=> 18014398509481984
# n.fdiv(d) #=> 0.3
#
# See also Float#denominator.
#
def numerator: () -> Integer
# <!-- rdoc-file=complex.c -->
# Returns 0 if `self` is positive, Math::PI otherwise.
#
alias phase angle
def polar: () -> [ Float, Integer | Float ]
# <!--
# rdoc-file=numeric.rb
# - positive? -> true or false
# -->
# Returns `true` if `self` is greater than 0, `false` otherwise.
#
def positive?: () -> bool
# <!--
# rdoc-file=numeric.c
# - float.prev_float -> float
# -->
# Returns the next-smaller representable Float.
#
# These examples show the internally stored values (64-bit hexadecimal) for each
# Float `f` and for the corresponding `f.pev_float`:
#
# f = 5e-324 # 0x0000000000000001
# f.prev_float # 0x0000000000000000
#
# f = 0.01 # 0x3f847ae147ae147b
# f.prev_float # 0x3f847ae147ae147a
#
# In the remaining examples here, the output is shown in the usual way (result
# `to_s`):
#
# 0.01.prev_float # => 0.009999999999999998
# 1.0.prev_float # => 0.9999999999999999
# 100.0.prev_float # => 99.99999999999999
#
# f = 0.01
# (0..3).each_with_index {|i| printf "%2d %-20a %s\n", i, f, f.to_s; f = f.prev_float }
#
# Output:
#
# 0 0x1.47ae147ae147bp-7 0.01
# 1 0x1.47ae147ae147ap-7 0.009999999999999998
# 2 0x1.47ae147ae1479p-7 0.009999999999999997
# 3 0x1.47ae147ae1478p-7 0.009999999999999995
#
# Related: Float#next_float.
#
def prev_float: () -> Float
# <!--
# rdoc-file=numeric.c
# - quo(other) -> numeric
# -->
# Returns the quotient from dividing `self` by `other`:
#
# f = 3.14
# f.quo(2) # => 1.57
# f.quo(-2) # => -1.57
# f.quo(Rational(2, 1)) # => 1.57
# f.quo(Complex(2, 0)) # => (1.57+0.0i)
#
def quo: (Complex) -> Complex
| (Numeric) -> Float
# <!--
# rdoc-file=rational.c
# - flt.rationalize([eps]) -> rational
# -->
# Returns a simpler approximation of the value (flt-|eps| <= result <=
# flt+|eps|). If the optional argument `eps` is not given, it will be chosen
# automatically.
#
# 0.3.rationalize #=> (3/10)
# 1.333.rationalize #=> (1333/1000)
# 1.333.rationalize(0.01) #=> (4/3)
#
# See also Float#to_r.
#
def rationalize: (?Numeric eps) -> Rational
def real: () -> Float
def real?: () -> true
def rect: () -> [ Float, Numeric ]
alias rectangular rect
def remainder: (Numeric) -> Float
# <!--
# rdoc-file=numeric.c
# - round(ndigits = 0, half: :up]) -> integer or float
# -->
# Returns `self` rounded to the nearest value with a precision of `ndigits`
# decimal digits.
#
# When `ndigits` is non-negative, returns a float with `ndigits` after the
# decimal point (as available):
#
# f = 12345.6789
# f.round(1) # => 12345.7
# f.round(3) # => 12345.679
# f = -12345.6789
# f.round(1) # => -12345.7
# f.round(3) # => -12345.679
#
# When `ndigits` is negative, returns an integer with at least `ndigits.abs`
# trailing zeros:
#
# f = 12345.6789
# f.round(0) # => 12346
# f.round(-3) # => 12000
# f = -12345.6789
# f.round(0) # => -12346
# f.round(-3) # => -12000
#
# If keyword argument `half` is given, and `self` is equidistant from the two
# candidate values, the rounding is according to the given `half` value:
#
# * `:up` or `nil`: round away from zero:
#
# 2.5.round(half: :up) # => 3
# 3.5.round(half: :up) # => 4
# (-2.5).round(half: :up) # => -3
#
# * `:down`: round toward zero:
#
# 2.5.round(half: :down) # => 2
# 3.5.round(half: :down) # => 3
# (-2.5).round(half: :down) # => -2
#
# * `:even`: round toward the candidate whose last nonzero digit is even:
#
# 2.5.round(half: :even) # => 2
# 3.5.round(half: :even) # => 4
# (-2.5).round(half: :even) # => -2
#
#
# Raises and exception if the value for `half` is invalid.
#
# Related: Float#truncate.
#
def round: (?half: :up | :down | :even) -> Integer
| (int digits, ?half: :up | :down | :even) -> (Integer | Float)
def step: (?Numeric limit, ?Numeric step) { (Float) -> void } -> self
| (?Numeric limit, ?Numeric step) -> Enumerator[Float, self]
| (?by: Numeric, ?to: Numeric) { (Float) -> void } -> self
| (?by: Numeric, ?to: Numeric) -> Enumerator[Float, self]
def to_c: () -> Complex
# <!--
# rdoc-file=numeric.rb
# - to_f -> self
# -->
# Returns `self` (which is already a Float).
#
def to_f: () -> Float
# <!--
# rdoc-file=numeric.c
# - to_i -> integer
# -->
# Returns `self` truncated to an Integer.
#
# 1.2.to_i # => 1
# (-1.2).to_i # => -1
#
# Note that the limited precision of floating-point arithmetic may lead to
# surprising results:
#
# (0.3 / 0.1).to_i # => 2 (!)
#
def to_i: () -> Integer
# <!-- rdoc-file=numeric.c -->
# Returns `self` truncated to an Integer.
#
# 1.2.to_i # => 1
# (-1.2).to_i # => -1
#
# Note that the limited precision of floating-point arithmetic may lead to
# surprising results:
#
# (0.3 / 0.1).to_i # => 2 (!)
#
alias to_int to_i
# <!--
# rdoc-file=rational.c
# - flt.to_r -> rational
# -->
# Returns the value as a rational.
#
# 2.0.to_r #=> (2/1)
# 2.5.to_r #=> (5/2)
# -0.75.to_r #=> (-3/4)
# 0.0.to_r #=> (0/1)
# 0.3.to_r #=> (5404319552844595/18014398509481984)
#
# NOTE: 0.3.to_r isn't the same as "0.3".to_r. The latter is equivalent to
# "3/10".to_r, but the former isn't so.
#
# 0.3.to_r == 3/10r #=> false
# "0.3".to_r == 3/10r #=> true
#
# See also Float#rationalize.
#
def to_r: () -> Rational
# <!--
# rdoc-file=numeric.c
# - to_s -> string
# -->
# Returns a string containing a representation of `self`; depending of the value
# of `self`, the string representation may contain:
#
# * A fixed-point number.
# * A number in "scientific notation" (containing an exponent).
# * 'Infinity'.
# * '-Infinity'.
# * 'NaN' (indicating not-a-number).
#
# 3.14.to_s # => "3.14" (10.1**50).to_s # =>
# "1.644631821843879e+50" (10.1**500).to_s # => "Infinity"
# (-10.1**500).to_s # => "-Infinity" (0.0/0.0).to_s # => "NaN"
#
def to_s: () -> String
# <!--
# rdoc-file=numeric.c
# - truncate(ndigits = 0) -> float or integer
# -->
# Returns `self` truncated (toward zero) to a precision of `ndigits` decimal
# digits.
#
# When `ndigits` is positive, returns a float with `ndigits` digits after the
# decimal point (as available):
#
# f = 12345.6789
# f.truncate(1) # => 12345.6
# f.truncate(3) # => 12345.678
# f = -12345.6789
# f.truncate(1) # => -12345.6
# f.truncate(3) # => -12345.678
#
# When `ndigits` is negative, returns an integer with at least `ndigits.abs`
# trailing zeros:
#
# f = 12345.6789
# f.truncate(0) # => 12345
# f.truncate(-3) # => 12000
# f = -12345.6789
# f.truncate(0) # => -12345
# f.truncate(-3) # => -12000
#
# Note that the limited precision of floating-point arithmetic may lead to
# surprising results:
#
# (0.3 / 0.1).truncate #=> 2 (!)
#
# Related: Float#round.
#
def truncate: () -> Integer
| (Integer ndigits) -> (Integer | Float)
# <!--
# rdoc-file=numeric.rb
# - zero? -> true or false
# -->
# Returns `true` if `self` is 0.0, `false` otherwise.
#
def zero?: () -> bool
end
# <!-- rdoc-file=numeric.c -->
# The minimum number of significant decimal digits in a double-precision
# floating point.
#
# Usually defaults to 15.
#
Float::DIG: Integer
# <!-- rdoc-file=numeric.c -->
# The difference between 1 and the smallest double-precision floating point
# number greater than 1.