eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'MeasurementValue':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: MeasurementValue


Inheritance:

   Object
   |
   +--Magnitude
      |
      +--ArithmeticValue
         |
         +--Number
            |
            +--MeasurementValue

Package:
stx:libbasic
Category:
Magnitude-Numbers
Version:
rev: 1.15 date: 2017/07/01 17:33:33
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
usage example(s):
     self unity

o  zero
return the neutral element for addition (0 +/- 0)
usage example(s):
     self zero

instance creation
o  value: valueArg error: errorArg
return a new measurementValue with a given value and an error (fraction)
usage example(s):
10 with an error of 20%:

     MeasurementValue value:10 error:0.2 

o  value: valueArg minValue: minArg maxValue: maxArg
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
usage example(s):
an order of magnitude error:

     MeasurementValue value:5 minValue:1 maxValue:10 

     10 percent:
     
     MeasurementValue value:10 minValue:9 maxValue:11   


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.
usage example(s):
     (MeasurementValue value:-10 error:0.2) * (MeasurementValue value:-10 error:0.2) 
     (MeasurementValue value:-10 error:0.2) * 2 

o  + aNumber
return the sum of the receiver and the argument.
Care for the error to propagate into the result.
usage example(s):
     (MeasurementValue value:-10 error:0.2) + (MeasurementValue value:-10 error:0.2) 
     (MeasurementValue value:-10 error:0.2) + 2  

o  - aNumber
return the difference of the receiver and the argument.
Care for the error to propagate into the result.
usage example(s):
     (MeasurementValue value:-10 error:0.2) - (MeasurementValue value:-10 error:0.2) 
     (MeasurementValue value:-10 error:0.2) - 10                                     
     (MeasurementValue value:10 error:0.2) - 10                                     

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 a given error.

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

o  generality
return the generality value - see ArithmeticValue>>retry:coercing:
usage example(s):
adding 1 to the value's generality has the subtle side effect of enforcing 

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  hash

o  lessFromFloat: aFloat
aFloat < self ?

o  lessFromInteger: anInteger
anInteger < self ?

printing & storing
o  printOn: aStream
(5 +/- 1) storeString
(MeasurementValue value:5 minValue:3 maxValue:8) storeString

private accessing
o  value: valueArg error: errorFraction

o  value: valueArg minValue: minValueArg maxValue: maxValueArg

queries
o  error
the relative error.
If the error is different in the min/max direction, the larger error is returned here
usage example(s):
     (MeasurementValue value:10 error:0.2) errorLow 
     (MeasurementValue value:10 error:0.2) errorHigh 
     (MeasurementValue value:10 error:0.2) error 

o  errorHigh
the relative error on the max side
usage example(s):
     (MeasurementValue value:10 error:0.2) errorLow  
     (MeasurementValue value:10 error:0.2) errorHigh 
     (MeasurementValue value:10 error:0.2) error     
     (MeasurementValue value:20 error:0.2) errorLow   
     (MeasurementValue value:20 minValue:1 maxValue:100) errorLow   
     (MeasurementValue value:20 minValue:1 maxValue:100) errorHigh  
     (MeasurementValue value:20 minValue:1 maxValue:100) error  

o  errorLow
the relative error on the min side
usage example(s):
     (MeasurementValue value:10 error:0.2) errorLow  
     (MeasurementValue value:10 error:0.2) errorHigh 
     (MeasurementValue value:10 error:0.2) error     
     (MeasurementValue value:20 error:0.2) errorLow   
     (MeasurementValue value:20 minValue:1 maxValue:100) errorLow   
     (MeasurementValue value:20 minValue:1 maxValue:100) errorHigh  
     (MeasurementValue value:20 minValue:1 maxValue:100) error  

testing
o  between: min and: max


Examples:


Instance creation message in number:
  (10 +/- 1)
arithmetic; notice, how the errors accumulate:
   (100 +/- 5) * 2
   (100 +/- 5) * (100 +/- 10)
   (100 +/- 5) + (100 +/- 10)
   (100 +/- 5) - (100 +/- 10)
again see, 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 7.1.0.0; WebServer 1.663 at exept.de:8081; Mon, 19 Nov 2018 09:37:30 GMT