author | Claus Gittinger <cg@exept.de> |
Thu, 27 Jun 2019 16:34:40 +0200 | |
changeset 24379 | 852be153b0ec |
parent 21929 | 1b3b40b8b16c |
child 25014 | a75b53bdb6c3 |
permissions | -rw-r--r-- |
10825 | 1 |
" |
2 |
COPYRIGHT (c) 2007 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
"{ Package: 'stx:libbasic' }" |
|
13 |
||
18832 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
10825 | 16 |
Number subclass:#MeasurementValue |
17 |
instanceVariableNames:'value minValue maxValue' |
|
11465 | 18 |
classVariableNames:'MeasurementValueZero' |
10825 | 19 |
poolDictionaries:'' |
20 |
category:'Magnitude-Numbers' |
|
21 |
! |
|
22 |
||
23 |
!MeasurementValue class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 2007 by eXept Software AG |
|
28 |
All Rights Reserved |
|
29 |
||
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
39 |
documentation |
|
40 |
" |
|
41 |
A MeasurementValue is a numeric value with an error, such as returned |
|
42 |
by measurement devices (Volt-Meter). For example, if a measurement-device has |
|
43 |
an error of 10%, a measured value of 20 could be any value between 18 and 22. |
|
44 |
||
45 |
Arithmetic operations keep track of the error; if any operand is a MeasurementValue, |
|
46 |
the operation returns a MeasurementValue as result. |
|
47 |
||
48 |
This class is possibly unfinished and needs more arithmetic methods. |
|
49 |
For now, the stuff found here represents our needs and more might be added in the future. |
|
50 |
||
11456 | 51 |
Also notice, that instances do not keep the error as a fraction, but instead a min. and maxValue. |
11606 | 52 |
That means, that we can handle the case where the error is different in |
11456 | 53 |
the positive and negative directions. |
11607 | 54 |
I am not sure if this is more flexibility than needed in the long run. |
11456 | 55 |
|
10825 | 56 |
[author:] |
57 |
Claus Gittinger |
|
58 |
||
59 |
[see also:] |
|
60 |
Number |
|
61 |
Float ShortFloat Fraction FixedPoint Integer Complex |
|
62 |
FloatArray DoubleArray |
|
63 |
" |
|
64 |
! |
|
65 |
||
66 |
examples |
|
67 |
" |
|
21929 | 68 |
Instance creation message in number: |
69 |
[exBegin] |
|
70 |
(10 +/- 1) |
|
71 |
[exEnd] |
|
72 |
||
73 |
arithmetic; notice, how the errors accumulate: |
|
74 |
[exBegin] |
|
75 |
(100 +/- 5) * 2 |
|
76 |
(100 +/- 5) * (100 +/- 10) |
|
77 |
(100 +/- 5) + (100 +/- 10) |
|
78 |
(100 +/- 5) - (100 +/- 10) |
|
79 |
[exEnd] |
|
80 |
||
81 |
again see, how the errors accumulate... |
|
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
82 |
[exBegin] |
10825 | 83 |
|voltage current power| |
84 |
||
85 |
voltage := MeasurementValue value:10 error:0.05. |
|
86 |
current := MeasurementValue value:2 error:0.1. |
|
87 |
power := voltage * current. |
|
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
88 |
power. |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
89 |
power minValue. |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
90 |
power maxValue. |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
91 |
[exEnd] |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
92 |
|
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
93 |
[exBegin] |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
94 |
|voltage current power| |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
95 |
|
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
96 |
voltage := MeasurementValue value:10 error:0.05. |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
97 |
current := 2. |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
98 |
power := voltage * current. |
10825 | 99 |
power |
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
100 |
[exEnd] |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
101 |
|
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
102 |
[exBegin] |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
103 |
|voltage doubleVoltage| |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
104 |
|
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
105 |
voltage := MeasurementValue value:10 error:0.1. |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
106 |
doubleVoltage := 2 * voltage. |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
107 |
doubleVoltage |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
108 |
[exEnd] |
10825 | 109 |
" |
110 |
! ! |
|
111 |
||
112 |
!MeasurementValue class methodsFor:'instance creation'! |
|
113 |
||
14445 | 114 |
value:valueArg error:errorArg |
10825 | 115 |
"return a new measurementValue with a given value and an error (fraction)" |
116 |
||
14445 | 117 |
^ self new value:valueArg error:errorArg |
10825 | 118 |
|
14445 | 119 |
"10 with an error of 20%: |
120 |
||
10825 | 121 |
MeasurementValue value:10 error:0.2 |
122 |
" |
|
123 |
! |
|
124 |
||
14445 | 125 |
value:valueArg minValue:minArg maxValue:maxArg |
10825 | 126 |
"return a new measurementValue with a given value and an error given as min-max values. |
127 |
Use this, if the error is not the same in both directions" |
|
128 |
||
14445 | 129 |
^ self new value:valueArg minValue:minArg maxValue:maxArg |
10825 | 130 |
|
14445 | 131 |
"an order of magnitude error: |
132 |
||
21929 | 133 |
MeasurementValue value:5 minValue:1 maxValue:10 |
134 |
||
135 |
10 percent: |
|
136 |
||
137 |
MeasurementValue value:10 minValue:9 maxValue:11 |
|
10825 | 138 |
" |
21929 | 139 |
|
140 |
"Modified (comment): / 01-07-2017 / 19:28:32 / cg" |
|
10825 | 141 |
! ! |
142 |
||
11465 | 143 |
!MeasurementValue class methodsFor:'constants'! |
144 |
||
11466 | 145 |
unity |
146 |
"return the neutral element for multiplication" |
|
147 |
||
148 |
^ 1 |
|
149 |
||
150 |
" |
|
151 |
self unity |
|
152 |
" |
|
153 |
! |
|
154 |
||
11465 | 155 |
zero |
156 |
"return the neutral element for addition (0 +/- 0)" |
|
157 |
||
158 |
MeasurementValueZero isNil ifTrue:[ |
|
159 |
MeasurementValueZero := self value:0 minValue:0 maxValue:0 |
|
160 |
]. |
|
161 |
^ MeasurementValueZero |
|
162 |
||
163 |
" |
|
164 |
self zero |
|
165 |
" |
|
166 |
! ! |
|
167 |
||
10825 | 168 |
!MeasurementValue methodsFor:'accessing'! |
169 |
||
170 |
maxValue |
|
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
171 |
"the maximum possible value, considerung what has been measured and what the measurement error is" |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
172 |
|
10825 | 173 |
^ maxValue |
174 |
! |
|
175 |
||
176 |
minValue |
|
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
177 |
"the minimum possible value, considerung what has been measured and what the measurement error is" |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
178 |
|
10825 | 179 |
^ minValue |
180 |
! |
|
181 |
||
182 |
value |
|
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
183 |
"the measured value" |
10825 | 184 |
|
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
185 |
^ value |
10825 | 186 |
! ! |
187 |
||
188 |
!MeasurementValue methodsFor:'arithmetic'! |
|
189 |
||
190 |
* aNumber |
|
11726 | 191 |
"return the product of the receiver and the argument. |
192 |
Care for the error to propagate into the result." |
|
193 |
||
10825 | 194 |
^ MeasurementValue new |
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
195 |
value:(value * aNumber value) |
14445 | 196 |
minValue:((minValue * aNumber minValue) min:(maxValue * aNumber minValue)) |
197 |
maxValue:((maxValue * aNumber maxValue) max:(minValue * aNumber maxValue)) |
|
198 |
||
199 |
" |
|
200 |
(MeasurementValue value:-10 error:0.2) * (MeasurementValue value:-10 error:0.2) |
|
201 |
(MeasurementValue value:-10 error:0.2) * 2 |
|
202 |
" |
|
10825 | 203 |
! |
204 |
||
205 |
+ aNumber |
|
11726 | 206 |
"return the sum of the receiver and the argument. |
207 |
Care for the error to propagate into the result." |
|
208 |
||
10825 | 209 |
^ MeasurementValue new |
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
210 |
value:(value + aNumber value) |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
211 |
minValue:(minValue + aNumber minValue) |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
212 |
maxValue:(maxValue + aNumber maxValue) |
14445 | 213 |
|
214 |
" |
|
215 |
(MeasurementValue value:-10 error:0.2) + (MeasurementValue value:-10 error:0.2) |
|
216 |
(MeasurementValue value:-10 error:0.2) + 2 |
|
217 |
" |
|
10825 | 218 |
! |
219 |
||
220 |
- aNumber |
|
11726 | 221 |
"return the difference of the receiver and the argument. |
222 |
Care for the error to propagate into the result." |
|
223 |
||
10825 | 224 |
^ MeasurementValue new |
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
225 |
value:(value - aNumber value) |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
226 |
minValue:(minValue - aNumber maxValue) |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
227 |
maxValue:(maxValue - aNumber minValue) |
14445 | 228 |
|
229 |
" |
|
230 |
(MeasurementValue value:-10 error:0.2) - (MeasurementValue value:-10 error:0.2) |
|
231 |
(MeasurementValue value:-10 error:0.2) - 10 |
|
232 |
(MeasurementValue value:10 error:0.2) - 10 |
|
233 |
" |
|
10825 | 234 |
! |
235 |
||
236 |
/ aNumber |
|
11726 | 237 |
"return the quotient of the receiver and the argument. |
238 |
Care for the error to propagate into the result." |
|
239 |
||
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
240 |
^ MeasurementValue new |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
241 |
value:(value / aNumber value) |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
242 |
minValue:(minValue / aNumber maxValue) |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
243 |
maxValue:(maxValue / aNumber minValue) |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
244 |
! ! |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
245 |
|
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
246 |
!MeasurementValue methodsFor:'coercing & converting'! |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
247 |
|
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
248 |
+/- error |
14008 | 249 |
"return a MeasurementValue with a given error." |
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
250 |
|
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
251 |
"/ what should I do here - take the new error, |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
252 |
"/ or multiply them ???? |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
253 |
self error. |
10825 | 254 |
|
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
255 |
minValue := value - error. |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
256 |
maxValue := value + error. |
14008 | 257 |
|
258 |
"Modified (comment): / 14-02-2012 / 14:17:39 / cg" |
|
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
259 |
! |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
260 |
|
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
261 |
coerce:aNumber |
18832 | 262 |
"convert the argument aNumber into an instance of the receiver's class and return it." |
11717 | 263 |
|
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
264 |
^ MeasurementValue value:aNumber minValue:aNumber maxValue:aNumber |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
265 |
! |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
266 |
|
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
267 |
generality |
11717 | 268 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
269 |
||
18832 | 270 |
"/ adding 1 to the value's generality has the subtle side effect of enforcing |
11717 | 271 |
"/ a call to coerce: for mixed type operations (i.e. Int * MeasurementValue). |
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
272 |
"/ try it. |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
273 |
|
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
274 |
^ value generality + 1 |
10825 | 275 |
! ! |
276 |
||
277 |
!MeasurementValue methodsFor:'comparing'! |
|
278 |
||
279 |
< aNumber |
|
11726 | 280 |
"return true, if the argument is greater than the receiver. |
281 |
Care for the error - i.e. compare against my maximum-value" |
|
282 |
||
10825 | 283 |
^ maxValue < aNumber |
284 |
! |
|
285 |
||
11465 | 286 |
= aNumber |
11726 | 287 |
"hard to tell, what we want here... |
288 |
How about: aNumber between:minValue and:maxValue ???" |
|
11465 | 289 |
|
290 |
^ value = aNumber value |
|
291 |
and:[ minValue = aNumber minValue |
|
292 |
and:[ maxValue = aNumber maxValue ]] |
|
293 |
! |
|
294 |
||
16274 | 295 |
hash |
296 |
^ value hash |
|
297 |
! |
|
298 |
||
10825 | 299 |
lessFromFloat:aFloat |
300 |
"aFloat < self ?" |
|
301 |
||
302 |
^ aFloat < minValue |
|
303 |
! |
|
304 |
||
305 |
lessFromInteger:anInteger |
|
306 |
"anInteger < self ?" |
|
307 |
||
308 |
^ anInteger < minValue |
|
309 |
! ! |
|
310 |
||
311 |
!MeasurementValue methodsFor:'printing & storing'! |
|
312 |
||
313 |
printOn:aStream |
|
11459 | 314 |
aStream nextPutAll:'('. |
315 |
(maxValue-value) = (value-minValue) ifTrue:[ |
|
316 |
value storeOn:aStream. |
|
317 |
aStream nextPutAll:' +/- '. |
|
14445 | 318 |
(maxValue-value) abs storeOn:aStream |
11459 | 319 |
] ifFalse:[ |
320 |
aStream nextPutAll:'MeasurementValue value:'. |
|
321 |
value storeOn:aStream. |
|
322 |
aStream nextPutAll:' minValue:'. |
|
323 |
minValue storeOn:aStream. |
|
324 |
aStream nextPutAll:' maxValue:'. |
|
325 |
maxValue storeOn:aStream. |
|
326 |
]. |
|
10825 | 327 |
')' printOn:aStream. |
11459 | 328 |
|
329 |
" |
|
330 |
(5 +/- 1) storeString |
|
331 |
(MeasurementValue value:5 minValue:3 maxValue:8) storeString |
|
332 |
" |
|
10825 | 333 |
! ! |
334 |
||
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
335 |
!MeasurementValue methodsFor:'private accessing'! |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
336 |
|
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
337 |
value:valueArg error:errorFraction |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
338 |
self |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
339 |
value:valueArg |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
340 |
minValue:(valueArg * (1-errorFraction)) |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
341 |
maxValue:(valueArg * (1+errorFraction)). |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
342 |
! |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
343 |
|
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
344 |
value:valueArg minValue:minValueArg maxValue:maxValueArg |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
345 |
value := valueArg. |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
346 |
minValue := minValueArg. |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
347 |
maxValue := maxValueArg. |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
348 |
! ! |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
349 |
|
14445 | 350 |
!MeasurementValue methodsFor:'queries'! |
351 |
||
352 |
error |
|
353 |
"the relative error. |
|
354 |
If the error is different in the min/max direction, the larger error is returned here" |
|
355 |
||
356 |
^ self errorHigh max:(self errorLow) |
|
357 |
||
358 |
" |
|
359 |
(MeasurementValue value:10 error:0.2) errorLow |
|
360 |
(MeasurementValue value:10 error:0.2) errorHigh |
|
361 |
(MeasurementValue value:10 error:0.2) error |
|
362 |
" |
|
363 |
! |
|
364 |
||
365 |
errorHigh |
|
366 |
"the relative error on the max side" |
|
367 |
||
368 |
^ (value - maxValue) abs / value |
|
369 |
||
370 |
" |
|
371 |
(MeasurementValue value:10 error:0.2) errorLow |
|
372 |
(MeasurementValue value:10 error:0.2) errorHigh |
|
373 |
(MeasurementValue value:10 error:0.2) error |
|
374 |
(MeasurementValue value:20 error:0.2) errorLow |
|
375 |
(MeasurementValue value:20 minValue:1 maxValue:100) errorLow |
|
376 |
(MeasurementValue value:20 minValue:1 maxValue:100) errorHigh |
|
377 |
(MeasurementValue value:20 minValue:1 maxValue:100) error |
|
378 |
" |
|
379 |
! |
|
380 |
||
381 |
errorLow |
|
382 |
"the relative error on the min side" |
|
383 |
||
384 |
^ (value - minValue) abs / value |
|
385 |
||
386 |
" |
|
387 |
(MeasurementValue value:10 error:0.2) errorLow |
|
388 |
(MeasurementValue value:10 error:0.2) errorHigh |
|
389 |
(MeasurementValue value:10 error:0.2) error |
|
390 |
(MeasurementValue value:20 error:0.2) errorLow |
|
391 |
(MeasurementValue value:20 minValue:1 maxValue:100) errorLow |
|
392 |
(MeasurementValue value:20 minValue:1 maxValue:100) errorHigh |
|
393 |
(MeasurementValue value:20 minValue:1 maxValue:100) error |
|
394 |
" |
|
395 |
! ! |
|
396 |
||
10825 | 397 |
!MeasurementValue methodsFor:'testing'! |
398 |
||
399 |
between:min and:max |
|
400 |
minValue < min ifTrue:[^ false]. |
|
401 |
maxValue > max ifTrue:[^ false]. |
|
402 |
^ true |
|
403 |
! ! |
|
404 |
||
405 |
!MeasurementValue class methodsFor:'documentation'! |
|
406 |
||
407 |
version |
|
18832 | 408 |
^ '$Header$' |
10825 | 409 |
! ! |
16274 | 410 |