vector_number 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/vector_number.rb CHANGED
@@ -1,23 +1,93 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "vector_number/comparing"
4
- require_relative "vector_number/converting"
5
- require_relative "vector_number/enumerating"
6
- require_relative "vector_number/math_converting"
7
- require_relative "vector_number/mathing"
8
- require_relative "vector_number/querying"
9
- require_relative "vector_number/stringifying"
10
- require_relative "vector_number/version"
11
-
12
- # A class to add together anything.
3
+ # VectorNumber provides a Numeric-like experience for doing arithmetics on heterogeneous objects,
4
+ # with more advanced operations based on real vector spaces available when needed.
5
+ #
6
+ # VectorNumber inherits from +Object+ and includes +Enumerable+ and +Comparable+.
7
+ # It implements mostly the same interface as +Numeric+ classes, but can {#coerce} any value.
8
+ # Its behavior follows +Complex+ when possible.
9
+ #
10
+ # All instances are frozen after creation.
11
+ #
12
+ # **Creation**
13
+ # - {.[]}: the simplest way to create a VectorNumber
14
+ # - {#initialize}: an alternative way, with some advanced features
15
+ #
16
+ # **Comparing**
17
+ # - {#==}: test for equal value
18
+ # - {#eql?}: test for equal value and type
19
+ # - {#<=>}: compare real values
20
+ # - {#hash}: calculate hash value for use in +Hash+es
21
+ #
22
+ # **Querying**
23
+ # - {#zero?}: check if all coefficients are zero
24
+ # - {#nonzero?}: check if any coefficient is non-zero
25
+ # - {#positive?}: check if all coefficients are positive
26
+ # - {#negative?}: check if all coefficients are negative
27
+ # - {#finite?}: check if all coefficients are finite
28
+ # - {#infinite?}: check if any coefficient is non-finite
29
+ # - {#numeric?}: test if value is real or complex
30
+ # - {#nonnumeric?}: test if value is not real or complex
31
+ # - {#integer?}: +false+
32
+ # - {#real?}: +false+
33
+ #
34
+ # **Unary** **math** **operations**
35
+ # - {#+}/{#dup}: return self
36
+ # - {#-@}/{#neg}: negate value
37
+ # - {#abs}/{#magnitude}: return absolute value (magnitude, length)
38
+ # - {#abs2}: return square of absolute value
39
+ #
40
+ # **Arithmetic** **operations**
41
+ # - {#coerce}: convert any object to a VectorNumber
42
+ # - {#+}/{#add}: add object
43
+ # - {#-}/{#sub}: subtract object
44
+ # - {#*}/{#mult}: multiply (scale) by a real number
45
+ # - {#/}/{#quo}: divide (scale) by a real number
46
+ # - {#fdiv}: divide (scale) by a real number, using +fdiv+
47
+ # - {#div}: perform integer division
48
+ # - {#%}/{#modulo}: return modulus from integer division
49
+ # - {#divmod}: combination of {#div} and {#modulo}
50
+ # - {#remainder}: return remainder from integer division
51
+ #
52
+ # **Rounding**
53
+ # - {#round}: round each coefficient
54
+ # - {#ceil}: round each coefficient up towards +∞
55
+ # - {#floor}: round each coefficient down towards -∞
56
+ # - {#truncate}: truncate each coefficient towards 0
57
+ #
58
+ # **Type** **conversion**
59
+ # - {#real}: return real part
60
+ # - {#imag}/{#imaginary}: return imaginary part
61
+ # - {#to_i}/{#to_int}: convert to +Integer+ if possible
62
+ # - {#to_f}: convert to +Float+ if possible
63
+ # - {#to_r}: convert to +Rational+ if possible
64
+ # - {#to_d}: convert to +BigDecimal+ if possible
65
+ # - {#to_c}: convert to +Complex+ if possible
66
+ #
67
+ # **Hash-like** **operations**
68
+ # - {#each}/{#each_pair}: iterate through every pair of unit and coefficient
69
+ # - {#[]}: get coefficient by unit
70
+ # - {#unit?}/{#key?}: check if a unit has a non-zero coefficient
71
+ # - {#units}/{#keys}: return an array of units
72
+ # - {#coefficients}/#{values}: return an array of coefficients
73
+ # - {#to_h}: convert to Hash
74
+ #
75
+ # **Miscellaneous** **methods**
76
+ # - {#size}: number of non-zero coefficients
77
+ # - {#options}: hash of options
78
+ # - {#dup}/{#+}: return self
79
+ # - {#clone}: return self
80
+ # - {#to_s}: return string representation suitable for printing
81
+ # - {#inspect}: return string representation suitable for display
13
82
  class VectorNumber
