rbs 0.13.1 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +1 -1
- data/.gitignore +0 -1
- data/CHANGELOG.md +7 -2
- data/Gemfile +3 -0
- data/README.md +8 -2
- data/Steepfile +1 -0
- data/bin/annotate-with-rdoc +1 -1
- data/bin/setup +0 -2
- data/docs/CONTRIBUTING.md +1 -0
- data/goodcheck.yml +22 -5
- data/lib/rbs/ast/comment.rb +1 -1
- data/lib/rbs/definition_builder.rb +4 -5
- data/lib/rbs/environment.rb +1 -1
- data/lib/rbs/namespace.rb +1 -1
- data/lib/rbs/parser.rb +3146 -0
- data/lib/rbs/parser.y +7 -2
- data/lib/rbs/test/setup_helper.rb +4 -4
- data/lib/rbs/test/type_check.rb +2 -2
- data/lib/rbs/type_name.rb +1 -1
- data/lib/rbs/variance_calculator.rb +1 -1
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +1 -1
- data/sig/constant.rbs +2 -2
- data/sig/constant_table.rbs +10 -10
- data/sig/declarations.rbs +1 -1
- data/sig/definition.rbs +1 -1
- data/sig/namespace.rbs +3 -3
- data/sig/parser.rbs +25 -0
- data/sig/substitution.rbs +3 -3
- data/sig/typename.rbs +1 -1
- data/sig/types.rbs +1 -1
- data/sig/writer.rbs +15 -15
- data/stdlib/benchmark/benchmark.rbs +2 -2
- data/stdlib/builtin/basic_object.rbs +54 -54
- data/stdlib/builtin/binding.rbs +42 -42
- data/stdlib/builtin/class.rbs +33 -33
- data/stdlib/builtin/complex.rbs +90 -90
- data/stdlib/builtin/encoding.rbs +33 -33
- data/stdlib/builtin/enumerable.rbs +32 -32
- data/stdlib/builtin/enumerator.rbs +35 -35
- data/stdlib/builtin/errors.rbs +1 -1
- data/stdlib/builtin/exception.rbs +50 -50
- data/stdlib/builtin/false_class.rbs +6 -6
- data/stdlib/builtin/fiber.rbs +14 -14
- data/stdlib/builtin/fiber_error.rbs +1 -1
- data/stdlib/builtin/float.rbs +161 -161
- data/stdlib/builtin/gc.rbs +1 -1
- data/stdlib/builtin/io.rbs +83 -83
- data/stdlib/builtin/kernel.rbs +69 -69
- data/stdlib/builtin/match_data.rbs +1 -1
- data/stdlib/builtin/method.rbs +19 -19
- data/stdlib/builtin/nil_class.rbs +20 -20
- data/stdlib/builtin/numeric.rbs +101 -101
- data/stdlib/builtin/object.rbs +172 -172
- data/stdlib/builtin/proc.rbs +91 -91
- data/stdlib/builtin/range.rbs +2 -4
- data/stdlib/builtin/rational.rbs +83 -83
- data/stdlib/builtin/signal.rbs +7 -7
- data/stdlib/builtin/string.rbs +4 -4
- data/stdlib/builtin/string_io.rbs +1 -1
- data/stdlib/builtin/thread.rbs +185 -185
- data/stdlib/builtin/thread_group.rbs +2 -2
- data/stdlib/builtin/true_class.rbs +9 -9
- data/stdlib/builtin/warning.rbs +1 -1
- data/stdlib/date/date.rbs +2 -2
- data/stdlib/find/find.rbs +10 -10
- data/stdlib/pathname/pathname.rbs +1 -1
- data/stdlib/tmpdir/tmpdir.rbs +12 -12
- metadata +3 -2
data/stdlib/builtin/errors.rbs
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
class ArgumentError < StandardError
|
21
21
|
end
|
22
22
|
|
23
|
-
# The exception class which will be raised when pushing into a closed Queue.
|
23
|
+
# The exception class which will be raised when pushing into a closed Queue.
|
24
24
|
# See Queue#close and SizedQueue#close.
|
25
25
|
#
|
26
26
|
class ClosedQueueError < StopIteration
|
@@ -9,19 +9,19 @@
|
|
9
9
|
# information like
|
10
10
|
# [NameError\#name](https://ruby-doc.org/core-2.6.3/NameError.html#method-i-name)
|
11
11
|
# .
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# Programs may make subclasses of
|
14
14
|
# [Exception](Exception), typically of
|
15
15
|
# [StandardError](https://ruby-doc.org/core-2.6.3/StandardError.html) or
|
16
16
|
# [RuntimeError](https://ruby-doc.org/core-2.6.3/RuntimeError.html), to
|
17
17
|
# provide custom classes and add additional information. See the subclass
|
18
18
|
# list below for defaults for `raise` and `rescue` .
|
19
|
-
#
|
19
|
+
#
|
20
20
|
# When an exception has been raised but not yet handled (in `rescue`,
|
21
21
|
# `ensure`, `at_exit` and `END` blocks) the global variable `$!` will
|
22
22
|
# contain the current exception and `$@` contains the current exception’s
|
23
23
|
# backtrace.
|
24
|
-
#
|
24
|
+
#
|
25
25
|
# It is recommended that a library should have one subclass of
|
26
26
|
# [StandardError](https://ruby-doc.org/core-2.6.3/StandardError.html) or
|
27
27
|
# [RuntimeError](https://ruby-doc.org/core-2.6.3/RuntimeError.html) and
|
@@ -29,97 +29,97 @@
|
|
29
29
|
# rescue a generic exception type to catch all exceptions the library may
|
30
30
|
# raise even if future versions of the library add new exception
|
31
31
|
# subclasses.
|
32
|
-
#
|
32
|
+
#
|
33
33
|
# For example:
|
34
|
-
#
|
34
|
+
#
|
35
35
|
# ```ruby
|
36
36
|
# class MyLibrary
|
37
37
|
# class Error < RuntimeError
|
38
38
|
# end
|
39
|
-
#
|
39
|
+
#
|
40
40
|
# class WidgetError < Error
|
41
41
|
# end
|
42
|
-
#
|
42
|
+
#
|
43
43
|
# class FrobError < Error
|
44
44
|
# end
|
45
|
-
#
|
45
|
+
#
|
46
46
|
# end
|
47
47
|
# ```
|
48
|
-
#
|
48
|
+
#
|
49
49
|
# To handle both WidgetError and FrobError the library user can rescue
|
50
50
|
# MyLibrary::Error.
|
51
|
-
#
|
51
|
+
#
|
52
52
|
# The built-in subclasses of [Exception](Exception)
|
53
53
|
# are:
|
54
|
-
#
|
54
|
+
#
|
55
55
|
# - [NoMemoryError](https://ruby-doc.org/core-2.6.3/NoMemoryError.html)
|
56
|
-
#
|
56
|
+
#
|
57
57
|
# - [ScriptError](https://ruby-doc.org/core-2.6.3/ScriptError.html)
|
58
|
-
#
|
58
|
+
#
|
59
59
|
# - [LoadError](https://ruby-doc.org/core-2.6.3/LoadError.html)
|
60
|
-
#
|
60
|
+
#
|
61
61
|
# - [NotImplementedError](https://ruby-doc.org/core-2.6.3/NotImplementedError.html)
|
62
|
-
#
|
62
|
+
#
|
63
63
|
# - [SyntaxError](https://ruby-doc.org/core-2.6.3/SyntaxError.html)
|
64
|
-
#
|
64
|
+
#
|
65
65
|
# - [SecurityError](https://ruby-doc.org/core-2.6.3/SecurityError.html)
|
66
|
-
#
|
66
|
+
#
|
67
67
|
# - [SignalException](https://ruby-doc.org/core-2.6.3/SignalException.html)
|
68
|
-
#
|
68
|
+
#
|
69
69
|
# - [Interrupt](https://ruby-doc.org/core-2.6.3/Interrupt.html)
|
70
|
-
#
|
70
|
+
#
|
71
71
|
# - [StandardError](https://ruby-doc.org/core-2.6.3/StandardError.html)
|
72
72
|
# -- default for `rescue`
|
73
|
-
#
|
73
|
+
#
|
74
74
|
# - [ArgumentError](https://ruby-doc.org/core-2.6.3/ArgumentError.html)
|
75
|
-
#
|
75
|
+
#
|
76
76
|
# - [UncaughtThrowError](https://ruby-doc.org/core-2.6.3/UncaughtThrowError.html)
|
77
|
-
#
|
77
|
+
#
|
78
78
|
# - [EncodingError](https://ruby-doc.org/core-2.6.3/EncodingError.html)
|
79
|
-
#
|
79
|
+
#
|
80
80
|
# - [FiberError](https://ruby-doc.org/core-2.6.3/FiberError.html)
|
81
|
-
#
|
81
|
+
#
|
82
82
|
# - [IOError](https://ruby-doc.org/core-2.6.3/IOError.html)
|
83
|
-
#
|
83
|
+
#
|
84
84
|
# - [EOFError](https://ruby-doc.org/core-2.6.3/EOFError.html)
|
85
|
-
#
|
85
|
+
#
|
86
86
|
# - [IndexError](https://ruby-doc.org/core-2.6.3/IndexError.html)
|
87
|
-
#
|
87
|
+
#
|
88
88
|
# - [KeyError](https://ruby-doc.org/core-2.6.3/KeyError.html)
|
89
|
-
#
|
89
|
+
#
|
90
90
|
# - [StopIteration](https://ruby-doc.org/core-2.6.3/StopIteration.html)
|
91
|
-
#
|
91
|
+
#
|
92
92
|
# - [LocalJumpError](https://ruby-doc.org/core-2.6.3/LocalJumpError.html)
|
93
|
-
#
|
93
|
+
#
|
94
94
|
# - [NameError](https://ruby-doc.org/core-2.6.3/NameError.html)
|
95
|
-
#
|
95
|
+
#
|
96
96
|
# - [NoMethodError](https://ruby-doc.org/core-2.6.3/NoMethodError.html)
|
97
|
-
#
|
97
|
+
#
|
98
98
|
# - [RangeError](https://ruby-doc.org/core-2.6.3/RangeError.html)
|
99
|
-
#
|
99
|
+
#
|
100
100
|
# - [FloatDomainError](https://ruby-doc.org/core-2.6.3/FloatDomainError.html)
|
101
|
-
#
|
101
|
+
#
|
102
102
|
# - [RegexpError](https://ruby-doc.org/core-2.6.3/RegexpError.html)
|
103
|
-
#
|
103
|
+
#
|
104
104
|
# - [RuntimeError](https://ruby-doc.org/core-2.6.3/RuntimeError.html)
|
105
105
|
# -- default for `raise`
|
106
|
-
#
|
106
|
+
#
|
107
107
|
# - [FrozenError](https://ruby-doc.org/core-2.6.3/FrozenError.html)
|
108
|
-
#
|
108
|
+
#
|
109
109
|
# - [SystemCallError](https://ruby-doc.org/core-2.6.3/SystemCallError.html)
|
110
|
-
#
|
110
|
+
#
|
111
111
|
# - Errno::\*
|
112
|
-
#
|
112
|
+
#
|
113
113
|
# - [ThreadError](https://ruby-doc.org/core-2.6.3/ThreadError.html)
|
114
|
-
#
|
114
|
+
#
|
115
115
|
# - [TypeError](https://ruby-doc.org/core-2.6.3/TypeError.html)
|
116
|
-
#
|
116
|
+
#
|
117
117
|
# - [ZeroDivisionError](https://ruby-doc.org/core-2.6.3/ZeroDivisionError.html)
|
118
|
-
#
|
118
|
+
#
|
119
119
|
# - [SystemExit](https://ruby-doc.org/core-2.6.3/SystemExit.html)
|
120
|
-
#
|
120
|
+
#
|
121
121
|
# - [SystemStackError](https://ruby-doc.org/core-2.6.3/SystemStackError.html)
|
122
|
-
#
|
122
|
+
#
|
123
123
|
# - fatal – impossible to rescue
|
124
124
|
class Exception < Object
|
125
125
|
def self.to_tty?: () -> bool
|
@@ -131,25 +131,25 @@ class Exception < Object
|
|
131
131
|
# Returns any backtrace associated with the exception. The backtrace is an
|
132
132
|
# array of strings, each containing either “filename:lineNo: in \`method”‘
|
133
133
|
# or “filename:lineNo.”
|
134
|
-
#
|
134
|
+
#
|
135
135
|
# ```ruby
|
136
136
|
# def a
|
137
137
|
# raise "boom"
|
138
138
|
# end
|
139
|
-
#
|
139
|
+
#
|
140
140
|
# def b
|
141
141
|
# a()
|
142
142
|
# end
|
143
|
-
#
|
143
|
+
#
|
144
144
|
# begin
|
145
145
|
# b()
|
146
146
|
# rescue => detail
|
147
147
|
# print detail.backtrace.join("\n")
|
148
148
|
# end
|
149
149
|
# ```
|
150
|
-
#
|
150
|
+
#
|
151
151
|
# *produces:*
|
152
|
-
#
|
152
|
+
#
|
153
153
|
# prog.rb:2:in `a'
|
154
154
|
# prog.rb:6:in `b'
|
155
155
|
# prog.rb:10
|
@@ -161,7 +161,7 @@ class Exception < Object
|
|
161
161
|
# the backtrace is an array of
|
162
162
|
# [Thread::Backtrace::Location](https://ruby-doc.org/core-2.6.3/Thread/Backtrace/Location.html)
|
163
163
|
# .
|
164
|
-
#
|
164
|
+
#
|
165
165
|
# Now, this method is not affected by
|
166
166
|
# [\#set\_backtrace](Exception.downloaded.ruby_doc#method-i-set_backtrace)
|
167
167
|
# .
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# The global value `false` is the only instance of class FalseClass and
|
2
2
|
# represents a logically false value in boolean expressions. The class provides
|
3
3
|
# operators allowing `false` to participate correctly in logical expressions.
|
4
|
-
#
|
4
|
+
#
|
5
5
|
class FalseClass
|
6
6
|
public
|
7
7
|
|
@@ -9,19 +9,19 @@ class FalseClass
|
|
9
9
|
|
10
10
|
# And---Returns `false`. *obj* is always evaluated as it is the argument to a
|
11
11
|
# method call---there is no short-circuit evaluation in this case.
|
12
|
-
#
|
12
|
+
#
|
13
13
|
def &: (untyped obj) -> bool
|
14
14
|
|
15
15
|
# Case Equality -- For class Object, effectively the same as calling `#==`, but
|
16
16
|
# typically overridden by descendants to provide meaningful semantics in `case`
|
17
17
|
# statements.
|
18
|
-
#
|
18
|
+
#
|
19
19
|
def ===: (false) -> true
|
20
20
|
| (untyped obj) -> bool
|
21
21
|
|
22
22
|
# Exclusive Or---If *obj* is `nil` or `false`, returns `false`; otherwise,
|
23
23
|
# returns `true`.
|
24
|
-
#
|
24
|
+
#
|
25
25
|
def ^: (nil) -> false
|
26
26
|
| (false) -> false
|
27
27
|
| (untyped obj) -> bool
|
@@ -29,11 +29,11 @@ class FalseClass
|
|
29
29
|
alias inspect to_s
|
30
30
|
|
31
31
|
# The string representation of `false` is "false".
|
32
|
-
#
|
32
|
+
#
|
33
33
|
def to_s: () -> "false"
|
34
34
|
|
35
35
|
# Or---Returns `false` if *obj* is `nil` or `false`; `true` otherwise.
|
36
|
-
#
|
36
|
+
#
|
37
37
|
def |: (nil) -> false
|
38
38
|
| (false) -> false
|
39
39
|
| (untyped obj) -> bool
|
data/stdlib/builtin/fiber.rbs
CHANGED
@@ -3,59 +3,59 @@
|
|
3
3
|
# that can be paused and resumed, much like threads. The main difference
|
4
4
|
# is that they are never preempted and that the scheduling must be done by
|
5
5
|
# the programmer and not the VM.
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# As opposed to other stackless light weight concurrency models, each
|
8
8
|
# fiber comes with a stack. This enables the fiber to be paused from
|
9
9
|
# deeply nested function calls within the fiber block. See the ruby(1)
|
10
10
|
# manpage to configure the size of the fiber stack(s).
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# When a fiber is created it will not run automatically. Rather it must be
|
13
13
|
# explicitly asked to run using the `Fiber#resume` method. The code
|
14
14
|
# running inside the fiber can give up control by calling `Fiber.yield` in
|
15
15
|
# which case it yields control back to caller (the caller of the
|
16
16
|
# `Fiber#resume` ).
|
17
|
-
#
|
17
|
+
#
|
18
18
|
# Upon yielding or termination the [Fiber](Fiber)
|
19
19
|
# returns the value of the last executed expression
|
20
|
-
#
|
20
|
+
#
|
21
21
|
# For instance:
|
22
|
-
#
|
22
|
+
#
|
23
23
|
# ```ruby
|
24
24
|
# fiber = Fiber.new do
|
25
25
|
# Fiber.yield 1
|
26
26
|
# 2
|
27
27
|
# end
|
28
|
-
#
|
28
|
+
#
|
29
29
|
# puts fiber.resume
|
30
30
|
# puts fiber.resume
|
31
31
|
# puts fiber.resume
|
32
32
|
# ```
|
33
|
-
#
|
33
|
+
#
|
34
34
|
# *produces*
|
35
|
-
#
|
35
|
+
#
|
36
36
|
# 1
|
37
37
|
# 2
|
38
38
|
# FiberError: dead fiber called
|
39
|
-
#
|
39
|
+
#
|
40
40
|
# The `Fiber#resume` method accepts an arbitrary number of parameters, if
|
41
41
|
# it is the first call to `resume` then they will be passed as block
|
42
42
|
# arguments. Otherwise they will be the return value of the call to
|
43
43
|
# `Fiber.yield`
|
44
|
-
#
|
44
|
+
#
|
45
45
|
# Example:
|
46
|
-
#
|
46
|
+
#
|
47
47
|
# ```ruby
|
48
48
|
# fiber = Fiber.new do |first|
|
49
49
|
# second = Fiber.yield first + 2
|
50
50
|
# end
|
51
|
-
#
|
51
|
+
#
|
52
52
|
# puts fiber.resume 10
|
53
53
|
# puts fiber.resume 14
|
54
54
|
# puts fiber.resume 18
|
55
55
|
# ```
|
56
|
-
#
|
56
|
+
#
|
57
57
|
# *produces*
|
58
|
-
#
|
58
|
+
#
|
59
59
|
# 12
|
60
60
|
# 14
|
61
61
|
# FiberError: dead fiber called
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# [Fiber](https://ruby-doc.org/core-2.6.3/Fiber.html), in particular when
|
3
3
|
# attempting to call/resume a dead fiber, attempting to yield from the
|
4
4
|
# root fiber, or calling a fiber across threads.
|
5
|
-
#
|
5
|
+
#
|
6
6
|
# ```ruby
|
7
7
|
# fiber = Fiber.new{}
|
8
8
|
# fiber.resume #=> nil
|
data/stdlib/builtin/float.rbs
CHANGED
@@ -1,158 +1,158 @@
|
|
1
1
|
# Float objects represent inexact real numbers using the native architecture's
|
2
2
|
# double-precision floating point representation.
|
3
|
-
#
|
3
|
+
#
|
4
4
|
# Floating point has a different arithmetic and is an inexact number. So you
|
5
5
|
# should know its esoteric system. See following:
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# * http://docs.sun.com/source/806-3568/ncg_goldberg.html
|
8
8
|
# * https://github.com/rdp/ruby_tutorials_core/wiki/Ruby-Talk-FAQ#floats_impre
|
9
9
|
# cise
|
10
10
|
# * http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems
|
11
|
-
#
|
12
|
-
#
|
11
|
+
#
|
12
|
+
#
|
13
13
|
class Float < Numeric
|
14
14
|
public
|
15
15
|
|
16
16
|
# Returns the modulo after division of `float` by `other`.
|
17
|
-
#
|
17
|
+
#
|
18
18
|
# 6543.21.modulo(137) #=> 104.21000000000004
|
19
19
|
# 6543.21.modulo(137.24) #=> 92.92999999999961
|
20
|
-
#
|
20
|
+
#
|
21
21
|
def %: (Integer) -> Float
|
22
22
|
| (Float) -> Float
|
23
23
|
| (Rational) -> Float
|
24
24
|
| (Numeric) -> Numeric
|
25
25
|
|
26
26
|
# Returns a new Float which is the product of `float` and `other`.
|
27
|
-
#
|
27
|
+
#
|
28
28
|
def *: (Complex) -> Complex
|
29
29
|
| (Numeric) -> Float
|
30
30
|
|
31
31
|
# Raises `float` to the power of `other`.
|
32
|
-
#
|
32
|
+
#
|
33
33
|
# 2.0**3 #=> 8.0
|
34
|
-
#
|
34
|
+
#
|
35
35
|
def **: (Complex) -> Complex
|
36
36
|
| (Numeric) -> Float
|
37
37
|
|
38
38
|
# Returns a new Float which is the sum of `float` and `other`.
|
39
|
-
#
|
39
|
+
#
|
40
40
|
def +: (Complex) -> Complex
|
41
41
|
| (Numeric) -> Float
|
42
42
|
|
43
43
|
def +@: () -> Float
|
44
44
|
|
45
45
|
# Returns a new Float which is the difference of `float` and `other`.
|
46
|
-
#
|
46
|
+
#
|
47
47
|
def -: (Complex) -> Complex
|
48
48
|
| (Numeric) -> Float
|
49
49
|
|
50
50
|
# Returns `float`, negated.
|
51
|
-
#
|
51
|
+
#
|
52
52
|
def -@: () -> Float
|
53
53
|
|
54
54
|
# Returns a new Float which is the result of dividing `float` by `other`.
|
55
|
-
#
|
55
|
+
#
|
56
56
|
def /: (Complex) -> Complex
|
57
57
|
| (Numeric) -> Float
|
58
58
|
|
59
59
|
# Returns `true` if `float` is less than `real`.
|
60
|
-
#
|
60
|
+
#
|
61
61
|
# The result of `NaN < NaN` is undefined, so an implementation-dependent value
|
62
62
|
# is returned.
|
63
|
-
#
|
63
|
+
#
|
64
64
|
def <: (Numeric) -> bool
|
65
65
|
|
66
66
|
# Returns `true` if `float` is less than or equal to `real`.
|
67
|
-
#
|
67
|
+
#
|
68
68
|
# The result of `NaN <= NaN` is undefined, so an implementation-dependent value
|
69
69
|
# is returned.
|
70
|
-
#
|
70
|
+
#
|
71
71
|
def <=: (Numeric) -> bool
|
72
72
|
|
73
73
|
# Returns -1, 0, or +1 depending on whether `float` is less than, equal to, or
|
74
74
|
# greater than `real`. This is the basis for the tests in the Comparable module.
|
75
|
-
#
|
75
|
+
#
|
76
76
|
# The result of `NaN <=> NaN` is undefined, so an implementation-dependent value
|
77
77
|
# is returned.
|
78
|
-
#
|
78
|
+
#
|
79
79
|
# `nil` is returned if the two values are incomparable.
|
80
|
-
#
|
80
|
+
#
|
81
81
|
def <=>: (Numeric) -> Integer?
|
82
82
|
|
83
83
|
# Returns `true` only if `obj` has the same value as `float`. Contrast this with
|
84
84
|
# Float#eql?, which requires `obj` to be a Float.
|
85
|
-
#
|
85
|
+
#
|
86
86
|
# 1.0 == 1 #=> true
|
87
|
-
#
|
87
|
+
#
|
88
88
|
# The result of `NaN == NaN` is undefined, so an implementation-dependent value
|
89
89
|
# is returned.
|
90
|
-
#
|
90
|
+
#
|
91
91
|
def ==: (untyped) -> bool
|
92
92
|
|
93
93
|
# Returns `true` only if `obj` has the same value as `float`. Contrast this with
|
94
94
|
# Float#eql?, which requires `obj` to be a Float.
|
95
|
-
#
|
95
|
+
#
|
96
96
|
# 1.0 == 1 #=> true
|
97
|
-
#
|
97
|
+
#
|
98
98
|
# The result of `NaN == NaN` is undefined, so an implementation-dependent value
|
99
99
|
# is returned.
|
100
|
-
#
|
100
|
+
#
|
101
101
|
def ===: (untyped) -> bool
|
102
102
|
|
103
103
|
# Returns `true` if `float` is greater than `real`.
|
104
|
-
#
|
104
|
+
#
|
105
105
|
# The result of `NaN > NaN` is undefined, so an implementation-dependent value
|
106
106
|
# is returned.
|
107
|
-
#
|
107
|
+
#
|
108
108
|
def >: (Numeric) -> bool
|
109
109
|
|
110
110
|
# Returns `true` if `float` is greater than or equal to `real`.
|
111
|
-
#
|
111
|
+
#
|
112
112
|
# The result of `NaN >= NaN` is undefined, so an implementation-dependent value
|
113
113
|
# is returned.
|
114
|
-
#
|
114
|
+
#
|
115
115
|
def >=: (Numeric) -> bool
|
116
116
|
|
117
117
|
# Returns the absolute value of `float`.
|
118
|
-
#
|
118
|
+
#
|
119
119
|
# (-34.56).abs #=> 34.56
|
120
120
|
# -34.56.abs #=> 34.56
|
121
121
|
# 34.56.abs #=> 34.56
|
122
|
-
#
|
122
|
+
#
|
123
123
|
# Float#magnitude is an alias for Float#abs.
|
124
|
-
#
|
124
|
+
#
|
125
125
|
def abs: () -> Float
|
126
126
|
|
127
127
|
def abs2: () -> Float
|
128
128
|
|
129
129
|
# Returns 0 if the value is positive, pi otherwise.
|
130
|
-
#
|
130
|
+
#
|
131
131
|
def angle: () -> (Integer | Float)
|
132
132
|
|
133
133
|
# Returns 0 if the value is positive, pi otherwise.
|
134
|
-
#
|
134
|
+
#
|
135
135
|
alias arg angle
|
136
136
|
|
137
137
|
# Returns the smallest number greater than or equal to `float` with a precision
|
138
138
|
# of `ndigits` decimal digits (default: 0).
|
139
|
-
#
|
139
|
+
#
|
140
140
|
# When the precision is negative, the returned value is an integer with at least
|
141
141
|
# `ndigits.abs` trailing zeros.
|
142
|
-
#
|
142
|
+
#
|
143
143
|
# Returns a floating point number when `ndigits` is positive, otherwise returns
|
144
144
|
# an integer.
|
145
|
-
#
|
145
|
+
#
|
146
146
|
# 1.2.ceil #=> 2
|
147
147
|
# 2.0.ceil #=> 2
|
148
148
|
# (-1.2).ceil #=> -1
|
149
149
|
# (-2.0).ceil #=> -2
|
150
|
-
#
|
150
|
+
#
|
151
151
|
# 1.234567.ceil(2) #=> 1.24
|
152
152
|
# 1.234567.ceil(3) #=> 1.235
|
153
153
|
# 1.234567.ceil(4) #=> 1.2346
|
154
154
|
# 1.234567.ceil(5) #=> 1.23457
|
155
|
-
#
|
155
|
+
#
|
156
156
|
# 34567.89.ceil(-5) #=> 100000
|
157
157
|
# 34567.89.ceil(-4) #=> 40000
|
158
158
|
# 34567.89.ceil(-3) #=> 35000
|
@@ -162,24 +162,24 @@ class Float < Numeric
|
|
162
162
|
# 34567.89.ceil(1) #=> 34567.9
|
163
163
|
# 34567.89.ceil(2) #=> 34567.89
|
164
164
|
# 34567.89.ceil(3) #=> 34567.89
|
165
|
-
#
|
165
|
+
#
|
166
166
|
# Note that the limited precision of floating point arithmetic might lead to
|
167
167
|
# surprising results:
|
168
|
-
#
|
168
|
+
#
|
169
169
|
# (2.1 / 0.7).ceil #=> 4 (!)
|
170
|
-
#
|
170
|
+
#
|
171
171
|
def ceil: () -> Integer
|
172
172
|
| (int digits) -> (Integer | Float)
|
173
173
|
|
174
174
|
def clone: (?freeze: bool) -> self
|
175
175
|
|
176
176
|
# Returns an array with both `numeric` and `float` represented as Float objects.
|
177
|
-
#
|
177
|
+
#
|
178
178
|
# This is achieved by converting `numeric` to a Float.
|
179
|
-
#
|
179
|
+
#
|
180
180
|
# 1.2.coerce(3) #=> [3.0, 1.2]
|
181
181
|
# 2.5.coerce(1.1) #=> [1.1, 2.5]
|
182
|
-
#
|
182
|
+
#
|
183
183
|
def coerce: (Numeric) -> [Numeric, Numeric]
|
184
184
|
|
185
185
|
def conj: () -> Float
|
@@ -187,61 +187,61 @@ class Float < Numeric
|
|
187
187
|
def conjugate: () -> Float
|
188
188
|
|
189
189
|
# Returns the denominator (always positive). The result is machine dependent.
|
190
|
-
#
|
190
|
+
#
|
191
191
|
# See also Float#numerator.
|
192
|
-
#
|
192
|
+
#
|
193
193
|
def denominator: () -> Integer
|
194
194
|
|
195
195
|
def div: (Numeric) -> Integer
|
196
196
|
|
197
197
|
# See Numeric#divmod.
|
198
|
-
#
|
198
|
+
#
|
199
199
|
# 42.0.divmod(6) #=> [7, 0.0]
|
200
200
|
# 42.0.divmod(5) #=> [8, 2.0]
|
201
|
-
#
|
201
|
+
#
|
202
202
|
def divmod: (Numeric) -> [Numeric, Numeric]
|
203
203
|
|
204
204
|
def dup: () -> self
|
205
205
|
|
206
206
|
# Returns `true` only if `obj` is a Float with the same value as `float`.
|
207
207
|
# Contrast this with Float#==, which performs type conversions.
|
208
|
-
#
|
208
|
+
#
|
209
209
|
# 1.0.eql?(1) #=> false
|
210
|
-
#
|
210
|
+
#
|
211
211
|
# The result of `NaN.eql?(NaN)` is undefined, so an implementation-dependent
|
212
212
|
# value is returned.
|
213
|
-
#
|
213
|
+
#
|
214
214
|
def eql?: (untyped) -> bool
|
215
215
|
|
216
216
|
# Returns `float / numeric`, same as Float#/.
|
217
|
-
#
|
217
|
+
#
|
218
218
|
def fdiv: (Complex) -> Complex
|
219
219
|
| (Numeric) -> Float
|
220
220
|
|
221
221
|
# Returns `true` if `float` is a valid IEEE floating point number, i.e. it is
|
222
222
|
# not infinite and Float#nan? is `false`.
|
223
|
-
#
|
223
|
+
#
|
224
224
|
def finite?: () -> bool
|
225
225
|
|
226
226
|
# Returns the largest number less than or equal to `float` with a precision of
|
227
227
|
# `ndigits` decimal digits (default: 0).
|
228
|
-
#
|
228
|
+
#
|
229
229
|
# When the precision is negative, the returned value is an integer with at least
|
230
230
|
# `ndigits.abs` trailing zeros.
|
231
|
-
#
|
231
|
+
#
|
232
232
|
# Returns a floating point number when `ndigits` is positive, otherwise returns
|
233
233
|
# an integer.
|
234
|
-
#
|
234
|
+
#
|
235
235
|
# 1.2.floor #=> 1
|
236
236
|
# 2.0.floor #=> 2
|
237
237
|
# (-1.2).floor #=> -2
|
238
238
|
# (-2.0).floor #=> -2
|
239
|
-
#
|
239
|
+
#
|
240
240
|
# 1.234567.floor(2) #=> 1.23
|
241
241
|
# 1.234567.floor(3) #=> 1.234
|
242
242
|
# 1.234567.floor(4) #=> 1.2345
|
243
243
|
# 1.234567.floor(5) #=> 1.23456
|
244
|
-
#
|
244
|
+
#
|
245
245
|
# 34567.89.floor(-5) #=> 0
|
246
246
|
# 34567.89.floor(-4) #=> 30000
|
247
247
|
# 34567.89.floor(-3) #=> 34000
|
@@ -251,19 +251,19 @@ class Float < Numeric
|
|
251
251
|
# 34567.89.floor(1) #=> 34567.8
|
252
252
|
# 34567.89.floor(2) #=> 34567.89
|
253
253
|
# 34567.89.floor(3) #=> 34567.89
|
254
|
-
#
|
254
|
+
#
|
255
255
|
# Note that the limited precision of floating point arithmetic might lead to
|
256
256
|
# surprising results:
|
257
|
-
#
|
257
|
+
#
|
258
258
|
# (0.3 / 0.1).floor #=> 2 (!)
|
259
|
-
#
|
259
|
+
#
|
260
260
|
def floor: () -> Integer
|
261
261
|
| (int digits) -> (Integer | Numeric)
|
262
262
|
|
263
263
|
# Returns a hash code for this float.
|
264
|
-
#
|
264
|
+
#
|
265
265
|
# See also Object#hash.
|
266
|
-
#
|
266
|
+
#
|
267
267
|
def hash: () -> Integer
|
268
268
|
|
269
269
|
def i: () -> Complex
|
@@ -274,11 +274,11 @@ class Float < Numeric
|
|
274
274
|
|
275
275
|
# Returns `nil`, -1, or 1 depending on whether the value is finite, `-Infinity`,
|
276
276
|
# or `+Infinity`.
|
277
|
-
#
|
277
|
+
#
|
278
278
|
# (0.0).infinite? #=> nil
|
279
279
|
# (-1.0/0.0).infinite? #=> -1
|
280
280
|
# (+1.0/0.0).infinite? #=> 1
|
281
|
-
#
|
281
|
+
#
|
282
282
|
def infinite?: () -> Integer?
|
283
283
|
|
284
284
|
alias inspect to_s
|
@@ -286,51 +286,51 @@ class Float < Numeric
|
|
286
286
|
def integer?: () -> bool
|
287
287
|
|
288
288
|
# Returns the absolute value of `float`.
|
289
|
-
#
|
289
|
+
#
|
290
290
|
# (-34.56).abs #=> 34.56
|
291
291
|
# -34.56.abs #=> 34.56
|
292
292
|
# 34.56.abs #=> 34.56
|
293
|
-
#
|
293
|
+
#
|
294
294
|
# Float#magnitude is an alias for Float#abs.
|
295
|
-
#
|
295
|
+
#
|
296
296
|
alias magnitude abs
|
297
297
|
|
298
298
|
# Returns the modulo after division of `float` by `other`.
|
299
|
-
#
|
299
|
+
#
|
300
300
|
# 6543.21.modulo(137) #=> 104.21000000000004
|
301
301
|
# 6543.21.modulo(137.24) #=> 92.92999999999961
|
302
|
-
#
|
302
|
+
#
|
303
303
|
def modulo: (Numeric) -> Float
|
304
304
|
|
305
305
|
# Returns `true` if `float` is an invalid IEEE floating point number.
|
306
|
-
#
|
306
|
+
#
|
307
307
|
# a = -1.0 #=> -1.0
|
308
308
|
# a.nan? #=> false
|
309
309
|
# a = 0.0/0.0 #=> NaN
|
310
310
|
# a.nan? #=> true
|
311
|
-
#
|
311
|
+
#
|
312
312
|
def nan?: () -> bool
|
313
313
|
|
314
314
|
# Returns `true` if `float` is less than 0.
|
315
|
-
#
|
315
|
+
#
|
316
316
|
def negative?: () -> bool
|
317
317
|
|
318
318
|
# Returns the next representable floating point number.
|
319
|
-
#
|
319
|
+
#
|
320
320
|
# Float::MAX.next_float and Float::INFINITY.next_float is Float::INFINITY.
|
321
|
-
#
|
321
|
+
#
|
322
322
|
# Float::NAN.next_float is Float::NAN.
|
323
|
-
#
|
323
|
+
#
|
324
324
|
# For example:
|
325
|
-
#
|
325
|
+
#
|
326
326
|
# 0.01.next_float #=> 0.010000000000000002
|
327
327
|
# 1.0.next_float #=> 1.0000000000000002
|
328
328
|
# 100.0.next_float #=> 100.00000000000001
|
329
|
-
#
|
329
|
+
#
|
330
330
|
# 0.01.next_float - 0.01 #=> 1.734723475976807e-18
|
331
331
|
# 1.0.next_float - 1.0 #=> 2.220446049250313e-16
|
332
332
|
# 100.0.next_float - 100.0 #=> 1.4210854715202004e-14
|
333
|
-
#
|
333
|
+
#
|
334
334
|
# f = 0.01; 20.times { printf "%-20a %s\n", f, f.to_s; f = f.next_float }
|
335
335
|
# #=> 0x1.47ae147ae147bp-7 0.01
|
336
336
|
# # 0x1.47ae147ae147cp-7 0.010000000000000002
|
@@ -352,7 +352,7 @@ class Float < Numeric
|
|
352
352
|
# # 0x1.47ae147ae148cp-7 0.01000000000000003
|
353
353
|
# # 0x1.47ae147ae148dp-7 0.010000000000000031
|
354
354
|
# # 0x1.47ae147ae148ep-7 0.010000000000000033
|
355
|
-
#
|
355
|
+
#
|
356
356
|
# f = 0.0
|
357
357
|
# 100.times { f += 0.1 }
|
358
358
|
# f #=> 9.99999999999998 # should be 10.0 in the ideal world.
|
@@ -362,48 +362,48 @@ class Float < Numeric
|
|
362
362
|
# (10-f)/(10*Float::EPSILON) #=> 8.8 # approximation of the above.
|
363
363
|
# "%a" % 10 #=> "0x1.4p+3"
|
364
364
|
# "%a" % f #=> "0x1.3fffffffffff5p+3" # the last hex digit is 5. 16 - 5 = 11 ulp.
|
365
|
-
#
|
365
|
+
#
|
366
366
|
def next_float: () -> Float
|
367
367
|
|
368
368
|
def nonzero?: () -> self?
|
369
369
|
|
370
370
|
# Returns the numerator. The result is machine dependent.
|
371
|
-
#
|
371
|
+
#
|
372
372
|
# n = 0.3.numerator #=> 5404319552844595
|
373
373
|
# d = 0.3.denominator #=> 18014398509481984
|
374
374
|
# n.fdiv(d) #=> 0.3
|
375
|
-
#
|
375
|
+
#
|
376
376
|
# See also Float#denominator.
|
377
|
-
#
|
377
|
+
#
|
378
378
|
def numerator: () -> Integer
|
379
379
|
|
380
380
|
# Returns 0 if the value is positive, pi otherwise.
|
381
|
-
#
|
381
|
+
#
|
382
382
|
alias phase angle
|
383
383
|
|
384
384
|
def polar: () -> [ Float, Integer | Float ]
|
385
385
|
|
386
386
|
# Returns `true` if `float` is greater than 0.
|
387
|
-
#
|
387
|
+
#
|
388
388
|
def positive?: () -> bool
|
389
389
|
|
390
390
|
# Returns the previous representable floating point number.
|
391
|
-
#
|
391
|
+
#
|
392
392
|
# (-Float::MAX).prev_float and (-Float::INFINITY).prev_float is
|
393
393
|
# -Float::INFINITY.
|
394
|
-
#
|
394
|
+
#
|
395
395
|
# Float::NAN.prev_float is Float::NAN.
|
396
|
-
#
|
396
|
+
#
|
397
397
|
# For example:
|
398
|
-
#
|
398
|
+
#
|
399
399
|
# 0.01.prev_float #=> 0.009999999999999998
|
400
400
|
# 1.0.prev_float #=> 0.9999999999999999
|
401
401
|
# 100.0.prev_float #=> 99.99999999999999
|
402
|
-
#
|
402
|
+
#
|
403
403
|
# 0.01 - 0.01.prev_float #=> 1.734723475976807e-18
|
404
404
|
# 1.0 - 1.0.prev_float #=> 1.1102230246251565e-16
|
405
405
|
# 100.0 - 100.0.prev_float #=> 1.4210854715202004e-14
|
406
|
-
#
|
406
|
+
#
|
407
407
|
# f = 0.01; 20.times { printf "%-20a %s\n", f, f.to_s; f = f.prev_float }
|
408
408
|
# #=> 0x1.47ae147ae147bp-7 0.01
|
409
409
|
# # 0x1.47ae147ae147ap-7 0.009999999999999998
|
@@ -425,24 +425,24 @@ class Float < Numeric
|
|
425
425
|
# # 0x1.47ae147ae146ap-7 0.00999999999999997
|
426
426
|
# # 0x1.47ae147ae1469p-7 0.009999999999999969
|
427
427
|
# # 0x1.47ae147ae1468p-7 0.009999999999999967
|
428
|
-
#
|
428
|
+
#
|
429
429
|
def prev_float: () -> Float
|
430
430
|
|
431
431
|
# Returns `float / numeric`, same as Float#/.
|
432
|
-
#
|
432
|
+
#
|
433
433
|
def quo: (Complex) -> Complex
|
434
434
|
| (Numeric) -> Float
|
435
435
|
|
436
436
|
# Returns a simpler approximation of the value (flt-|eps| <= result <=
|
437
437
|
# flt+|eps|). If the optional argument `eps` is not given, it will be chosen
|
438
438
|
# automatically.
|
439
|
-
#
|
439
|
+
#
|
440
440
|
# 0.3.rationalize #=> (3/10)
|
441
441
|
# 1.333.rationalize #=> (1333/1000)
|
442
442
|
# 1.333.rationalize(0.01) #=> (4/3)
|
443
|
-
#
|
443
|
+
#
|
444
444
|
# See also Float#to_r.
|
445
|
-
#
|
445
|
+
#
|
446
446
|
def rationalize: (?Numeric eps) -> Rational
|
447
447
|
|
448
448
|
def real: () -> Float
|
@@ -457,23 +457,23 @@ class Float < Numeric
|
|
457
457
|
|
458
458
|
# Returns `float` rounded to the nearest value with a precision of `ndigits`
|
459
459
|
# decimal digits (default: 0).
|
460
|
-
#
|
460
|
+
#
|
461
461
|
# When the precision is negative, the returned value is an integer with at least
|
462
462
|
# `ndigits.abs` trailing zeros.
|
463
|
-
#
|
463
|
+
#
|
464
464
|
# Returns a floating point number when `ndigits` is positive, otherwise returns
|
465
465
|
# an integer.
|
466
|
-
#
|
466
|
+
#
|
467
467
|
# 1.4.round #=> 1
|
468
468
|
# 1.5.round #=> 2
|
469
469
|
# 1.6.round #=> 2
|
470
470
|
# (-1.5).round #=> -2
|
471
|
-
#
|
471
|
+
#
|
472
472
|
# 1.234567.round(2) #=> 1.23
|
473
473
|
# 1.234567.round(3) #=> 1.235
|
474
474
|
# 1.234567.round(4) #=> 1.2346
|
475
475
|
# 1.234567.round(5) #=> 1.23457
|
476
|
-
#
|
476
|
+
#
|
477
477
|
# 34567.89.round(-5) #=> 0
|
478
478
|
# 34567.89.round(-4) #=> 30000
|
479
479
|
# 34567.89.round(-3) #=> 35000
|
@@ -483,15 +483,15 @@ class Float < Numeric
|
|
483
483
|
# 34567.89.round(1) #=> 34567.9
|
484
484
|
# 34567.89.round(2) #=> 34567.89
|
485
485
|
# 34567.89.round(3) #=> 34567.89
|
486
|
-
#
|
486
|
+
#
|
487
487
|
# If the optional `half` keyword argument is given, numbers that are half-way
|
488
488
|
# between two possible rounded values will be rounded according to the specified
|
489
489
|
# tie-breaking `mode`:
|
490
|
-
#
|
490
|
+
#
|
491
491
|
# * `:up` or `nil`: round half away from zero (default)
|
492
492
|
# * `:down`: round half toward zero
|
493
493
|
# * `:even`: round half toward the nearest even number
|
494
|
-
#
|
494
|
+
#
|
495
495
|
# 2.5.round(half: :up) #=> 3
|
496
496
|
# 2.5.round(half: :down) #=> 2
|
497
497
|
# 2.5.round(half: :even) #=> 2
|
@@ -501,7 +501,7 @@ class Float < Numeric
|
|
501
501
|
# (-2.5).round(half: :up) #=> -3
|
502
502
|
# (-2.5).round(half: :down) #=> -2
|
503
503
|
# (-2.5).round(half: :even) #=> -2
|
504
|
-
#
|
504
|
+
#
|
505
505
|
def round: (?half: :up | :down | :even) -> Integer
|
506
506
|
| (int digits, ?half: :up | :down | :even) -> (Integer | Float)
|
507
507
|
|
@@ -513,174 +513,174 @@ class Float < Numeric
|
|
513
513
|
def to_c: () -> Complex
|
514
514
|
|
515
515
|
# Since `float` is already a Float, returns `self`.
|
516
|
-
#
|
516
|
+
#
|
517
517
|
def to_f: () -> Float
|
518
518
|
|
519
519
|
# Returns the `float` truncated to an Integer.
|
520
|
-
#
|
520
|
+
#
|
521
521
|
# 1.2.to_i #=> 1
|
522
522
|
# (-1.2).to_i #=> -1
|
523
|
-
#
|
523
|
+
#
|
524
524
|
# Note that the limited precision of floating point arithmetic might lead to
|
525
525
|
# surprising results:
|
526
|
-
#
|
526
|
+
#
|
527
527
|
# (0.3 / 0.1).to_i #=> 2 (!)
|
528
|
-
#
|
528
|
+
#
|
529
529
|
# #to_int is an alias for #to_i.
|
530
|
-
#
|
530
|
+
#
|
531
531
|
def to_i: () -> Integer
|
532
532
|
|
533
533
|
# Returns the `float` truncated to an Integer.
|
534
|
-
#
|
534
|
+
#
|
535
535
|
# 1.2.to_i #=> 1
|
536
536
|
# (-1.2).to_i #=> -1
|
537
|
-
#
|
537
|
+
#
|
538
538
|
# Note that the limited precision of floating point arithmetic might lead to
|
539
539
|
# surprising results:
|
540
|
-
#
|
540
|
+
#
|
541
541
|
# (0.3 / 0.1).to_i #=> 2 (!)
|
542
|
-
#
|
542
|
+
#
|
543
543
|
# #to_int is an alias for #to_i.
|
544
|
-
#
|
544
|
+
#
|
545
545
|
alias to_int to_i
|
546
546
|
|
547
547
|
# Returns the value as a rational.
|
548
|
-
#
|
548
|
+
#
|
549
549
|
# 2.0.to_r #=> (2/1)
|
550
550
|
# 2.5.to_r #=> (5/2)
|
551
551
|
# -0.75.to_r #=> (-3/4)
|
552
552
|
# 0.0.to_r #=> (0/1)
|
553
553
|
# 0.3.to_r #=> (5404319552844595/18014398509481984)
|
554
|
-
#
|
554
|
+
#
|
555
555
|
# NOTE: 0.3.to_r isn't the same as "0.3".to_r. The latter is equivalent to
|
556
556
|
# "3/10".to_r, but the former isn't so.
|
557
|
-
#
|
557
|
+
#
|
558
558
|
# 0.3.to_r == 3/10r #=> false
|
559
559
|
# "0.3".to_r == 3/10r #=> true
|
560
|
-
#
|
560
|
+
#
|
561
561
|
# See also Float#rationalize.
|
562
|
-
#
|
562
|
+
#
|
563
563
|
def to_r: () -> Rational
|
564
564
|
|
565
565
|
# Returns a string containing a representation of `self`. As well as a fixed or
|
566
566
|
# exponential form of the `float`, the call may return `NaN`, `Infinity`, and
|
567
567
|
# `-Infinity`.
|
568
|
-
#
|
568
|
+
#
|
569
569
|
def to_s: () -> String
|
570
570
|
|
571
571
|
# Returns `float` truncated (toward zero) to a precision of `ndigits` decimal
|
572
572
|
# digits (default: 0).
|
573
|
-
#
|
573
|
+
#
|
574
574
|
# When the precision is negative, the returned value is an integer with at least
|
575
575
|
# `ndigits.abs` trailing zeros.
|
576
|
-
#
|
576
|
+
#
|
577
577
|
# Returns a floating point number when `ndigits` is positive, otherwise returns
|
578
578
|
# an integer.
|
579
|
-
#
|
579
|
+
#
|
580
580
|
# 2.8.truncate #=> 2
|
581
581
|
# (-2.8).truncate #=> -2
|
582
582
|
# 1.234567.truncate(2) #=> 1.23
|
583
583
|
# 34567.89.truncate(-2) #=> 34500
|
584
|
-
#
|
584
|
+
#
|
585
585
|
# Note that the limited precision of floating point arithmetic might lead to
|
586
586
|
# surprising results:
|
587
|
-
#
|
587
|
+
#
|
588
588
|
# (0.3 / 0.1).truncate #=> 2 (!)
|
589
|
-
#
|
589
|
+
#
|
590
590
|
def truncate: () -> Integer
|
591
591
|
| (Integer ndigits) -> (Integer | Float)
|
592
592
|
|
593
593
|
# Returns `true` if `float` is 0.0.
|
594
|
-
#
|
594
|
+
#
|
595
595
|
def zero?: () -> bool
|
596
596
|
end
|
597
597
|
|
598
598
|
# The minimum number of significant decimal digits in a double-precision
|
599
599
|
# floating point.
|
600
|
-
#
|
600
|
+
#
|
601
601
|
# Usually defaults to 15.
|
602
|
-
#
|
602
|
+
#
|
603
603
|
Float::DIG: Integer
|
604
604
|
|
605
605
|
# The difference between 1 and the smallest double-precision floating point
|
606
606
|
# number greater than 1.
|
607
|
-
#
|
607
|
+
#
|
608
608
|
# Usually defaults to 2.2204460492503131e-16.
|
609
|
-
#
|
609
|
+
#
|
610
610
|
Float::EPSILON: Float
|
611
611
|
|
612
612
|
# An expression representing positive infinity.
|
613
|
-
#
|
613
|
+
#
|
614
614
|
Float::INFINITY: Float
|
615
615
|
|
616
616
|
# The number of base digits for the `double` data type.
|
617
|
-
#
|
617
|
+
#
|
618
618
|
# Usually defaults to 53.
|
619
|
-
#
|
619
|
+
#
|
620
620
|
Float::MANT_DIG: Integer
|
621
621
|
|
622
622
|
# The largest possible integer in a double-precision floating point number.
|
623
|
-
#
|
623
|
+
#
|
624
624
|
# Usually defaults to 1.7976931348623157e+308.
|
625
|
-
#
|
625
|
+
#
|
626
626
|
Float::MAX: Float
|
627
627
|
|
628
628
|
# The largest positive exponent in a double-precision floating point where 10
|
629
629
|
# raised to this power minus 1.
|
630
|
-
#
|
630
|
+
#
|
631
631
|
# Usually defaults to 308.
|
632
|
-
#
|
632
|
+
#
|
633
633
|
Float::MAX_10_EXP: Integer
|
634
634
|
|
635
635
|
# The largest possible exponent value in a double-precision floating point.
|
636
|
-
#
|
636
|
+
#
|
637
637
|
# Usually defaults to 1024.
|
638
|
-
#
|
638
|
+
#
|
639
639
|
Float::MAX_EXP: Integer
|
640
640
|
|
641
641
|
# The smallest positive normalized number in a double-precision floating point.
|
642
|
-
#
|
642
|
+
#
|
643
643
|
# Usually defaults to 2.2250738585072014e-308.
|
644
|
-
#
|
644
|
+
#
|
645
645
|
# If the platform supports denormalized numbers, there are numbers between zero
|
646
646
|
# and Float::MIN. 0.0.next_float returns the smallest positive floating point
|
647
647
|
# number including denormalized numbers.
|
648
|
-
#
|
648
|
+
#
|
649
649
|
Float::MIN: Float
|
650
650
|
|
651
651
|
# The smallest negative exponent in a double-precision floating point where 10
|
652
652
|
# raised to this power minus 1.
|
653
|
-
#
|
653
|
+
#
|
654
654
|
# Usually defaults to -307.
|
655
|
-
#
|
655
|
+
#
|
656
656
|
Float::MIN_10_EXP: Integer
|
657
657
|
|
658
658
|
# The smallest possible exponent value in a double-precision floating point.
|
659
|
-
#
|
659
|
+
#
|
660
660
|
# Usually defaults to -1021.
|
661
|
-
#
|
661
|
+
#
|
662
662
|
Float::MIN_EXP: Integer
|
663
663
|
|
664
664
|
# An expression representing a value which is "not a number".
|
665
|
-
#
|
665
|
+
#
|
666
666
|
Float::NAN: Float
|
667
667
|
|
668
668
|
# The base of the floating point, or number of unique digits used to represent
|
669
669
|
# the number.
|
670
|
-
#
|
670
|
+
#
|
671
671
|
# Usually defaults to 2 on most systems, which would represent a base-10
|
672
672
|
# decimal.
|
673
|
-
#
|
673
|
+
#
|
674
674
|
Float::RADIX: Integer
|
675
675
|
|
676
676
|
# Deprecated, do not use.
|
677
|
-
#
|
677
|
+
#
|
678
678
|
# Represents the rounding mode for floating point addition at the start time.
|
679
|
-
#
|
679
|
+
#
|
680
680
|
# Usually defaults to 1, rounding to the nearest number.
|
681
|
-
#
|
681
|
+
#
|
682
682
|
# Other modes include:
|
683
|
-
#
|
683
|
+
#
|
684
684
|
# -1
|
685
685
|
# : Indeterminable
|
686
686
|
# 0
|
@@ -691,6 +691,6 @@ Float::RADIX: Integer
|
|
691
691
|
# : Rounding towards positive infinity
|
692
692
|
# 3
|
693
693
|
# : Rounding towards negative infinity
|
694
|
-
#
|
695
|
-
#
|
694
|
+
#
|
695
|
+
#
|
696
696
|
Float::ROUNDS: Integer
|