vector_number 0.4.1 → 0.4.3
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/README.md +102 -37
- data/lib/vector_number/comparing.rb +17 -0
- data/lib/vector_number/enumerating.rb +4 -4
- data/lib/vector_number/math_converting.rb +4 -2
- data/lib/vector_number/numeric_refinements.rb +15 -3
- data/lib/vector_number/stringifying.rb +1 -1
- data/lib/vector_number/version.rb +1 -1
- data/lib/vector_number.rb +5 -5
- data/sig/vector_number.rbs +2 -0
- metadata +18 -19
- data/CHANGELOG.md +0 -174
- data/LICENSE.txt +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05d6547284c73b585a149026d1a0a123f5914e13c81856e2419180f44f05404c
|
4
|
+
data.tar.gz: 2b942db9aa53c4e8027540a630355f2defd64de96d3c90bbd55e539844f32bfa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8d079e1d0915ae151ac2dcb28621f672365e55efa0cb505ad3e846eb3619eababa4e39e5654098bb305fafa2ff602a1085c913c5d6fc8ea02922688087fb09b
|
7
|
+
data.tar.gz: f09e3d71187e9c202ff1a4960cbf19b7a02f679dc6b49b7b1e96e42e074a66990507262ab1648182217b8dacc980fe0ed777c48ac76db44734dccfdf34a7b488
|
data/README.md
CHANGED
@@ -1,17 +1,22 @@
|
|
1
1
|
# VectorNumber
|
2
2
|
|
3
|
-
|
4
|
-
> You may be viewing documentation for an older (or newer) version of the gem.
|
5
|
-
> Check badges below to see what the latest released version is.
|
6
|
-
> Look at [Changelog](https://github.com/trinistr/vector_number/blob/main/CHANGELOG.md)
|
7
|
-
> to see all versions, including unreleased changes!
|
8
|
-
|
9
|
-
Latest: [](https://rubygems.org/gems/vector_number)
|
3
|
+
[](https://rubygems.org/gems/vector_number)
|
10
4
|
[](https://github.com/trinistr/vector_number/actions/workflows/CI.yaml)
|
11
5
|
|
6
|
+
> [!TIP]
|
7
|
+
> You may be viewing documentation for an older (or newer) version of the gem. Look at [Changelog](https://github.com/trinistr/dicey/blob/main/CHANGELOG.md) to see all versions, including unreleased changes.
|
8
|
+
|
12
9
|
***
|
13
10
|
|
14
|
-
|
11
|
+
VectorNumber is a Ruby gem that provides a Numeric-like experience for doing arithmetics on heterogeneous objects, with more advanced operations based on real vector spaces available when needed.
|
12
|
+
|
13
|
+
Features:
|
14
|
+
- [Add and subtract](#basics) (almost) any object, with no setup or declaration.
|
15
|
+
- [Multiply and divide](#basics) vectors by any real number to create 1.35 of an array and -2 of a string. What does that mean? Only you know!
|
16
|
+
- [Use vectors instead of inbuilt numbers](#numerical-behavior) in most situtations with no difference in behavior. Or, use familiar methods from numerics with sane semantics!
|
17
|
+
- [Enumerate vectors in a hash-like fashion](#enumeration-and-hash-like-behavior), or transform to an array or hash as needed.
|
18
|
+
- Enjoy a mix of vector-, complex- and polynomial-like behavior at appropriate times.
|
19
|
+
- No dependencies, no extensions. It just works!
|
15
20
|
|
16
21
|
Similar projects:
|
17
22
|
- [vector_space](https://github.com/tomstuart/vector_space) aims to provide typed vector spaces with limited dimensions and nice formatting;
|
@@ -20,11 +25,23 @@ Similar projects:
|
|
20
25
|
|
21
26
|
However, none of them have been updated in *years*.
|
22
27
|
|
23
|
-
##
|
28
|
+
## Table of contents
|
24
29
|
|
25
|
-
|
30
|
+
- [Installation](#installation)
|
31
|
+
- [Ruby engine support status](#ruby-engine-support-status)
|
32
|
+
- [Usage](#usage)
|
33
|
+
- [Basics](#basics)
|
34
|
+
- [(Somewhat) advanced usage](#somewhat-advanced-usage)
|
35
|
+
- [Frozenness](#frozenness)
|
36
|
+
- [Numerical behavior](#numerical-behavior)
|
37
|
+
- [Enumeration and hash-like behavior](#enumeration-and-hash-like-behavior)
|
38
|
+
- [Development](#development)
|
39
|
+
- [Contributing](#contributing)
|
40
|
+
- [License](#license)
|
26
41
|
|
27
|
-
|
42
|
+
## Installation
|
43
|
+
|
44
|
+
Install with `gem`:
|
28
45
|
```sh
|
29
46
|
gem install vector_number
|
30
47
|
```
|
@@ -34,52 +51,100 @@ If using Bundler, add gem to your Gemfile:
|
|
34
51
|
gem "vector_number"
|
35
52
|
```
|
36
53
|
|
54
|
+
### Ruby engine support status
|
55
|
+
|
56
|
+
VectorNumber is developed on MRI (CRuby) but should work on other engines too.
|
57
|
+
- TruffleRuby: there are some minor differences in behavior, but otherwise works as expected.
|
58
|
+
- JRuby: significant problems, but may work, currently not tested.
|
59
|
+
- Other engines: untested, but should work, depending on compatibility with MRI.
|
60
|
+
|
37
61
|
## Usage
|
38
62
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
VectorNumber["string", "string", "string", "str"] # => (3⋅'string' + 1⋅'str')
|
45
|
-
VectorNumber[:s] * 2 + VectorNumber["string"] * 0.3 # => (2⋅s + 0.3⋅'string')
|
46
|
-
VectorNumber[:s] / 3 # => (1/3⋅s)
|
47
|
-
1/3r * VectorNumber[[]] # => (1/3⋅[])
|
48
|
-
```
|
63
|
+
> [!Note]
|
64
|
+
> - Latest API documentation from `main` branch is automatically deployed to [GitHub Pages](https://trinistr.github.io/vector_number).
|
65
|
+
> - Documentation for published versions is available on [RubyDoc](https://rubydoc.info/gems/vector_number).
|
66
|
+
|
67
|
+
### Basics
|
49
68
|
|
50
|
-
VectorNumbers are mostly useful for
|
69
|
+
VectorNumbers are mostly useful for tallying up heterogeneous objects:
|
51
70
|
```ruby
|
52
|
-
sum = VectorNumber[]
|
53
|
-
[4, "death", "death", 13, nil].each { sum = sum + _1 }
|
71
|
+
sum = [4, "death", "death", 13, nil].reduce(VectorNumber[], :+)
|
54
72
|
sum # => (17 + 2⋅'death' + 1⋅)
|
55
|
-
sum.to_a # => [[1, 17], ["death", 2], [nil, 1]]
|
56
73
|
sum.to_h # => {1=>17, "death"=>2, nil=>1}
|
57
|
-
|
74
|
+
sum.to_a # => [[1, 17], ["death", 2], [nil, 1]]
|
58
75
|
|
59
|
-
Alternatively, the same result can be equivalently (and more efficiently)
|
60
|
-
passing all values to a constructor:
|
61
|
-
```ruby
|
76
|
+
# Alternatively, the same result can be equivalently (and more efficiently)
|
77
|
+
# achieved by passing all values to a constructor:
|
62
78
|
VectorNumber[4, "death", "death", 13, nil]
|
63
79
|
VectorNumber.new([4, "death", "death", 13, nil])
|
64
80
|
```
|
65
81
|
|
66
|
-
|
82
|
+
Doing arithmetic with vectors is simple and intuitive:
|
83
|
+
```ruby
|
84
|
+
VectorNumber["string"] + "string" # => (2⋅'string')
|
85
|
+
VectorNumber["string"] - "str" # => (1⋅'string' - 1⋅'str')
|
86
|
+
VectorNumber[5] + VectorNumber["string"] - 0.5 # => (4.5 + 1⋅'string')
|
87
|
+
VectorNumber["string", "string", "string", "str"] # => (3⋅'string' + 1⋅'str')
|
88
|
+
# Multiply and divide by any real number:
|
89
|
+
VectorNumber[:s] * 2 + VectorNumber["string"] * 0.3 # => (2⋅s + 0.3⋅'string')
|
90
|
+
VectorNumber[:s] / VectorNumber[3] # => (1/3⋅s)
|
91
|
+
# Multiplication even works when the left operand is a regular number:
|
92
|
+
1/3r * VectorNumber[[]] # => (1/3⋅[])
|
93
|
+
```
|
67
94
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
95
|
+
### (Somewhat) advanced usage
|
96
|
+
|
97
|
+
> [!TIP]
|
98
|
+
> Look at API documentation for all methods.
|
99
|
+
|
100
|
+
#### Frozenness
|
101
|
+
VectorNumbers are always frozen, as a number should be. However, they hold references to units (keys), which aren't frozen or duplicated. It is the user's responsibility to ensure that keys aren't mutated, the same as it is for Hash.
|
102
|
+
|
103
|
+
As vectors are immutable, `+@`, `dup` and `clone` return the same instance.
|
104
|
+
|
105
|
+
#### Numerical behavior
|
106
|
+
VectorNumbers implement most of the methods you can find in `Numeric`, with appropriate behavior. For example:
|
107
|
+
- `abs` (`magnitude`) calculates length of the vector;
|
108
|
+
- `infinite?` checks whether any coefficient is infinite (or NaN), in the same way as `Complex` does it;
|
109
|
+
- `positive?` is true if all coefficients are positive, the same for `negative?` (though this is different from `Complex`) (and they can both be false);
|
110
|
+
- `round` and friends round each coefficient, with all the bells and whistles;
|
111
|
+
- `div` and `%` perform division and remainder operations elementwise;
|
112
|
+
- `5 < VectorNumber[6]` returns `true` and `5 < VectorNumber["string"]` raises `ArgumentError`, etc.
|
113
|
+
|
114
|
+
VectorNumbers, if only consisting of a real number, can mostly be used interchangeably with core numbers due to `coerce` and conversion (`to_i`, etc.) methods. They can even be used as array indices! Due to including `Comparable`, they can also participate in comparison and sorting.
|
115
|
+
|
116
|
+
#### Enumeration and Hash-like behavior
|
117
|
+
VectorNumbers implement `each` (`each_pair`) in the same way as Hash does, allowing `Enumerable` methods to be used in a familiar way.
|
118
|
+
|
119
|
+
There are also the usual `[]`, `unit?` (`key?`), `units` (`keys`), `coefficients` (`values`) methods. `to_h` and `to_a` can be used if a regular Hash or Array is needed.
|
120
|
+
|
121
|
+
> [!NOTE]
|
122
|
+
> Be aware that `[]` always returns `0` for "missing" units. `unit?` will return `false` for them.
|
72
123
|
|
73
124
|
## Development
|
74
125
|
|
75
|
-
After checking out the repo, run `
|
126
|
+
After checking out the repo, run `bundle install` to install dependencies. Then, run `rake spec` to run the tests, `rake rubocop` to lint code and check style compliance, `rake rbs` to validate signatures or just `rake` to do everything above. There is also `rake steep` to check typing, and `rake docs` to generate YARD documentation.
|
127
|
+
|
128
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment, or `bin/benchmark` to run a benchmark script and generate a StackProf flamegraph.
|
129
|
+
|
130
|
+
To install this gem onto your local machine, run `rake install`.
|
76
131
|
|
77
|
-
To
|
132
|
+
To release a new version, run `rake version:{major|minor|patch}`, and then run `rake release`, which will build the package and push the `.gem` file to [rubygems.org](https://rubygems.org). After that, push the release commit and tags to the repository with `git push --follow-tags`.
|
78
133
|
|
79
134
|
## Contributing
|
80
135
|
|
81
136
|
Bug reports and pull requests are welcome on GitHub at [https://github.com/trinistr/vector_number]().
|
82
137
|
|
138
|
+
### Checklist for a new or updated feature
|
139
|
+
|
140
|
+
- Running `rake spec` reports 100% coverage (unless it's impossible to achieve in one run).
|
141
|
+
- Running `rake rubocop` reports no offenses.
|
142
|
+
- Running `rake steep` reports no new warnings or errors.
|
143
|
+
- Tests cover the behavior and its interactions. 100% coverage *is not enough*, as it does not guarantee that all code paths are tested.
|
144
|
+
- Documentation is up-to-date: generate it with `rake docs` and read it.
|
145
|
+
- "*CHANGELOG.md*" lists the change if it has impact on users.
|
146
|
+
- "*README.md*" is updated if the feature should be visible there.
|
147
|
+
|
83
148
|
## License
|
84
149
|
|
85
|
-
|
150
|
+
This gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT), see [LICENSE.txt](https://github.com/trinistr/vector_number/blob/main/LICENSE.txt).
|
@@ -45,6 +45,7 @@ class VectorNumber
|
|
45
45
|
#
|
46
46
|
# Values are considered equal only if +other+ is a VectorNumber
|
47
47
|
# and it has exactly the same units and coefficients, though possibly in a different order.
|
48
|
+
# Additionally, `a.eql?(b)` implies `a.hash == b.hash`.
|
48
49
|
#
|
49
50
|
# Note that {#options} are not considered for equality.
|
50
51
|
#
|
@@ -69,6 +70,22 @@ class VectorNumber
|
|
69
70
|
end
|
70
71
|
end
|
71
72
|
|
73
|
+
# Generate an Integer hash value for self.
|
74
|
+
#
|
75
|
+
# Hash values are stable during runtime, but not between processes.
|
76
|
+
#
|
77
|
+
# @example
|
78
|
+
# VectorNumber["b", "a"].hash # => 3081872088394655324
|
79
|
+
# VectorNumber["a", "b", mult: :cross].hash # => 3081872088394655324
|
80
|
+
# VectorNumber["b", "c"].hash # => -1002381358514682371
|
81
|
+
#
|
82
|
+
# @return [Integer]
|
83
|
+
#
|
84
|
+
# @since 0.4.2
|
85
|
+
def hash
|
86
|
+
[self.class, @data].hash
|
87
|
+
end
|
88
|
+
|
72
89
|
# Compare to +other+ and return -1, 0, or 1
|
73
90
|
# if +self+ is less than, equal, or larger than +other+.
|
74
91
|
#
|
@@ -36,10 +36,10 @@ class VectorNumber
|
|
36
36
|
# @see Enumerator
|
37
37
|
#
|
38
38
|
# @since 0.1.0
|
39
|
-
def each(&)
|
39
|
+
def each(&block)
|
40
40
|
return to_enum { size } unless block_given?
|
41
41
|
|
42
|
-
@data.each(&)
|
42
|
+
@data.each(&block)
|
43
43
|
self
|
44
44
|
end
|
45
45
|
|
@@ -85,10 +85,10 @@ class VectorNumber
|
|
85
85
|
# @return [Hash{Object => Integer, Float, Rational, BigDecimal}]
|
86
86
|
#
|
87
87
|
# @since 0.1.0
|
88
|
-
def to_h(&)
|
88
|
+
def to_h(&block)
|
89
89
|
# TODO: Remove block argument.
|
90
90
|
if block_given?
|
91
|
-
@data.to_h(&)
|
91
|
+
@data.to_h(&block)
|
92
92
|
else
|
93
93
|
@data.dup
|
94
94
|
end
|
@@ -110,10 +110,12 @@ class VectorNumber
|
|
110
110
|
when :even then :half_even
|
111
111
|
else :half_up
|
112
112
|
end
|
113
|
-
new { _1.is_a?(BigDecimal) ? _1.round(digits, bd_mode) : _1.round(digits, half:) }
|
113
|
+
new { _1.is_a?(BigDecimal) ? _1.round(digits, bd_mode) : _1.round(digits, half: half) }
|
114
|
+
# :nocov:
|
114
115
|
else
|
115
|
-
new { _1.round(digits, half:) }
|
116
|
+
new { _1.round(digits, half: half) }
|
116
117
|
end
|
118
|
+
# :nocov:
|
117
119
|
end
|
118
120
|
end
|
119
121
|
end
|
@@ -8,6 +8,8 @@ class VectorNumber
|
|
8
8
|
# - refinement for +Complex#<=>+ to work with classes implementing +<=>+;
|
9
9
|
# - refinement for +Kernel#BigDecimal+ to work with classes implementing +to_d+.
|
10
10
|
#
|
11
|
+
# @note Refinements won't work on Ruby 3.0.
|
12
|
+
#
|
11
13
|
# @example activating refinements
|
12
14
|
# require "vector_number/numeric_refinements"
|
13
15
|
# using VectorNumber::NumericRefinements
|
@@ -41,7 +43,11 @@ class VectorNumber
|
|
41
43
|
end
|
42
44
|
|
43
45
|
if (Complex(1, 0) <=> VectorNumber[1]).nil?
|
44
|
-
refine(Complex)
|
46
|
+
refine(Complex) do
|
47
|
+
import_methods CommutativeShuttle
|
48
|
+
rescue
|
49
|
+
warn "Numeric refinements are not available on Ruby < 3.1"
|
50
|
+
end
|
45
51
|
end
|
46
52
|
|
47
53
|
# Refinement module to change Kernel#BigDecimal so it works with +#to_d+.
|
@@ -68,11 +74,17 @@ class VectorNumber
|
|
68
74
|
if value.respond_to?(:to_d)
|
69
75
|
ndigits.nil? ? value.to_d : value.to_d(ndigits)
|
70
76
|
else
|
71
|
-
ndigits.nil? ? super(value, exception:) : super
|
77
|
+
ndigits.nil? ? super(value, exception: exception) : super
|
72
78
|
end
|
73
79
|
end
|
74
80
|
end
|
75
81
|
|
76
|
-
|
82
|
+
if defined?(BigDecimal)
|
83
|
+
refine(Kernel) do
|
84
|
+
import_methods BigDecimalToD
|
85
|
+
rescue
|
86
|
+
warn "Numeric refinements are not available on Ruby < 3.1"
|
87
|
+
end
|
88
|
+
end
|
77
89
|
end
|
78
90
|
end
|
data/lib/vector_number.rb
CHANGED
@@ -107,12 +107,12 @@ class VectorNumber
|
|
107
107
|
# @yieldparam coefficient [Integer, Float, Rational, BigDecimal]
|
108
108
|
# @yieldreturn [Integer, Float, Rational, BigDecimal] new coefficient
|
109
109
|
# @raise [RangeError] if any pesky non-reals get where they shouldn't
|
110
|
-
def initialize(values = nil, options = nil, &)
|
110
|
+
def initialize(values = nil, options = nil, &transform)
|
111
111
|
# @type var options: Hash[Symbol, Object]
|
112
112
|
initialize_from(values)
|
113
|
-
apply_transform(&)
|
113
|
+
apply_transform(&transform)
|
114
114
|
finalize_contents
|
115
|
-
save_options(options, values:)
|
115
|
+
save_options(options, values: values)
|
116
116
|
@options.freeze
|
117
117
|
@data.freeze
|
118
118
|
freeze
|
@@ -152,8 +152,8 @@ class VectorNumber
|
|
152
152
|
# @yieldparam coefficient [Integer, Float, Rational, BigDecimal]
|
153
153
|
# @yieldreturn [Integer, Float, Rational, BigDecimal] new coefficient
|
154
154
|
# @return [VectorNumber]
|
155
|
-
def new(from = self, &)
|
156
|
-
self.class.new(from, options, &)
|
155
|
+
def new(from = self, &transform)
|
156
|
+
self.class.new(from, options, &transform)
|
157
157
|
end
|
158
158
|
|
159
159
|
# Check if +other+ is a real number.
|
data/sig/vector_number.rbs
CHANGED
metadata
CHANGED
@@ -1,26 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vector_number
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandr Bulancov
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies: []
|
13
|
-
description:
|
14
|
-
|
12
|
+
description: |
|
13
|
+
VectorNumber provides a Numeric-like experience for doing arithmetics on heterogeneous objects, with more advanced operations based on real vector spaces available when needed.
|
14
|
+
|
15
|
+
Features:
|
16
|
+
- Add and subtract (almost) any object, with no setup or declaration.
|
17
|
+
- Multiply and divide vectors by any real number to create 1.35 of an array and -2 of a string. What does that mean? Only you know!
|
18
|
+
- Use vectors instead of inbuilt numbers in most situtations with no difference in behavior. Or, use familiar methods from numerics with sane semantics!
|
19
|
+
- Enumerate vectors in a hash-like fashion, or transform to an array or hash as needed.
|
20
|
+
- Enjoy a mix of vector-, complex- and polynomial-like behavior at appropriate times.
|
21
|
+
- No dependencies, no extensions. It just works!
|
15
22
|
executables: []
|
16
23
|
extensions: []
|
17
24
|
extra_rdoc_files:
|
18
25
|
- README.md
|
19
|
-
- CHANGELOG.md
|
20
|
-
- LICENSE.txt
|
21
26
|
files:
|
22
|
-
- CHANGELOG.md
|
23
|
-
- LICENSE.txt
|
24
27
|
- README.md
|
25
28
|
- lib/vector_number.rb
|
26
29
|
- lib/vector_number/comparing.rb
|
@@ -39,31 +42,27 @@ licenses:
|
|
39
42
|
metadata:
|
40
43
|
homepage_uri: https://github.com/trinistr/vector_number
|
41
44
|
bug_tracker_uri: https://github.com/trinistr/vector_number/issues
|
42
|
-
documentation_uri: https://rubydoc.info/gems/vector_number/0.4.
|
43
|
-
source_code_uri: https://github.com/trinistr/vector_number/tree/v0.4.
|
44
|
-
changelog_uri: https://github.com/trinistr/vector_number/blob/v0.4.
|
45
|
+
documentation_uri: https://rubydoc.info/gems/vector_number/0.4.3
|
46
|
+
source_code_uri: https://github.com/trinistr/vector_number/tree/v0.4.3
|
47
|
+
changelog_uri: https://github.com/trinistr/vector_number/blob/v0.4.3/CHANGELOG.md
|
45
48
|
rubygems_mfa_required: 'true'
|
46
|
-
post_install_message:
|
47
49
|
rdoc_options:
|
48
50
|
- "--main"
|
49
51
|
- README.md
|
50
|
-
- "--files"
|
51
|
-
- CHANGELOG.md,LICENSE.txt
|
52
52
|
require_paths:
|
53
53
|
- lib
|
54
54
|
required_ruby_version: !ruby/object:Gem::Requirement
|
55
55
|
requirements:
|
56
56
|
- - ">="
|
57
57
|
- !ruby/object:Gem::Version
|
58
|
-
version: 3.
|
58
|
+
version: 3.0.0
|
59
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
61
|
- - ">="
|
62
62
|
- !ruby/object:Gem::Version
|
63
63
|
version: '0'
|
64
64
|
requirements: []
|
65
|
-
rubygems_version: 3.
|
66
|
-
signing_key:
|
65
|
+
rubygems_version: 3.6.9
|
67
66
|
specification_version: 4
|
68
|
-
summary:
|
67
|
+
summary: Add, subtract and do math with any objects
|
69
68
|
test_files: []
|
data/CHANGELOG.md
DELETED
@@ -1,174 +0,0 @@
|
|
1
|
-
# Changelog
|
2
|
-
|
3
|
-
All notable changes to this project will be documented in this file.
|
4
|
-
|
5
|
-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
6
|
-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
-
|
8
|
-
## [Next]
|
9
|
-
|
10
|
-
[Compare v0.4.1...main](https://github.com/trinistr/vector_number/compare/v0.4.1...main)
|
11
|
-
|
12
|
-
|
13
|
-
## [v0.4.1] — 2025-07-07
|
14
|
-
|
15
|
-
Small update to fix Changelog.
|
16
|
-
|
17
|
-
[Compare v0.4.0...v0.4.1](https://github.com/trinistr/vector_number/compare/v0.4.0...v0.4.1)
|
18
|
-
|
19
|
-
## [v0.4.0] — 2025-07-07
|
20
|
-
|
21
|
-
**Changed**
|
22
|
-
- [🍄 BREAKING] Change `R` and `I` constants to be `1` and `2` instead of `0i` and `1i` respectively.
|
23
|
-
Their values are still semi-private and should not be relied on.
|
24
|
-
- [🍄 BREAKING] Calling `new` with an unsupported value now raises `ArgumentError` instead of treating it like air.
|
25
|
-
- Optimize various initialization paths. It is now 1.5-2.5 times faster, depending on arguments.
|
26
|
-
- [🚀 CI] Disable JRuby testing on CI.
|
27
|
-
|
28
|
-
[Compare v0.3.1...v0.4.0](https://github.com/trinistr/vector_number/compare/v0.3.1...v0.4.0)
|
29
|
-
|
30
|
-
## [v0.3.1] — 2025-06-21
|
31
|
-
|
32
|
-
This is mostly a documentation update with a side of improved gemspec.
|
33
|
-
|
34
|
-
**Changed**
|
35
|
-
- Improve method documentation and unify documentation style across the board.
|
36
|
-
- Improve gemspec:
|
37
|
-
- change source code and changelog links to point to a tagged commit;
|
38
|
-
- add links to bugtracker and documentation (for appropriate version);
|
39
|
-
- properly add CHANGELOG.md to doc generation.
|
40
|
-
- Improve documentation for NumericRefinements to include examples and more info.
|
41
|
-
- `#dup` is now an alias of `#+@` with no change in function.
|
42
|
-
- `#abs` is now calculated from `#abs2` instead of the other way around to reduce errors.
|
43
|
-
|
44
|
-
**Fixed**
|
45
|
-
- Correct broken changelog link in gem metadata.
|
46
|
-
|
47
|
-
[Compare v0.3.0...v0.3.1](https://github.com/trinistr/vector_number/compare/v0.3.0...v0.3.1)
|
48
|
-
|
49
|
-
## [v0.3.0] — 2025-05-12
|
50
|
-
|
51
|
-
**Added**
|
52
|
-
- Add aliases to other operators:
|
53
|
-
`#neg` for `#-@`, `#add` for `#+`, `#sub` for `#-`, `#mult` for `#*`.
|
54
|
-
`#+@` was already practically aliased by `#dup`.
|
55
|
-
|
56
|
-
**Changed**
|
57
|
-
- [🍄 BREAKING] Long-existing but broken options feature is now fixed.
|
58
|
-
When creating new vector through any operation, participating vector's options
|
59
|
-
are copied to the new one. When several vectors are present, only first one matters.
|
60
|
-
- Both `#+@` and `#dup` are now aliases of `#itself` instead of full methods.
|
61
|
-
- [🚀 CI] "CI" workflow now reports status of all checks,
|
62
|
-
excluding allowed-to-fail workflows (currently JRuby and TruffleRuby).
|
63
|
-
|
64
|
-
[Compare v0.2.6...v0.3.0](https://github.com/trinistr/vector_number/compare/v0.2.6...v0.3.0)
|
65
|
-
|
66
|
-
## [v0.2.6] — 2025-04-30
|
67
|
-
|
68
|
-
**Added**
|
69
|
-
- Add `#div`, `#%` (aliased as `#modulo`), `#divmod` and `#remainder` methods.
|
70
|
-
- Add `#quo` alias to `#/`.
|
71
|
-
|
72
|
-
**Fixed**
|
73
|
-
- `#/`, `#fdiv` as well as new division methods now properly check for division by zero.
|
74
|
-
VectorNumber does not support this as not all Numeric classes do.
|
75
|
-
|
76
|
-
**Changed**
|
77
|
-
- [🚀 CI] Add Ruby 3.4 to CI.
|
78
|
-
|
79
|
-
[Compare v0.2.5...v0.2.6](https://github.com/trinistr/vector_number/compare/v0.2.5...v0.2.6)
|
80
|
-
|
81
|
-
## [v0.2.5] — 2025-02-26
|
82
|
-
|
83
|
-
Technical update after release to rubygems.org.
|
84
|
-
README was updated to reflect this change.
|
85
|
-
|
86
|
-
[Compare v0.2.4...v0.2.5](https://github.com/trinistr/vector_number/compare/v0.2.4...v0.2.5)
|
87
|
-
|
88
|
-
## [v0.2.4] — 2025-02-26
|
89
|
-
|
90
|
-
**Added**
|
91
|
-
- Add hash-like methods `#[]` and `#unit?` (aliased as `#key?`).
|
92
|
-
|
93
|
-
**Changed**
|
94
|
-
- [🍄 BREAKING] Change `positive?` and `negative?` to no longer return `nil`
|
95
|
-
when number is neither strictly positive or negative,
|
96
|
-
these cases will now return `false`.
|
97
|
-
- Make `VectorNumber.new` accept options when initializing from a VectorNumber
|
98
|
-
instead of only copying. Options will be merged.
|
99
|
-
- Remove `Initializing` module, move its methods to the actual class.
|
100
|
-
- Update development gems' versions.
|
101
|
-
|
102
|
-
**Fixed**
|
103
|
-
- `#dup` and `#clone` now behave exactly like Numeric versions, preventing unfreezing.
|
104
|
-
|
105
|
-
[Compare v0.2.3...v0.2.4](https://github.com/trinistr/vector_number/compare/v0.2.3...v0.2.4)
|
106
|
-
|
107
|
-
## [v0.2.3] — 2024-10-15
|
108
|
-
|
109
|
-
**Fixed**
|
110
|
-
- BigDecimal tests are now properly skipped when BigDecimal is not available, instead of always.
|
111
|
-
|
112
|
-
[Compare v0.2.2...v0.2.3](https://github.com/trinistr/vector_number/compare/v0.2.2...v0.2.3)
|
113
|
-
|
114
|
-
## [v0.2.2] — 2024-10-07
|
115
|
-
|
116
|
-
**Added**
|
117
|
-
- Add `#abs` (aliased as `#magnitude`) and `#abs2`.
|
118
|
-
- Add `#ceil`, `#floor` and `#round`.
|
119
|
-
|
120
|
-
**Changed**
|
121
|
-
- [🚀 CI] Add ruby 3.1.0, covering the earliest supported version, and ruby-next (3.4) to CI.
|
122
|
-
- [🚀 CI] Add JRuby and TruffleRuby to CI, without full support.
|
123
|
-
- [🚀 CI] Make tests runnable even without available `bigdecimal` gem.
|
124
|
-
|
125
|
-
**Fixed**
|
126
|
-
- `Kernel#BigDecimal` refinement now correctly works without `ndigits` argument.
|
127
|
-
|
128
|
-
[Compare v0.2.1...v0.2.2](https://github.com/trinistr/vector_number/compare/v0.2.1...v0.2.2)
|
129
|
-
|
130
|
-
## [v0.2.1] — 2024-08-24
|
131
|
-
|
132
|
-
**Added**
|
133
|
-
- Add `#*` and `#/` for working with real numbers.
|
134
|
-
- Add `#fdiv`, `#truncate`, `#nonnumeric?` and `#integer?`.
|
135
|
-
|
136
|
-
**Changed**
|
137
|
-
- Allow to use fully real VectorNumbers as real numbers.
|
138
|
-
|
139
|
-
**Fixed**
|
140
|
-
- Fix reversed result in refined `#<=>`.
|
141
|
-
|
142
|
-
**Removed**
|
143
|
-
- Remove `#to_str`, as VectorNumber is not a String-like object.
|
144
|
-
- Due to the above, `Kernel.BigDecimal` no longer works without refinements.
|
145
|
-
|
146
|
-
[Compare v0.2.0...v0.2.1](https://github.com/trinistr/vector_number/compare/v0.2.0...v0.2.1)
|
147
|
-
|
148
|
-
## [v0.2.0] — 2024-08-19
|
149
|
-
|
150
|
-
**Added**
|
151
|
-
- VectorNumbers can be created from any object or collection.
|
152
|
-
- Addition and subtraction are supported.
|
153
|
-
- VectorNumbers are mostly interoperable with core numbers.
|
154
|
-
|
155
|
-
[Compare v0.1.0...v0.2.0](https://github.com/trinistr/vector_number/compare/v0.1.0...v0.2.0)
|
156
|
-
|
157
|
-
## [v0.1.0] — 2024-05-09
|
158
|
-
|
159
|
-
- Initial work.
|
160
|
-
|
161
|
-
[Next]: https://github.com/trinistr/vector_number/tree/main
|
162
|
-
[v0.4.1]: https://github.com/trinistr/vector_number/tree/v0.4.1
|
163
|
-
[v0.4.0]: https://github.com/trinistr/vector_number/tree/v0.4.0
|
164
|
-
[v0.3.1]: https://github.com/trinistr/vector_number/tree/v0.3.1
|
165
|
-
[v0.3.0]: https://github.com/trinistr/vector_number/tree/v0.3.0
|
166
|
-
[v0.2.6]: https://github.com/trinistr/vector_number/tree/v0.2.6
|
167
|
-
[v0.2.5]: https://github.com/trinistr/vector_number/tree/v0.2.5
|
168
|
-
[v0.2.4]: https://github.com/trinistr/vector_number/tree/v0.2.4
|
169
|
-
[v0.2.3]: https://github.com/trinistr/vector_number/tree/v0.2.3
|
170
|
-
[v0.2.2]: https://github.com/trinistr/vector_number/tree/v0.2.2
|
171
|
-
[v0.2.1]: https://github.com/trinistr/vector_number/tree/v0.2.1
|
172
|
-
[v0.2.0]: https://github.com/trinistr/vector_number/tree/v0.2.0
|
173
|
-
[v0.1.0]: https://github.com/trinistr/vector_number/tree/v0.1.0
|
174
|
-
[🚀 CI]: https://github.com/trinistr/vector_number/actions/workflows/CI.yaml
|
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2024-2025 Alexandr Bulancov
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|