14
- include Mathing
15
- include MathConverting
16
- include Converting
17
- include Enumerating
18
- include Comparing
19
- include Querying
20
- include Stringifying
83
+ require_relative "vector_number/comparing"
84
+ require_relative "vector_number/converting"
85
+ require_relative "vector_number/enumerating"
86
+ require_relative "vector_number/math_converting"
87
+ require_relative "vector_number/mathing"
88
+ require_relative "vector_number/querying"
89
+ require_relative "vector_number/stringifying"
90
+ require_relative "vector_number/version"
21
91
 
22
92
  # Keys for possible options.
23
93
  # Unknown options will be rejected when creating a vector.
@@ -47,6 +117,7 @@ class VectorNumber
47
117
  # @since 0.1.0
48
118
  I = UNIT[2]
49
119
 
120
+ # @group Creation
50
121
  # Create new VectorNumber from a list of values, possibly specifying options.
51
122
  #
52
123
  # @example
@@ -67,6 +138,7 @@ class VectorNumber
67
138
  def self.[](*values, **options)
68
139
  new(values, options)
69
140
  end
141
+ # @endgroup
70
142
 
71
143
  # Number of non-zero dimensions.
72
144
  #
@@ -84,9 +156,21 @@ class VectorNumber
84
156
  # @since 0.1.0
85
157
  attr_reader :options
86
158
 
159
+ # @group Creation
87
160
  # Create new VectorNumber from +values+, possibly specifying +options+,
88
161
  # possibly modifying coefficients with a block.
89
162
  #
163
+ # +values+ can be:
164
+ # - an array of values (see {.[]});
165
+ # - a VectorNumber to copy;
166
+ # - a hash in the format returned by {#to_h};
167
+ # - +nil+ to specify a 0-dimensional vector (same as an empty array or hash).
168
+ #
169
+ # Using a hash as +values+ is an advanced technique which allows to quickly
170
+ # construct a VectorNumber with desired units and coefficients,
171
+ # but it can also lead to unexpected results if care is not taken
172
+ # to provide only valid keys and values.
173
+ #
90
174
  # @example
91
175
  # VectorNumber.new(1, 2, 3) # ArgumentError
92
176
  # VectorNumber.new([1, 2, 3]) # => (6)
@@ -96,28 +180,32 @@ class VectorNumber
96
180
  # VectorNumber.new(["a", "b", "c", 3]) { _1 * 2 } # => (2⋅'a' + 2⋅'b' + 2⋅'c' + 6)
97
181
  # VectorNumber.new(["a", "b", "c", 3], &:-@) # => (-1⋅'a' - 1⋅'b' - 1⋅'c' - 3)
98
182
  # VectorNumber.new(["a", "b", "c", 3], &:digits) # RangeError
183
+ # @example using hash for values
184
+ # v = VectorNumber.new({1 => 15, "a" => 3.4, nil => -3}) # => (15 + 3.4⋅'a' - 3⋅)
185
+ # v.to_h # => {1 => 15, "a" => 3.4, nil => -3}
99
186
  #
100
- # @param values [Array, VectorNumber, Hash{Object => Integer, Float, Rational, BigDecimal}, nil]
101
- # values for this number, hashes are treated like plain vector numbers
187
+ # @param values [Array, VectorNumber, Hash{Object => Numeric}, nil] values for this vector
102
188
  # @param options [Hash{Symbol => Object}, nil]
