author | Claus Gittinger <cg@exept.de> |
Sun, 01 Dec 2019 05:27:11 +0100 | |
changeset 25014 | a75b53bdb6c3 |
parent 21929 | 1b3b40b8b16c |
child 25254 | 41d6e0766006 |
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 |
||
25014 | 143 |
!MeasurementValue class methodsFor:'coercing & converting'! |
144 |
||
145 |
coerce:aNumber |
|
146 |
"convert the argument aNumber into an instance of the receiver's class and return it." |
|
147 |
||
148 |
^ MeasurementValue value:aNumber minValue:aNumber maxValue:aNumber |
|
149 |
! ! |
|
150 |
||
11465 | 151 |
!MeasurementValue class methodsFor:'constants'! |
152 |
||
11466 | 153 |
unity |
154 |
"return the neutral element for multiplication" |
|
155 |
||
156 |
^ 1 |
|
157 |
||
158 |
" |
|
159 |
self unity |
|
160 |
" |
|
161 |
! |
|
162 |
||
11465 | 163 |
zero |
164 |
"return the neutral element for addition (0 +/- 0)" |
|
165 |
||
166 |
MeasurementValueZero isNil ifTrue:[ |
|
167 |
MeasurementValueZero := self value:0 minValue:0 maxValue:0 |
|
168 |
]. |
|
169 |
^ MeasurementValueZero |
|
170 |
||
171 |
" |
|
172 |
self zero |
|
173 |
" |
|
174 |
! ! |
|
175 |
||
10825 | 176 |
!MeasurementValue methodsFor:'accessing'! |
177 |
||
178 |
maxValue |
|
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
179 |
"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
|
180 |
|
10825 | 181 |
^ maxValue |
182 |
! |
|
183 |
||
184 |
minValue |
|
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
185 |
"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
|
186 |
|
10825 | 187 |
^ minValue |
188 |
! |
|
189 |
||
190 |
value |
|
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
191 |
"the measured value" |
10825 | 192 |
|
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
193 |
^ value |
10825 | 194 |
! ! |
195 |
||
196 |
!MeasurementValue methodsFor:'arithmetic'! |
|
197 |
||
198 |
* aNumber |
|
11726 | 199 |
"return the product of the receiver and the argument. |
200 |
Care for the error to propagate into the result." |
|
201 |
||
10825 | 202 |
^ MeasurementValue new |
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
203 |
value:(value * aNumber value) |
14445 | 204 |
minValue:((minValue * aNumber minValue) min:(maxValue * aNumber minValue)) |
205 |
maxValue:((maxValue * aNumber maxValue) max:(minValue * aNumber maxValue)) |
|
206 |
||
207 |
" |
|
208 |
(MeasurementValue value:-10 error:0.2) * (MeasurementValue value:-10 error:0.2) |
|
209 |
(MeasurementValue value:-10 error:0.2) * 2 |
|
210 |
" |
|
10825 | 211 |
! |
212 |
||
213 |
+ aNumber |
|
11726 | 214 |
"return the sum of the receiver and the argument. |
215 |
Care for the error to propagate into the result." |
|
216 |
||
10825 | 217 |
^ MeasurementValue new |
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
218 |
value:(value + aNumber value) |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
219 |
minValue:(minValue + aNumber minValue) |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
220 |
maxValue:(maxValue + aNumber maxValue) |
14445 | 221 |
|
222 |
" |
|
223 |
(MeasurementValue value:-10 error:0.2) + (MeasurementValue value:-10 error:0.2) |
|
224 |
(MeasurementValue value:-10 error:0.2) + 2 |
|
225 |
" |
|
10825 | 226 |
! |
227 |
||
228 |
- aNumber |
|
11726 | 229 |
"return the difference of the receiver and the argument. |
230 |
Care for the error to propagate into the result." |
|
231 |
||
10825 | 232 |
^ MeasurementValue new |
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
233 |
value:(value - aNumber value) |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
234 |
minValue:(minValue - aNumber maxValue) |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
235 |
maxValue:(maxValue - aNumber minValue) |
14445 | 236 |
|
237 |
" |
|
238 |
(MeasurementValue value:-10 error:0.2) - (MeasurementValue value:-10 error:0.2) |
|
239 |
(MeasurementValue value:-10 error:0.2) - 10 |
|
240 |
(MeasurementValue value:10 error:0.2) - 10 |
|
241 |
" |
|
10825 | 242 |
! |
243 |
||
244 |
/ aNumber |
|
11726 | 245 |
"return the quotient of the receiver and the argument. |
246 |
Care for the error to propagate into the result." |
|
247 |
||
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
248 |
^ MeasurementValue new |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
249 |
value:(value / aNumber value) |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
250 |
minValue:(minValue / aNumber maxValue) |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
251 |
maxValue:(maxValue / aNumber minValue) |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
252 |
! ! |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
253 |
|
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
254 |
!MeasurementValue methodsFor:'coercing & converting'! |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
255 |
|
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
256 |
+/- error |
14008 | 257 |
"return a MeasurementValue with a given error." |
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
258 |
|
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
259 |
"/ what should I do here - take the new error, |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
260 |
"/ or multiply them ???? |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
261 |
self error. |
10825 | 262 |
|
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
263 |
minValue := value - error. |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
264 |
maxValue := value + error. |
14008 | 265 |
|
266 |
"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
|
267 |
! |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
268 |
|
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
269 |
coerce:aNumber |
18832 | 270 |
"convert the argument aNumber into an instance of the receiver's class and return it." |
11717 | 271 |
|
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
272 |
^ MeasurementValue value:aNumber minValue:aNumber maxValue:aNumber |
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 |
|
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
275 |
generality |
11717 | 276 |
"return the generality value - see ArithmeticValue>>retry:coercing:" |
277 |
||
18832 | 278 |
"/ adding 1 to the value's generality has the subtle side effect of enforcing |
11717 | 279 |
"/ 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
|
280 |
"/ try it. |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
281 |
|
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
282 |
^ value generality + 1 |
10825 | 283 |
! ! |
284 |
||
285 |
!MeasurementValue methodsFor:'comparing'! |
|
286 |
||
287 |
< aNumber |
|
11726 | 288 |
"return true, if the argument is greater than the receiver. |
289 |
Care for the error - i.e. compare against my maximum-value" |
|
290 |
||
10825 | 291 |
^ maxValue < aNumber |
292 |
! |
|
293 |
||
11465 | 294 |
= aNumber |
11726 | 295 |
"hard to tell, what we want here... |
296 |
How about: aNumber between:minValue and:maxValue ???" |
|
11465 | 297 |
|
298 |
^ value = aNumber value |
|
299 |
and:[ minValue = aNumber minValue |
|
300 |
and:[ maxValue = aNumber maxValue ]] |
|
301 |
! |
|
302 |
||
16274 | 303 |
hash |
304 |
^ value hash |
|
305 |
! |
|
306 |
||
10825 | 307 |
lessFromFloat:aFloat |
308 |
"aFloat < self ?" |
|
309 |
||
310 |
^ aFloat < minValue |
|
311 |
! |
|
312 |
||
313 |
lessFromInteger:anInteger |
|
314 |
"anInteger < self ?" |
|
315 |
||
316 |
^ anInteger < minValue |
|
317 |
! ! |
|
318 |
||
319 |
!MeasurementValue methodsFor:'printing & storing'! |
|
320 |
||
321 |
printOn:aStream |
|
11459 | 322 |
aStream nextPutAll:'('. |
323 |
(maxValue-value) = (value-minValue) ifTrue:[ |
|
324 |
value storeOn:aStream. |
|
325 |
aStream nextPutAll:' +/- '. |
|
14445 | 326 |
(maxValue-value) abs storeOn:aStream |
11459 | 327 |
] ifFalse:[ |
328 |
aStream nextPutAll:'MeasurementValue value:'. |
|
329 |
value storeOn:aStream. |
|
330 |
aStream nextPutAll:' minValue:'. |
|
331 |
minValue storeOn:aStream. |
|
332 |
aStream nextPutAll:' maxValue:'. |
|
333 |
maxValue storeOn:aStream. |
|
334 |
]. |
|
10825 | 335 |
')' printOn:aStream. |
11459 | 336 |
|
337 |
" |
|
338 |
(5 +/- 1) storeString |
|
339 |
(MeasurementValue value:5 minValue:3 maxValue:8) storeString |
|
340 |
" |
|
10825 | 341 |
! ! |
342 |
||
11457
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
343 |
!MeasurementValue methodsFor:'private accessing'! |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
344 |
|
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
345 |
value:valueArg error:errorFraction |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
346 |
self |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
347 |
value:valueArg |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
348 |
minValue:(valueArg * (1-errorFraction)) |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
349 |
maxValue:(valueArg * (1+errorFraction)). |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
350 |
! |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
351 |
|
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
352 |
value:valueArg minValue:minValueArg maxValue:maxValueArg |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
353 |
value := valueArg. |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
354 |
minValue := minValueArg. |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
355 |
maxValue := maxValueArg. |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
356 |
! ! |
5ff638783ee0
double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents:
11456
diff
changeset
|
357 |
|
14445 | 358 |
!MeasurementValue methodsFor:'queries'! |
359 |
||
360 |
error |
|
361 |
"the relative error. |
|
362 |
If the error is different in the min/max direction, the larger error is returned here" |
|
363 |
||
364 |
^ self errorHigh max:(self errorLow) |
|
365 |
||
366 |
" |
|
367 |
(MeasurementValue value:10 error:0.2) errorLow |
|
368 |
(MeasurementValue value:10 error:0.2) errorHigh |
|
369 |
(MeasurementValue value:10 error:0.2) error |
|
370 |
" |
|
371 |
! |
|
372 |
||
373 |
errorHigh |
|
374 |
"the relative error on the max side" |
|
375 |
||
376 |
^ (value - maxValue) abs / value |
|
377 |
||
378 |
" |
|
379 |
(MeasurementValue value:10 error:0.2) errorLow |
|
380 |
(MeasurementValue value:10 error:0.2) errorHigh |
|
381 |
(MeasurementValue value:10 error:0.2) error |
|
382 |
(MeasurementValue value:20 error:0.2) errorLow |
|
383 |
(MeasurementValue value:20 minValue:1 maxValue:100) errorLow |
|
384 |
(MeasurementValue value:20 minValue:1 maxValue:100) errorHigh |
|
385 |
(MeasurementValue value:20 minValue:1 maxValue:100) error |
|
386 |
" |
|
387 |
! |
|
388 |
||
389 |
errorLow |
|
390 |
"the relative error on the min side" |
|
391 |
||
392 |
^ (value - minValue) abs / value |
|
393 |
||
394 |
" |
|
395 |
(MeasurementValue value:10 error:0.2) errorLow |
|
396 |
(MeasurementValue value:10 error:0.2) errorHigh |
|
397 |
(MeasurementValue value:10 error:0.2) error |
|
398 |
(MeasurementValue value:20 error:0.2) errorLow |
|
399 |
(MeasurementValue value:20 minValue:1 maxValue:100) errorLow |
|
400 |
(MeasurementValue value:20 minValue:1 maxValue:100) errorHigh |
|
401 |
(MeasurementValue value:20 minValue:1 maxValue:100) error |
|
402 |
" |
|
403 |
! ! |
|
404 |
||
10825 | 405 |
!MeasurementValue methodsFor:'testing'! |
406 |
||
407 |
between:min and:max |
|
408 |
minValue < min ifTrue:[^ false]. |
|
409 |
maxValue > max ifTrue:[^ false]. |
|
410 |
^ true |
|
411 |
! ! |
|
412 |
||
413 |
!MeasurementValue class methodsFor:'documentation'! |
|
414 |
||
415 |
version |
|
18832 | 416 |
^ '$Header$' |
10825 | 417 |
! ! |
16274 | 418 |