 ## Smalltalk/X Webserver

#### Documentation of class 'MeasurementValue':

Documentation
www.exept.de
Everywhere
for: # 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 unity
return the neutral element for multiplication

usage example(s):

 `````` self unity `````` zero
return the neutral element for addition (0 +/- 0)

usage example(s):

 `````` self zero ``````

instance creation 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 `````` 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 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.

usage example(s):

 `````` (MeasurementValue value:-10 error:0.2) * (MeasurementValue value:-10 error:0.2) (MeasurementValue value:-10 error:0.2) * 2 `````` + 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 `````` - 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 `````` / 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 a given error. coerce: aNumber
convert the argument aNumber into an instance of the receiver's class and return it. 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 < 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 ??? hash lessFromFloat: aFloat
aFloat < self ? lessFromInteger: anInteger
anInteger < self ?

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

private accessing value: valueArg error: errorFraction value: valueArg minValue: minValueArg maxValue: maxValueArg

queries 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 `````` 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 `````` 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 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.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Tue, 17 May 2022 20:39:02 GMT