|
|
Class: MeasurementValue
Object
|
+--Magnitude
|
+--ArithmeticValue
|
+--Number
|
+--MeasurementValue
- Package:
- stx:libbasic
- Category:
- Magnitude-Numbers
- Version:
- rev:
1.10
date: 2009/05/26 06:37:29
- user: cg
- file: MeasurementValue.st directory: libbasic
- module: stx stc-classLibrary: libbasic
- Author:
- Claus Gittinger
A MeasurementValue is a numeric value with an error, such as returned
by measurement devices (Volt-Meter). For example, if a measurement-device has
an error of 10%, a measured value of 20 could be any value between 18 and 22.
Arithmetic operations keep track of the error; if any operand is a MeasurementValue,
the operation returns a MeasurementValue as result.
This class is possibly unfinished and needs more arithmetic methods.
For now, the stuff found here represents our needs and more might be added in the future.
Also notice, that instances do not keep the error as a fraction, but instead a min. and maxValue.
That means, that we can handle the case where the error is different in
the positive and negative directions.
I am not sure if this is more flexibility than needed in the long run.
Number
Float
ShortFloat
Fraction
FixedPoint
Integer
Complex
FloatArray
DoubleArray
constants
-
unity
-
return the neutral element for multiplication
-
zero
-
return the neutral element for addition (0 +/- 0)
instance creation
-
value: arg1 error: arg2
-
return a new measurementValue with a given value and an error (fraction)
-
value: arg1 minValue: arg2 maxValue: arg3
-
return a new measurementValue with a given value and an error given as min-max values.
Use this, if the error is not the same in both directions
accessing
-
maxValue
-
the maximum possible value, considerung what has been measured and what the measurement error is
-
minValue
-
the minimum possible value, considerung what has been measured and what the measurement error is
-
value
-
the measured value
arithmetic
-
* aNumber
-
return the product of the receiver and the argument.
Care for the error to propagate into the result.
-
+ aNumber
-
return the sum of the receiver and the argument.
Care for the error to propagate into the result.
-
- aNumber
-
return the difference of the receiver and the argument.
Care for the error to propagate into the result.
-
/ aNumber
-
return the quotient of the receiver and the argument.
Care for the error to propagate into the result.
coercing & converting
-
+/- error
-
return a MeasurementValue with the given error.
-
coerce: aNumber
-
convert the argument aNumber into an instance of the receivers class and return it.
-
generality
-
return the generality value - see ArithmeticValue>>retry:coercing:
comparing
-
< aNumber
-
return true, if the argument is greater than the receiver.
Care for the error - i.e. compare against my maximum-value
-
= aNumber
-
hard to tell, what we want here...
How about: aNumber between:minValue and:maxValue ???
-
lessFromFloat: aFloat
-
aFloat < self ?
-
lessFromInteger: anInteger
-
anInteger < self ?
printing & storing
-
printOn: aStream
-
private accessing
-
value: valueArg error: errorFraction
-
-
value: valueArg minValue: minValueArg maxValue: maxValueArg
-
testing
-
between: min and: max
-
Notice, how the errors accumulate...
|voltage current power|
voltage := MeasurementValue value:10 error:0.05.
current := MeasurementValue value:2 error:0.1.
power := voltage * current.
power.
power minValue.
power maxValue.
|
|voltage current power|
voltage := MeasurementValue value:10 error:0.05.
current := 2.
power := voltage * current.
power
|
|voltage doubleVoltage|
voltage := MeasurementValue value:10 error:0.1.
doubleVoltage := 2 * voltage.
doubleVoltage
|
|