vector_number 0.2.6 → 0.3.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -6
- data/README.md +6 -7
- data/lib/vector_number/mathing.rb +9 -3
- data/lib/vector_number/stringifying.rb +1 -0
- data/lib/vector_number/version.rb +1 -1
- data/lib/vector_number.rb +19 -13
- data/sig/vector_number.rbs +7 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c55a93e873d8e98092a5be77940f3f91cf06e90abb973f16d2fc91f0df0276ca
|
4
|
+
data.tar.gz: 446cb27d60ff3b588ffbc6fa49489013d6a2cfc8e6f2b577abc4a40b47587658
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a069408f786816659721505e8e09d50aeaf891e6dcc85c35d008a161500548e74c3cb0224a8992521c3e9385cb8cabe6c9b565874981c0098d5fb5c081ee65f
|
7
|
+
data.tar.gz: 99c2b90210dfceaeec85f6f8fd897074296c27ba6e9a6cb8ffcd0d407b3f65482b445b721fd5a41139a339d5d54f8ce81f4860dfdffccc0db1909002744fa8fe
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
8
|
## [Next]
|
9
|
+
## [v0.3.0] — 2025-05-12
|
10
|
+
|
11
|
+
**Added**
|
12
|
+
- Add aliases to other operators:
|
13
|
+
`#neg` for `#-@`, `#add` for `#+`, `#sub` for `#-`, `#mult` for `#*`.
|
14
|
+
`#+@` was already practically aliased by `#dup`.
|
15
|
+
|
16
|
+
**Changed**
|
17
|
+
- [Breaking] Long-existing but broken options feature is now fixed.
|
18
|
+
When creating new vector through any operation, participating vector's options
|
19
|
+
are copied to the new one. When several vectors are present, only first one matters.
|
20
|
+
- Both `#+@` and `#dup` are now aliases of `#itself` instead of full methods.
|
21
|
+
- [🚀 CI] Refactor workflows to reduce duplication.
|
22
|
+
|
9
23
|
## [v0.2.6] — 2025-04-30
|
10
24
|
|
11
25
|
**Added**
|
@@ -16,6 +30,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
16
30
|
- `#/`, `#fdiv` as well as new division methods now properly check for division by zero.
|
17
31
|
VectorNumber does not support this as not all Numeric classes do.
|
18
32
|
|
33
|
+
**Changed**
|
34
|
+
- [🚀 CI] Add Ruby 3.4 to CI.
|
35
|
+
|
19
36
|
## [v0.2.5] — 2025-02-26
|
20
37
|
|
21
38
|
Technical update after release to rubygems.org.
|
@@ -27,8 +44,9 @@ README was updated to reflect this change.
|
|
27
44
|
- Add hash-like methods `#[]` and `#unit?` (aliased as `#key?`).
|
28
45
|
|
29
46
|
**Changed**
|
30
|
-
- [Breaking] Change `positive?` and `negative?` to no longer return `nil
|
31
|
-
|
47
|
+
- [Breaking] Change `positive?` and `negative?` to no longer return `nil`
|
48
|
+
when number is neither strictly positive or negative,
|
49
|
+
these cases will now return `false`.
|
32
50
|
- Make `VectorNumber.new` accept options when initializing from a VectorNumber
|
33
51
|
instead of only copying. Options will be merged.
|
34
52
|
- Remove `Initializing` module, move its methods to the actual class.
|
@@ -49,9 +67,9 @@ README was updated to reflect this change.
|
|
49
67
|
- Add `#ceil`, `#floor` and `#round`.
|
50
68
|
|
51
69
|
**Changed**
|
52
|
-
- Add ruby 3.1.0, covering the earliest supported version, and ruby-next (3.4) to CI.
|
53
|
-
- Add JRuby and TruffleRuby to CI, without full support.
|
54
|
-
- Make tests runnable even without available `bigdecimal` gem.
|
70
|
+
- [🚀 CI] Add ruby 3.1.0, covering the earliest supported version, and ruby-next (3.4) to CI.
|
71
|
+
- [🚀 CI] Add JRuby and TruffleRuby to CI, without full support.
|
72
|
+
- [🚀 CI] Make tests runnable even without available `bigdecimal` gem.
|
55
73
|
|
56
74
|
**Fixed**
|
57
75
|
- `Kernel#BigDecimal` refinement now correctly works without `ndigits` argument.
|
@@ -59,7 +77,7 @@ README was updated to reflect this change.
|
|
59
77
|
## [v0.2.1] — 2024-08-24
|
60
78
|
|
61
79
|
**Added**
|
62
|
-
- Add
|
80
|
+
- Add `#*` and `#/` for working with real numbers.
|
63
81
|
- Add `#fdiv`, `#truncate`, `#nonnumeric?` and `#integer?`.
|
64
82
|
|
65
83
|
**Changed**
|
@@ -82,3 +100,5 @@ README was updated to reflect this change.
|
|
82
100
|
## [v0.1.0] — 2024-05-09
|
83
101
|
|
84
102
|
- Initial work.
|
103
|
+
|
104
|
+
[🚀 CI]: https://github.com/trinistr/vector_number/actions/workflows/CI.yaml
|
data/README.md
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
# VectorNumber
|
2
2
|
|
3
|
-

