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 |
|
|
14 |
Number subclass:#MeasurementValue
|
|
15 |
instanceVariableNames:'value minValue maxValue'
|
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Magnitude-Numbers'
|
|
19 |
!
|
|
20 |
|
|
21 |
!MeasurementValue class methodsFor:'documentation'!
|
|
22 |
|
|
23 |
copyright
|
|
24 |
"
|
|
25 |
COPYRIGHT (c) 2007 by eXept Software AG
|
|
26 |
All Rights Reserved
|
|
27 |
|
|
28 |
This software is furnished under a license and may be used
|
|
29 |
only in accordance with the terms of that license and with the
|
|
30 |
inclusion of the above copyright notice. This software may not
|
|
31 |
be provided or otherwise made available to, or used by, any
|
|
32 |
other person. No title to or ownership of the software is
|
|
33 |
hereby transferred.
|
|
34 |
"
|
|
35 |
!
|
|
36 |
|
|
37 |
documentation
|
|
38 |
"
|
|
39 |
A MeasurementValue is a numeric value with an error, such as returned
|
|
40 |
by measurement devices (Volt-Meter). For example, if a measurement-device has
|
|
41 |
an error of 10%, a measured value of 20 could be any value between 18 and 22.
|
|
42 |
|
|
43 |
Arithmetic operations keep track of the error; if any operand is a MeasurementValue,
|
|
44 |
the operation returns a MeasurementValue as result.
|
|
45 |
|
|
46 |
This class is possibly unfinished and needs more arithmetic methods.
|
|
47 |
For now, the stuff found here represents our needs and more might be added in the future.
|
|
48 |
|
|
49 |
[author:]
|
|
50 |
Claus Gittinger
|
|
51 |
|
|
52 |
[see also:]
|
|
53 |
Number
|
|
54 |
Float ShortFloat Fraction FixedPoint Integer Complex
|
|
55 |
FloatArray DoubleArray
|
|
56 |
"
|
|
57 |
!
|
|
58 |
|
|
59 |
examples
|
|
60 |
"
|
|
61 |
|voltage current power|
|
|
62 |
|
|
63 |
voltage := MeasurementValue value:10 error:0.05.
|
|
64 |
current := MeasurementValue value:2 error:0.1.
|
|
65 |
power := voltage * current.
|
|
66 |
power
|
|
67 |
"
|
|
68 |
! !
|
|
69 |
|
|
70 |
!MeasurementValue class methodsFor:'instance creation'!
|
|
71 |
|
|
72 |
value:arg1 error:arg2
|
|
73 |
"return a new measurementValue with a given value and an error (fraction)"
|
|
74 |
|
|
75 |
^ self new value:arg1 error:arg2
|
|
76 |
|
|
77 |
"
|
|
78 |
MeasurementValue value:10 error:0.2
|
|
79 |
"
|
|
80 |
!
|
|
81 |
|
|
82 |
value:arg1 minValue:arg2 maxValue:arg3
|
|
83 |
"return a new measurementValue with a given value and an error given as min-max values.
|
|
84 |
Use this, if the error is not the same in both directions"
|
|
85 |
|
|
86 |
^ self new value:arg1 minValue:arg2 maxValue:arg3
|
|
87 |
|
|
88 |
"a power of 10 error:
|
|
89 |
MeasurementValue value:5 minValue:1 maxValue:10
|
|
90 |
"
|
|
91 |
! !
|
|
92 |
|
|
93 |
!MeasurementValue methodsFor:'accessing'!
|
|
94 |
|
|
95 |
maxValue
|
|
96 |
^ maxValue
|
|
97 |
!
|
|
98 |
|
|
99 |
minValue
|
|
100 |
^ minValue
|
|
101 |
!
|
|
102 |
|
|
103 |
value
|
|
104 |
^ value
|
|
105 |
!
|
|
106 |
|
|
107 |
value:valueArg error:errorFraction
|
|
108 |
self
|
|
109 |
value:valueArg
|
|
110 |
minValue:(valueArg * (1-errorFraction))
|
|
111 |
maxValue:(valueArg * (1+errorFraction)).
|
|
112 |
!
|
|
113 |
|
|
114 |
value:valueArg minValue:minValueArg maxValue:maxValueArg
|
|
115 |
value := valueArg.
|
|
116 |
minValue := minValueArg.
|
|
117 |
maxValue := maxValueArg.
|
|
118 |
! !
|
|
119 |
|
|
120 |
!MeasurementValue methodsFor:'arithmetic'!
|
|
121 |
|
|
122 |
* aNumber
|
|
123 |
(aNumber isKindOf:MeasurementValue) ifTrue:[
|
|
124 |
^ MeasurementValue new
|
|
125 |
value:(value * aNumber value)
|
|
126 |
minValue:(minValue * aNumber minValue)
|
|
127 |
maxValue:(maxValue * aNumber maxValue)
|
|
128 |
].
|
|
129 |
|
|
130 |
^ MeasurementValue new
|
|
131 |
value:(value * aNumber)
|
|
132 |
minValue:(minValue * aNumber)
|
|
133 |
maxValue:(maxValue * aNumber)
|
|
134 |
!
|
|
135 |
|
|
136 |
+ aNumber
|
|
137 |
(aNumber isKindOf:MeasurementValue) ifTrue:[
|
|
138 |
^ MeasurementValue new
|
|
139 |
value:(value + aNumber value)
|
|
140 |
minValue:(minValue + aNumber minValue)
|
|
141 |
maxValue:(maxValue + aNumber maxValue)
|
|
142 |
].
|
|
143 |
|
|
144 |
^ MeasurementValue new
|
|
145 |
value:(value + aNumber)
|
|
146 |
minValue:(minValue + aNumber)
|
|
147 |
maxValue:(maxValue + aNumber)
|
|
148 |
!
|
|
149 |
|
|
150 |
- aNumber
|
|
151 |
(aNumber isKindOf:MeasurementValue) ifTrue:[
|
|
152 |
^ MeasurementValue new
|
|
153 |
value:(value - aNumber value)
|
|
154 |
minValue:(minValue - aNumber maxValue)
|
|
155 |
maxValue:(maxValue - aNumber minValue)
|
|
156 |
].
|
|
157 |
|
|
158 |
^ MeasurementValue new
|
|
159 |
value:(value - aNumber)
|
|
160 |
minValue:(minValue - aNumber)
|
|
161 |
maxValue:(maxValue - aNumber)
|
|
162 |
!
|
|
163 |
|
|
164 |
/ aNumber
|
|
165 |
(aNumber isKindOf:MeasurementValue) ifTrue:[
|
|
166 |
^ MeasurementValue new
|
|
167 |
value:(value / aNumber value)
|
|
168 |
minValue:(minValue / aNumber maxValue)
|
|
169 |
maxValue:(maxValue / aNumber minValue)
|
|
170 |
].
|
|
171 |
|
|
172 |
^ MeasurementValue new
|
|
173 |
value:(value / aNumber)
|
|
174 |
minValue:(minValue / aNumber)
|
|
175 |
maxValue:(maxValue / aNumber)
|
|
176 |
! !
|
|
177 |
|
|
178 |
!MeasurementValue methodsFor:'comparing'!
|
|
179 |
|
|
180 |
< aNumber
|
|
181 |
^ maxValue < aNumber
|
|
182 |
!
|
|
183 |
|
|
184 |
lessFromFloat:aFloat
|
|
185 |
"aFloat < self ?"
|
|
186 |
|
|
187 |
^ aFloat < minValue
|
|
188 |
!
|
|
189 |
|
|
190 |
lessFromInteger:anInteger
|
|
191 |
"anInteger < self ?"
|
|
192 |
|
|
193 |
^ anInteger < minValue
|
|
194 |
! !
|
|
195 |
|
|
196 |
!MeasurementValue methodsFor:'printing & storing'!
|
|
197 |
|
|
198 |
printOn:aStream
|
|
199 |
value printOn:aStream.
|
|
200 |
'(' printOn:aStream.
|
|
201 |
minValue printOn:aStream.
|
|
202 |
'..' printOn:aStream.
|
|
203 |
maxValue printOn:aStream.
|
|
204 |
')' printOn:aStream.
|
|
205 |
! !
|
|
206 |
|
|
207 |
!MeasurementValue methodsFor:'testing'!
|
|
208 |
|
|
209 |
between:min and:max
|
|
210 |
minValue < min ifTrue:[^ false].
|
|
211 |
maxValue > max ifTrue:[^ false].
|
|
212 |
^ true
|
|
213 |
! !
|
|
214 |
|
|
215 |
!MeasurementValue class methodsFor:'documentation'!
|
|
216 |
|
|
217 |
version
|
|
218 |
^ '$Header: /cvs/stx/stx/libbasic/MeasurementValue.st,v 1.1 2008-01-07 13:42:05 cg Exp $'
|
|
219 |
! !
|