measurand 0.1.0 → 0.1.2
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 +15 -0
- data/lib/Measurand/VERSION.rb +1 -1
- data/lib/measurand.rb +5 -1
- data/test/Measurand/Measurand_test.rb +28 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3f7451fd4b4f04126d6972c38330e194122abd13c020e16afbbb2e8c33b537cf
|
|
4
|
+
data.tar.gz: 4368d50379adb53a21dec70907418ba842ebd2848013c042c35de4f677c4e5ab
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 831847f65e8dd96d99fadee93519f030202a4deaaf06cd0f0a6653c4923785245d5c2a26efe0fbb55f5011cd24fd1f2353fb61d41d9777625b6e74600b4eff62
|
|
7
|
+
data.tar.gz: d319a5eb42dcc32bc04fb57fb96ec0f40136f2987ca51cc8942c6e9692024938a3e930ac2df41540b619cda228439e8adf12737ad95895d4c6b5b9b0ab926277
|
data/CHANGELOG
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 20260817
|
|
4
|
+
|
|
5
|
+
0.1.2: Measurand#/ divided two integer values as integers.
|
|
6
|
+
|
|
7
|
+
1. ~ Measurand#/: through Numeric#quo rather than #/, so that two Integer values divide exactly. A ratio of two integer counts came back as nothing at all — 9579583 over 10900458 gave 0 rather than 0.8788 — which is what a speedup or a rate is made of, and integer counts are what a clock reads in. A Float value stays a Float, and the partials were already in Float and are unaffected. duration.rb met the same defect at its 0.5.0 and took the same fix.
|
|
8
|
+
2. + test/Measurand/Measurand_test.rb: that two integer values divide exactly, and that two exact ones keep a Rational.
|
|
9
|
+
3. + test/Measurand/Measurand_test.rb: that Measurand#** carries no such defect, an integer raised to a negative exponent giving a Rational rather than truncating, in the value and in the derivative alike. Integer#** promotes where Integer#/ truncates, which is Ruby's inconsistency and not this gem's, and nothing here would have said so.
|
|
10
|
+
4. ~ Measurand::VERSION: /0.1.1/0.1.2/
|
|
11
|
+
|
|
12
|
+
0.1.1: Populate the .gitignore, which had been committed empty.
|
|
13
|
+
|
|
14
|
+
1. ~ .gitignore: 47 lines, covering gem builds, bundler, RDoc and YARD output, .DS_Store, editor files, the Ruby version managers, test artefacts and .claude. The file was created empty by the root commit and nothing had since filled it in.
|
|
15
|
+
2. ~ Measurand::VERSION: /0.1.0/0.1.1/
|
|
16
|
+
|
|
17
|
+
|
|
3
18
|
## 20260815
|
|
4
19
|
|
|
5
20
|
0.1.0: + Measurand#place, Measurand#rounded_uncertainty.
|
data/lib/Measurand/VERSION.rb
CHANGED
data/lib/measurand.rb
CHANGED
|
@@ -84,9 +84,13 @@ class Measurand
|
|
|
84
84
|
self.class.derived(@value * other.value, combine(other.value, other, @value))
|
|
85
85
|
end
|
|
86
86
|
|
|
87
|
+
# Through #quo rather than #/, so that two Integer values divide exactly:
|
|
88
|
+
# 1.quo(3) is (1/3) where 1 / 3 is 0, and a ratio of two integer counts would
|
|
89
|
+
# otherwise come back as nothing at all. A Float value stays a Float. The
|
|
90
|
+
# partials were already in Float and are unaffected.
|
|
87
91
|
def /(other)
|
|
88
92
|
other = wrap(other)
|
|
89
|
-
self.class.derived(@value
|
|
93
|
+
self.class.derived(@value.quo(other.value), combine(1.0 / other.value, other, -@value.to_f / (other.value ** 2)))
|
|
90
94
|
end
|
|
91
95
|
|
|
92
96
|
def **(other)
|
|
@@ -203,4 +203,32 @@ describe Measurand do
|
|
|
203
203
|
_(a.overlaps?(Measurand.new(5.3, 0.1))).must_equal false
|
|
204
204
|
end
|
|
205
205
|
end
|
|
206
|
+
|
|
207
|
+
describe "division of integer values" do
|
|
208
|
+
it "divides exactly rather than as integers" do
|
|
209
|
+
_((Measurand.new(9_579_583, 84) / Measurand.new(10_900_458, 84)).value.to_f) \
|
|
210
|
+
.must_be_close_to(0.878824, 0.000001)
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
it "keeps a Rational where both are exact" do
|
|
214
|
+
_((Measurand.new(1) / Measurand.new(3)).value).must_equal(Rational(1, 3))
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
# Integer#** promotes to Rational where Integer#/ truncates, so the defect
|
|
219
|
+
# fixed above has no counterpart here. Held under test all the same, since
|
|
220
|
+
# nothing in Measurand says so and the two operators read alike.
|
|
221
|
+
describe "exponentiation of integer values" do
|
|
222
|
+
it "stays exact under a negative exponent" do
|
|
223
|
+
_((Measurand.new(2, 0.1) ** -1).value).must_equal(Rational(1, 2))
|
|
224
|
+
_((Measurand.new(8, 0.1) ** -1).value).must_equal(Rational(1, 8))
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
it "propagates through a derivative which is exact for the same reason" do
|
|
228
|
+
_((Measurand.new(2, 0.1) ** -1).uncertainty).must_be_close_to(0.025, 1e-9)
|
|
229
|
+
_((Measurand.new(8, 0.1) ** -1).uncertainty).must_be_close_to(0.0015625, 1e-9)
|
|
230
|
+
_((Measurand.new(2, 0.1) ** 3).uncertainty).must_be_close_to(1.2, 1e-9)
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
|
|
206
234
|
end
|