103
- # options for this number, if +values+ is a VectorNumber or contains it,
189
+ # options for this vector, if +values+ is a VectorNumber or contains it,
104
190
  # these will be merged with options from its +options+
105
- # @option options [Symbol, String] :mult
106
- # text to use between unit and coefficient, see {Stringifying#to_s} for explanation
107
- # @yieldparam coefficient [Integer, Float, Rational, BigDecimal]
108
- # @yieldreturn [Integer, Float, Rational, BigDecimal] new coefficient
109
- # @raise [RangeError] if any pesky non-reals get where they shouldn't
110
- def initialize(values = nil, options = nil, &)
191
+ # @option options [Symbol, String] :mult Multiplication symbol,
192
+ # either a key from {MULT_STRINGS} or a literal string to use
193
+ # @yieldparam coefficient [Numeric] a real number
194
+ # @yieldreturn [Numeric] new coefficient
195
+ # @raise [RangeError] if a block is used and it returns a non-number or non-real number
196
+ def initialize(values = nil, options = nil, &transform)
111
197
  # @type var options: Hash[Symbol, Object]
112
198
  initialize_from(values)
113
- apply_transform(&)
199
+ apply_transform(&transform)
114
200
  finalize_contents
115
- save_options(options, values:)
201
+ save_options(options, values)
116
202
  @options.freeze
117
203
  @data.freeze
118
204
  freeze
119
205
  end
120
206
 
207
+ # @group Miscellaneous methods
208
+
121
209
  # Return self.
122
210
  #
123
211
  # @return [VectorNumber]
@@ -149,11 +237,11 @@ class VectorNumber
149
237
  # Create new VectorNumber from a value or self, optionally applying a transform.
150
238
  #
151
239
  # @param from [Object] self if not specified
152
- # @yieldparam coefficient [Integer, Float, Rational, BigDecimal]
153
- # @yieldreturn [Integer, Float, Rational, BigDecimal] new coefficient
240
+ # @yieldparam coefficient [Numeric] a real number
241
+ # @yieldreturn [Numeric] new coefficient
154
242
  # @return [VectorNumber]
155
- def new(from = self, &)
156
- self.class.new(from, options, &)
243
+ def new(from = self, &transform)
244
+ self.class.new(from, options, &transform)
157
245
  end
158
246
 
159
247
  # Check if +other+ is a real number.
@@ -162,16 +250,12 @@ class VectorNumber
162
250
  #
163
251
  # @param value [Object]
164
252
  # @return [Boolean]
165
- #
166
- # @since 0.1.0
167
253
  def real_number?(value)
168
254
  (value.is_a?(Numeric) && value.real?) || (value.is_a?(self.class) && value.numeric?(1))
169
255
  end
170
256
 
171
- # @param values [Array, Hash{Object => Integer, Float, Rational, BigDecimal}, VectorNumber, nil]
257
+ # @param values [Array, Hash{Object => Numeric}, VectorNumber, nil]
172
258
  # @return [void]
173
- #
174
- # @since 0.1.0
175
259
  def initialize_from(values)
176
260
  @data = values.to_h and return if values.is_a?(VectorNumber)
177
261
 
@@ -190,8 +274,6 @@ class VectorNumber
190
274
 
191
275
  # @param value [VectorNumber, Numeric, Object]
192
276
  # @return [void]
193
- #
194
- # @since 0.1.0
195
277
  def add_value_to_data(value)
196
278
  case value
197
279
  when Numeric
@@ -205,8 +287,6 @@ class VectorNumber
205
287
 
206
288
  # @param value [Numeric]
207
289
  # @return [void]
208
- #
209
- # @since 0.1.0
210
290
  def add_numeric_value_to_data(value)
211
291
  @data[R] += value.real
212
292
  # Most numbers will be real, and this extra condition appreciably speeds up addition,
@@ -214,10 +294,8 @@ class VectorNumber
214
294
  @data[I] += value.imaginary unless value.real?
215
295
  end
216
296
 
