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