|
6
|
-
-->
|
3
|
+
[](https://github.com/trinistr/vector_number/actions/workflows/CI.yaml)
|
7
4
|
|
8
5
|
A library to add together anything: be it a number, string or random Object, it can be added together in an infinite-dimensional vector space, with math operations available on results.
|
9
6
|
|
@@ -16,7 +13,9 @@ Similar projects:
|
|
16
13
|
|
17
14
|
## Installation
|
18
15
|
|
19
|
-
|
16
|
+
VectorNumber does not have any dependencies and does not include extensions.
|
17
|
+
|
18
|
+
Install with `gem` (available from 0.2.4):
|
20
19
|
```sh
|
21
20
|
gem install vector_number
|
22
21
|
```
|
@@ -58,9 +57,9 @@ VectorNumber.new([4, "death", "death", 13, nil])
|
|
58
57
|
## Ruby engine support status
|
59
58
|
|
60
59
|
VectorNumber is developed on MRI (CRuby) but should work on other engines too.
|
61
|
-
- JRuby: should work, but currently CI does not pass.
|
62
60
|
- TruffleRuby: works as expected, but there are differences in core Ruby code, so some tests fail.
|
63
|
-
-
|
61
|
+
- JRuby: significant problems (at least on CI), but may work.
|
62
|
+
- Other engines: untested, but should work, depending on compatibility.
|
64
63
|
|
65
64
|
## Development
|
66
65
|
|
@@ -18,9 +18,7 @@ class VectorNumber
|
|
18
18
|
|
19
19
|
# Return self.
|
20
20
|
# @return [VectorNumber]
|
21
|
-
|
22
|
-
self
|
23
|
-
end
|
21
|
+
alias +@ itself
|
24
22
|
|
25
23
|
# Return new vector with negated coefficients.
|
26
24
|
# This preserves order of units.
|
@@ -29,6 +27,8 @@ class VectorNumber
|
|
29
27
|
new(&:-@)
|
30
28
|
end
|
31
29
|
|
30
|
+
alias neg -@
|
31
|
+
|
32
32
|
# Return new vector as a sum of this and other value.
|
33
33
|
# This is analogous to {VectorNumber.[]}.
|
34
34
|
# @param other [Object]
|
@@ -37,6 +37,8 @@ class VectorNumber
|
|
37
37
|
new([self, other])
|
38
38
|
end
|
39
39
|
|
40
|
+
alias add +
|
41
|
+
|
40
42
|
# Return new vector as a sum of this and negative of the other value.
|
41
43
|
# This is analogous to {VectorNumber.[]}, but allows to negate anything.
|
42
44
|
# @param other [Object]
|
@@ -45,6 +47,8 @@ class VectorNumber
|
|
45
47
|
self + new([other], &:-@)
|
46
48
|
end
|
47
49
|
|
50
|
+
alias sub -
|
51
|
+
|
48
52
|
# Multiply all coefficients by a real number, returning new vector.
|
49
53
|
# This effectively multiplies magnitude by the specified factor.
|
50
54
|
# @param other [Integer, Float, Rational, BigDecimal, VectorNumber]
|
@@ -63,6 +67,8 @@ class VectorNumber
|
|
63
67
|
end
|
64
68
|
end
|
65
69
|
|
70
|
+
alias mult *
|
71
|
+
|
66
72
|
# Divide all coefficients by a real number, returning new vector.
|
67
73
|
# This effectively multiplies magnitude by reciprocal of +other+.
|
68
74
|
# @param other [Integer, Float, Rational, BigDecimal, VectorNumber]
|
data/lib/vector_number.rb
CHANGED
@@ -54,18 +54,15 @@ class VectorNumber
|
|
54
54
|
# @param values [Array, Hash{Object => Integer, Float, Rational, BigDecimal}, VectorNumber]
|
55
55
|
# values for this number, hashes are treated like plain vector numbers
|
56
56
|
# @param options [Hash{Symbol => Object}]
|
57
|
-
# options for this number, if +values+ is a VectorNumber,
|
58
|
-
# these will be merged with options from +
|
57
|
+
# options for this number, if +values+ is a VectorNumber or contains it,
|
58
|
+
# these will be merged with options from its +options+
|
59
59
|
# @option options [Symbol, String] :mult
|
60
60
|
# text to use between unit and coefficient, see {Stringifying#to_s} for explanation
|
61
61
|
# @yieldparam coefficient [Integer, Float, Rational, BigDecimal]
|
62
62
|
# @yieldreturn [Integer, Float, Rational, BigDecimal] new coefficient
|
63
63
|
# @raise [RangeError] if any pesky non-reals get where they shouldn't
|
64
|
-
def initialize(values = nil, options =
|
65
|
-
#
|
66
|
-
# > (VectorNumber[1, 'a', mult: :invisible] + 2).options
|
67
|
-
# => {:mult=>:dot}
|
68
|
-
super()
|
64
|
+
def initialize(values = nil, options = nil, &)
|
65
|
+
# @type var options: Hash[Symbol, Symbol]
|
69
66
|
initialize_from(values)
|
70
67
|
apply_transform(&)
|
71
68
|
finalize_contents
|
@@ -78,9 +75,7 @@ class VectorNumber
|
|
78
75
|
# Return self.
|
79
76
|
#
|
80
77
|
# @return [VectorNumber]
|
81
|
-
|
82
|
-
self
|
83
|
-
end
|
78
|
+
alias dup itself
|
84
79
|
|
85
80
|
# Return self.
|
86
81
|
#
|
@@ -106,7 +101,7 @@ class VectorNumber
|
|
106
101
|
# @yieldreturn [Integer, Float, Rational, BigDecimal] new coefficient
|
107
102
|
# @return [VectorNumber]
|
108
103
|
def new(from = self, &)
|
109
|
-
self.class.new(from, &)
|
104
|
+
self.class.new(from, options, &)
|
110
105
|
end
|
111
106
|
|
112
107
|
# @param value [Object]
|
@@ -183,15 +178,26 @@ class VectorNumber
|
|
183
178
|
case [options, values]
|
184
179
|
in [{} | nil, VectorNumber]
|
185
180
|
values.options
|
181
|
+
in [{} | nil, [*, VectorNumber => vector, *]]
|
182
|
+
vector.options
|
186
183
|
in Hash, VectorNumber
|
187
|
-
values.options
|
184
|
+
merge_options(values.options, options)
|
185
|
+
in Hash, [*, VectorNumber => vector, *]
|
186
|
+
merge_options(vector.options, options)
|
188
187
|
in Hash, _ unless options.empty?
|
189
|
-
default_options
|
188
|
+
merge_options(default_options, options)
|
190
189
|
else
|
191
190
|
default_options
|
192
191
|
end
|
193
192
|
end
|
194
193
|
|
194
|
+
def merge_options(base_options, added_options)
|
195
|
+
# Optimization for the common case of passing options through #new.
|
196
|
+
return base_options if added_options.equal?(base_options)
|
197
|
+
|
198
|
+
base_options.merge(added_options).slice(*known_options)
|
199
|
+
end
|
200
|
+
|
195
201
|
# Compact coefficients, calculate size and freeze data.
|
196
202
|
# @return [void]
|
197
203
|
def finalize_contents
|
data/sig/vector_number.rbs
CHANGED
@@ -51,7 +51,7 @@ class VectorNumber
|
|
51
51
|
def self.[]: (*unit_type values, **options_type options) -> vector_type
|
52
52
|
|
53
53
|
def initialize:
|
54
|
-
(?(units_list_type | plain_vector_type | vector_type)? values, ?options_type options)
|
54
|
+
(?(units_list_type | plain_vector_type | vector_type)? values, ?options_type? options)
|
55
55
|
?{ (coefficient_type coefficient) -> coefficient_type }
|
56
56
|
-> void
|
57
57
|
|
@@ -90,12 +90,16 @@ class VectorNumber
|
|
90
90
|
def +@: () -> self
|
91
91
|
|
92
92
|
def -@: () -> vector_type
|
93
|
+
alias neg -@
|
93
94
|
|
94
95
|
def +: (in_value_type) -> vector_type
|
96
|
+
alias add +
|
95
97
|
|
96
98
|
def -: (in_value_type) -> vector_type
|
99
|
+
alias sub -
|
97
100
|
|
98
101
|
def *: (real_number | vector_type) -> vector_type
|
102
|
+
alias mult *
|
99
103
|
|
100
104
|
def /: (real_number | vector_type) -> vector_type
|
101
105
|
alias quo /
|
@@ -130,6 +134,8 @@ class VectorNumber
|
|
130
134
|
def ceil: (Integer) -> vector_type
|
131
135
|
|
132
136
|
def floor: (Integer) -> vector_type
|
137
|
+
|
138
|
+
def round: (Integer, ?half: (:up | :down | :even)) -> vector_type
|
133
139
|
end
|
134
140
|
|
135
141
|
# Methods for converting to different number classes.
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vector_number
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandr Bulancov
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-05-12 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
12
|
executables: []
|
13
13
|
extensions: []
|