217
- # @param vector [VectorNumber, Hash{Object => Integer, Float, Rational, BigDecimal}]
297
+ # @param vector [VectorNumber, Hash{Object => Numeric}]
218
298
  # @return [void]
219
- #
220
- # @since 0.1.0
221
299
  def add_vector_to_data(vector)
222
300
  vector.each_pair do |unit, coefficient|
223
301
  raise RangeError, "#{coefficient} is not a real number" unless real_number?(coefficient)
@@ -226,12 +304,10 @@ class VectorNumber
226
304
  end
227
305
  end
228
306
 
229
- # @yieldparam coefficient [Integer, Float, Rational, BigDecimal]
230
- # @yieldreturn [Integer, Float, Rational, BigDecimal]
307
+ # @yieldparam coefficient [Numeric] a real number
308
+ # @yieldreturn [Numeric] new coefficient
231
309
  # @return [void]
232
310
  # @raise [RangeError]
233
- #
234
- # @since 0.1.0
235
311
  def apply_transform
236
312
  return unless block_given?
237
313
 
@@ -246,9 +322,7 @@ class VectorNumber
246
322
  # @param options [Hash{Symbol => Object}, nil]
247
323
  # @param values [Object] initializing object
248
324
  # @return [void]
249
- #
250
- # @since 0.1.0
251
- def save_options(options, values:)
325
+ def save_options(options, values)
252
326
  @options =
253
327
  case values
254
328
  in VectorNumber
@@ -263,8 +337,6 @@ class VectorNumber
263
337
  # @param base_options [Hash{Symbol => Object}]
264
338
  # @param added_options [Hash{Symbol => Object}, nil]
265
339
  # @return [Hash{Symbol => Object}]
266
- #
267
- # @since 0.3.0
268
340
  def merge_options(base_options, added_options)
269
341
  return base_options if !added_options || added_options.empty?
270
342
  # Optimization for the common case of passing options through #new.
@@ -275,8 +347,6 @@ class VectorNumber
275
347
 
276
348
  # Compact coefficients, calculate size and freeze data.
277
349
  # @return [void]
278
- #
279
- # @since 0.1.0
280
350
  def finalize_contents
281
351
  @data.delete_if { |_u, c| c.zero? }
282
352
  @data.freeze
@@ -1,43 +1,22 @@
1
- type vector_type = VectorNumber
2
- type real_number = Integer | Float | Rational | BigDecimal
1
+ # A class to add together anything.
2
+ class VectorNumber
3
+ # ---- Generic types ----
4
+ type real_number = Integer | Float | Rational | BigDecimal
3
5
 
4
- type in_value_type = untyped
5
- type unit_type = untyped
6
- type coefficient_type = real_number
6
+ type in_value_type = untyped
7
+ type unit_type = untyped
8
+ type coefficient_type = real_number
7
9
 
8
- type list[T] = Array[T]
10
+ type list[T] = Array[T]
9
11
 
10
- type plain_vector_type = Hash[unit_type, coefficient_type]
11
- type units_list_type = list[unit_type]
12
- type coefficients_list_type = list[coefficient_type]
13
- type each_value_type = [unit_type, coefficient_type]
12
+ type plain_instance = Hash[unit_type, coefficient_type]
13
+ type units_list_type = list[unit_type]
14
+ type coefficients_list_type = list[coefficient_type]
15
+ type each_value_type = [unit_type, coefficient_type]
14
16
 
15
- type options_type = Hash[Symbol, untyped]
17
+ type options_type = Hash[Symbol, untyped]
16
18
 
17
- interface _BaseMethods
18
- def size: -> Integer
19
- def options: -> options_type
20
-
21
- # private
22
- def new: () { (coefficient_type value) -> coefficient_type } -> vector_type
23
- | (in_value_type) { (coefficient_type value) -> coefficient_type } -> vector_type
24
- | () -> vector_type
25
- | (in_value_type) -> vector_type
26
- def real_number?: (real_number value) -> true
27
- | (vector_type) -> bool
28
- | (in_value_type value) -> false
29
- end
30
-
31
- # A class to add together anything.
32
- class VectorNumber
33
- include _BaseMethods
34
- include VectorNumber::Mathing
35
- include VectorNumber::MathConverting
36
- include VectorNumber::Converting
37
- include VectorNumber::Enumerating
38
- include VectorNumber::Comparing
39
- include VectorNumber::Querying
40
- include VectorNumber::Stringifying
19
+ # ---- Constants ----
41
20
 
