eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'MeasurementValue':

Home

everywhere
www.exept.de
for:
[back]

Class: MeasurementValue


Inheritance:

   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

Description:


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.


Related information:

    Number
    Float
    ShortFloat
    Fraction
    FixedPoint
    Integer
    Complex
    FloatArray
    DoubleArray

Class protocol:

constants
o  unity
return the neutral element for multiplication

o  zero
return the neutral element for addition (0 +/- 0)

instance creation
o  value: arg1 error: arg2
return a new measurementValue with a given value and an error (fraction)

o  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


Instance protocol:

accessing
o  maxValue
the maximum possible value, considerung what has been measured and what the measurement error is

o  minValue
the minimum possible value, considerung what has been measured and what the measurement error is

o  value
the measured value

arithmetic
o  * aNumber
return the product of the receiver and the argument.
Care for the error to propagate into the result.

o  + aNumber
return the sum of the receiver and the argument.
Care for the error to propagate into the result.

o  - aNumber
return the difference of the receiver and the argument.
Care for the error to propagate into the result.

o  / aNumber
return the quotient of the receiver and the argument.
Care for the error to propagate into the result.

coercing & converting
o  +/- error
return a MeasurementValue with the given error.

o  coerce: aNumber
convert the argument aNumber into an instance of the receivers class and return it.

o  generality
return the generality value - see ArithmeticValue>>retry:coercing:

comparing
o  < aNumber
return true, if the argument is greater than the receiver.
Care for the error - i.e. compare against my maximum-value

o  = aNumber
hard to tell, what we want here...
How about: aNumber between:minValue and:maxValue ???

o  lessFromFloat: aFloat
aFloat < self ?

o  lessFromInteger: anInteger
anInteger < self ?

printing & storing
o  printOn: aStream

private accessing
o  value: valueArg error: errorFraction

o  value: valueArg minValue: minValueArg maxValue: maxValueArg

testing
o  between: min and: max


Examples:


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


ST/X 6.1.1; WebServer 1.620 at exept:8081; Wed, 23 May 2012 20:01:37 GMT