42
21
  VERSION: String
43
22
 
@@ -48,10 +27,15 @@ class VectorNumber
48
27
  R: Complex
49
28
  I: Complex
50
29
 
51
- def self.[]: (*unit_type values, **options_type options) -> vector_type
30
+ # ---- Public methods ----
31
+
32
+ def self.[]: (*unit_type values, **options_type options) -> instance
33
+
34
+ def size: -> Integer
35
+ def options: -> options_type
52
36
 
53
37
  def initialize:
54
- (?(units_list_type | plain_vector_type | vector_type)? values, ?options_type? options)
38
+ (?(units_list_type | plain_instance | instance)? values, ?options_type? options)
55
39
  ?{ (coefficient_type coefficient) -> coefficient_type }
56
40
  -> void
57
41
 
@@ -64,196 +48,179 @@ class VectorNumber
64
48
 
65
49
  @size: Integer
66
50
  @options: options_type
67
- @data: plain_vector_type
51
+ @data: plain_instance
68
52
 
69
- def initialize_from: ((units_list_type | plain_vector_type | vector_type)? values) -> void
53
+ def new: () { (coefficient_type value) -> coefficient_type } -> instance
54
+ | (in_value_type) { (coefficient_type value) -> coefficient_type } -> instance
55
+ | () -> instance
56
+ | (in_value_type) -> instance
70
57
 
71
- def add_value_to_data: ((vector_type | Numeric | unit_type) value) -> void
58
+ def real_number?: (real_number value) -> true
59
+ | (instance) -> bool
60
+ | (in_value_type value) -> false
61
+
62
+ def initialize_from: ((units_list_type | plain_instance | instance)? values) -> void
63
+
64
+ def add_value_to_data: ((instance | Numeric | unit_type) value) -> void
72
65
 
73
66
  def add_numeric_value_to_data: (Numeric value) -> void
74
67
 
75
- def add_vector_to_data: ((vector_type | plain_vector_type) vector) -> void
68
+ def add_vector_to_data: ((instance | plain_instance) vector) -> void
76
69
 
77
70
  def apply_transform: () ?{ (coefficient_type value) -> coefficient_type } -> void
78
71
 
79
- def save_options: (options_type? options, values: in_value_type) -> void
72
+ def save_options: (options_type? options, in_value_type values) -> void
80
73
  def merge_options: (options_type base_options, options_type added_options) -> options_type
81
- def default_options: () -> options_type
82
- def known_options: () -> list[Symbol]
83
74
 
84
75
  def finalize_contents: () -> void
76
+ end
85
77
 
86
- # Methods for performing actual math.
87
- module Mathing
88
- include _BaseMethods
89
-
90
- def coerce: (in_value_type) -> [vector_type, self]
91
-
92
- def -@: () -> vector_type
93
- alias neg -@
94
-
95
- def +: (in_value_type) -> vector_type
96
- alias add +
97
-
98
- def -: (in_value_type) -> vector_type
99
- alias sub -
100
-
101
- def *: (real_number | vector_type) -> vector_type
102
- alias mult *
103
-
104
- def /: (real_number | vector_type) -> vector_type
105
- alias quo /
106
-
107
- def fdiv: (real_number | vector_type) -> vector_type
78
+ # Methods for performing actual math.
79
+ class VectorNumber
80
+ def coerce: (in_value_type) -> [instance, self]
108
81
 
109
- def div: (real_number | vector_type) -> vector_type
82
+ def -@: () -> instance
83
+ alias neg -@
110
84
 
111
- def %: (real_number | vector_type) -> vector_type
112
- alias modulo %
85
+ def +: (in_value_type) -> instance
86
+ alias add +
113
87
 
114
- def divmod: (real_number | vector_type) -> [vector_type, vector_type]
88
+ def -: (in_value_type) -> instance
89
+ alias sub -
115
90
 
116
- def remainder: (real_number | vector_type) -> vector_type
91
+ def *: (real_number | instance) -> instance
92
+ alias mult *
117
93
 
118
- private
94
+ def /: (real_number | instance) -> instance
95
+ alias quo /
119
96
 
120
- def check_divisibility: (real_number | vector_type) -> void
121
- end
97
+ def fdiv: (real_number | instance) -> instance
122
98
 
123
- # Various mathematical operations that are also conversions.
124
- module MathConverting
125
- include _BaseMethods
126
- include Enumerating
99
+ def div: (real_number | instance) -> instance
127
100
 
128
- def abs: () -> Float
101
+ def %: (real_number | instance) -> instance
102
+ alias modulo %
129
103
 
130
- def abs2: () -> Float
104
+ def divmod: (real_number | instance) -> [instance, instance]
131
105
 
132
- def truncate: (Integer) -> vector_type
106
+ def remainder: (real_number | instance) -> instance
133
107
 
134
- def ceil: (Integer) -> vector_type
108
+ private
135
109
 
136
- def floor: (Integer) -> vector_type
110
+ def check_divisibility: (real_number | instance) -> void
111
+ end
137
112
 
138
- def round: (Integer, ?half: (:up | :down | :even)) -> vector_type
139
- end
113
+ # Various mathematical operations that are also conversions.
114
+ class VectorNumber
115
+ def abs: () -> Float
140
116
 
141
- # Methods for converting to different number classes.
142
- module Converting
143
- include _BaseMethods
144
- include Querying
117
+ def abs2: () -> Float
145
118
 
146
- def real: () -> real_number
119
+ def truncate: (?Integer) -> instance
147
120
 
148
- def imaginary: () -> real_number
149
- alias imag imaginary
121
+ def ceil: (?Integer) -> instance
150
122
 
151
- def to_i: () -> Integer
152
- | () -> void
153
- alias to_int to_i
123
+ def floor: (?Integer) -> instance
154
124
 
155
- def to_f: () -> Float
156
- | () -> void
125
+ def round: (?Integer, ?half: (:up | :down | :even)) -> instance
126
+ end
157
127
 
158
- def to_r: () -> Rational
159
- | () -> void
128
+ # Methods for converting to different number classes.
129
+ class VectorNumber
130
+ def real: () -> real_number
160
131
 
161
- def to_d: (?Integer?) -> BigDecimal
162
- | (?Integer?) -> void
132
+ def imaginary: () -> real_number
133
+ alias imag imaginary
163
134
 
164
- def to_c: () -> Complex
165
- | () -> void
135
+ def to_i: () -> Integer
136
+ alias to_int to_i
166
137
 
167
- def truncate: (?Integer digits) -> vector_type
138
+ def to_f: () -> Float
168
139
 
169
- private
140
+ def to_r: () -> Rational
170
141
 
171
- def raise_convert_error: (Class) -> void
172
- end
142
+ def to_d: (?Integer?) -> BigDecimal
173
143
 
174
- # Methods for enumerating values of the number.
175
- module Enumerating
176
- include _BaseMethods
177
- include _Each[each_value_type]
178
- include Enumerable[each_value_type]
144
+ def to_c: () -> Complex
179
145
 
180
- def each: () { (unit_type unit, coefficient_type coefficient) -> void } -> self
181
- | () -> Enumerator[each_value_type, Integer]
182
- | ...
183
- alias each_pair each
146
+ private
184
147
 
185
- def units: () -> units_list_type
186
- alias keys units
148
+ def raise_convert_error: (Class) -> void
149
+ end
187
150
 
188
- def coefficients: () -> coefficients_list_type
189
- alias values coefficients
151
+ class VectorNumber
152
+ include _Each[each_value_type]
153
+ include Enumerable[each_value_type]
190
154
 
191
- def to_h: () -> plain_vector_type
192
- | () { (unit_type, coefficient_type) -> each_value_type } -> plain_vector_type
155
+ def each: () { (unit_type unit, coefficient_type coefficient) -> void } -> self
156
+ | () -> Enumerator[each_value_type, Integer]
157
+ | ...
158
+ alias each_pair each
193
159
 
194
- def []: (unit_type unit) -> coefficient_type
160
+ def units: () -> units_list_type
161
+ alias keys units
195
162
 
196
- def unit?: (unit_type unit) -> bool
197
- alias key? unit?
198
- end
163
+ def coefficients: () -> coefficients_list_type
164
+ alias values coefficients
199
165
 
200
- # Methods for comparing with other numbers.
201
- module Comparing
202
- include _BaseMethods
203
- include Enumerating
204
- include Converting
205
- include Querying
166
+ def to_h: () -> plain_instance
167
+ | () { (unit_type, coefficient_type) -> each_value_type } -> plain_instance
206
168
 
207
- def ==: (in_value_type other) -> bool
169
+ def []: (unit_type unit) -> coefficient_type
208
170
 
209
- def eql?: (in_value_type other) -> bool
171
+ def unit?: (unit_type unit) -> bool
172
+ alias key? unit?
173
+ end
210
174
 
211
- def hash: () -> Integer
175
+ # Methods for comparing with other numbers.
176
+ class VectorNumber
177
+ def ==: (in_value_type other) -> bool
212
178
 
213
- def <=>: (in_value_type other) -> Integer?
214
- end
179
+ def eql?: (in_value_type other) -> bool
215
180
 
216
- # Methods for querying state of the number.
217
- # Mostly modeled after {::Complex}.
218
- module Querying
219
- include Enumerating
181
+ def hash: () -> Integer
220
182
 
221
- def numeric?: (?Integer) -> bool
183
+ def <=>: (in_value_type other) -> Integer?
184
+ end
222
185
 
223
- def nonnumeric?: (?Integer) -> bool
186
+ # Methods for querying state of the number.
187
+ # Mostly modeled after {::Complex}.
188
+ class VectorNumber
189
+ def numeric?: (?Integer) -> bool
224
190
 
225
- def finite?: () -> bool
191
+ def nonnumeric?: (?Integer) -> bool
226
192
 
227
- def infinite?: () -> Integer?
193
+ def finite?: () -> bool
228
194
 
229
- def zero?: () -> bool
195
+ def infinite?: () -> Integer?
230
196
 
231
- def nonzero?: () -> self?
197
+ def zero?: () -> bool
232
198
 
233
- def positive?: () -> bool
199
+ def nonzero?: () -> self?
234
200
 
235
- def negative?: () -> bool
201
+ def positive?: () -> bool
236
202
 
237
- def real?: () -> false
203
+ def negative?: () -> bool
238
204
 
239
- def integer?: () -> false
240
- end
205
+ def real?: () -> false
241
206
 
242
- # Methods and options for string representation.
243
- module Stringifying
244
- include Querying
207
+ def integer?: () -> false
208
+ end
245
209
 
246
- MULT_STRINGS: Hash[Symbol, String]
210
+ # Methods and options for string representation.
211
+ class VectorNumber
212
+ MULT_STRINGS: Hash[Symbol, String]
247
213
 
248
- def to_s: (?mult: (Symbol | String)) -> String
214
+ def to_s: (?mult: (Symbol | String)) -> String
249
215
 
250
- def inspect: () -> String
216
+ def inspect: () -> String
251
217
 
252
- private
218
+ private
253
219
 
254
- def value_to_s: (unit_type unit, coefficient_type coefficient, mult: (Symbol | String)) -> String
255
- end
220
+ def value_to_s: (unit_type unit, coefficient_type coefficient, mult: (Symbol | String)) -> String
221
+ end
256
222
 
223
+ class VectorNumber
257
224
  # Refinements of Numeric classes to better work with VectorNumber and similar classes.
258
225
  module NumericRefinements
259
226
  module CommutativeShuttle