MeasurementValue.st
author Stefan Vogel <sv@exept.de>
Tue, 28 Apr 2020 16:21:34 +0200
changeset 25373 f030619565e1
parent 25254 41d6e0766006
permissions -rw-r--r--
#REFACTORING by stefan class: ArrayedCollection class changed: #with:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25254
41d6e0766006 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25014
diff changeset
     1
"{ Encoding: utf8 }"
41d6e0766006 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25014
diff changeset
     2
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
"
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
 COPYRIGHT (c) 2007 by eXept Software AG
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
              All Rights Reserved
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 This software is furnished under a license and may be used
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
 hereby transferred.
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
"
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
"{ Package: 'stx:libbasic' }"
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
18832
885cfb29ed7c #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 16274
diff changeset
    16
"{ NameSpace: Smalltalk }"
885cfb29ed7c #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 16274
diff changeset
    17
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
Number subclass:#MeasurementValue
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	instanceVariableNames:'value minValue maxValue'
11465
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
    20
	classVariableNames:'MeasurementValueZero'
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	poolDictionaries:''
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	category:'Magnitude-Numbers'
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
!MeasurementValue class methodsFor:'documentation'!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
copyright
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
"
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
 COPYRIGHT (c) 2007 by eXept Software AG
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
              All Rights Reserved
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 This software is furnished under a license and may be used
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 only in accordance with the terms of that license and with the
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 be provided or otherwise made available to, or used by, any
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
 other person.  No title to or ownership of the software is
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
 hereby transferred.
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
"
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
documentation
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
"
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
    A MeasurementValue is a numeric value with an error, such as returned
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
    by measurement devices (Volt-Meter). For example, if a measurement-device has
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
    an error of 10%, a measured value of 20 could be any value between 18 and 22.
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
    Arithmetic operations keep track of the error; if any operand is a MeasurementValue,
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
    the operation returns a MeasurementValue as result.
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
    This class is possibly unfinished and needs more arithmetic methods.
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
    For now, the stuff found here represents our needs and more might be added in the future.
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
11456
3ab3ea28c8f4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10825
diff changeset
    53
    Also notice, that instances do not keep the error as a fraction, but instead a min. and maxValue.
11606
f657ce220093 comment
Claus Gittinger <cg@exept.de>
parents: 11466
diff changeset
    54
    That means, that we can handle the case where the error is different in
11456
3ab3ea28c8f4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10825
diff changeset
    55
    the positive and negative directions.
11607
39bd3dc180df comment
Claus Gittinger <cg@exept.de>
parents: 11606
diff changeset
    56
    I am not sure if this is more flexibility than needed in the long run.
11456
3ab3ea28c8f4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10825
diff changeset
    57
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
    [author:]
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
        Claus Gittinger
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
    [see also:]
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
        Number
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
        Float ShortFloat Fraction FixedPoint Integer Complex
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
        FloatArray DoubleArray
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
"
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
examples
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
"
21929
1b3b40b8b16c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18832
diff changeset
    70
  Instance creation message in number:
1b3b40b8b16c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18832
diff changeset
    71
                                                                        [exBegin]
1b3b40b8b16c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18832
diff changeset
    72
    (10 +/- 1)
1b3b40b8b16c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18832
diff changeset
    73
                                                                        [exEnd]
1b3b40b8b16c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18832
diff changeset
    74
1b3b40b8b16c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18832
diff changeset
    75
  arithmetic; notice, how the errors accumulate:
1b3b40b8b16c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18832
diff changeset
    76
                                                                        [exBegin]
1b3b40b8b16c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18832
diff changeset
    77
     (100 +/- 5) * 2
1b3b40b8b16c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18832
diff changeset
    78
     (100 +/- 5) * (100 +/- 10)
1b3b40b8b16c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18832
diff changeset
    79
     (100 +/- 5) + (100 +/- 10)
1b3b40b8b16c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18832
diff changeset
    80
     (100 +/- 5) - (100 +/- 10)
1b3b40b8b16c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18832
diff changeset
    81
                                                                        [exEnd]
1b3b40b8b16c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18832
diff changeset
    82
1b3b40b8b16c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18832
diff changeset
    83
  again see, how the errors accumulate...
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    84
                                                                        [exBegin]
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
    |voltage current power|
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
    voltage := MeasurementValue value:10 error:0.05.
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
    current := MeasurementValue value:2 error:0.1.
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
    power := voltage * current.
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    90
    power.                   
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    91
    power minValue.
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    92
    power maxValue.
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    93
                                                                        [exEnd]
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    94
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    95
                                                                        [exBegin]
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    96
    |voltage current power|
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    97
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    98
    voltage := MeasurementValue value:10 error:0.05.
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    99
    current := 2.
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   100
    power := voltage * current.
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
    power
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   102
                                                                        [exEnd]
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   103
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   104
                                                                        [exBegin]
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   105
    |voltage doubleVoltage|
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   106
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   107
    voltage := MeasurementValue value:10 error:0.1.
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   108
    doubleVoltage := 2 * voltage.
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   109
    doubleVoltage
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   110
                                                                        [exEnd]
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
"
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
! !
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
!MeasurementValue class methodsFor:'instance creation'!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
25254
41d6e0766006 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25014
diff changeset
   116
value:valueArg absoluteError:errorArg
41d6e0766006 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25014
diff changeset
   117
    "return a new measurementValue with a given value and an error (fraction)"
41d6e0766006 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25014
diff changeset
   118
41d6e0766006 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25014
diff changeset
   119
    ^ self new value:valueArg minValue:(valueArg - errorArg) maxValue:(valueArg + errorArg)
41d6e0766006 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25014
diff changeset
   120
41d6e0766006 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25014
diff changeset
   121
    "
41d6e0766006 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25014
diff changeset
   122
     10 with an error of 20%:
41d6e0766006 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25014
diff changeset
   123
        MeasurementValue value:10 error:0.2 
41d6e0766006 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25014
diff changeset
   124
     pi within 1%:
41d6e0766006 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25014
diff changeset
   125
        MeasurementValue value:(Float pi) error:1e-1 
41d6e0766006 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25014
diff changeset
   126
     pi within +/- 1e-3:
41d6e0766006 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25014
diff changeset
   127
        MeasurementValue value:(Float pi) absoluteError:1e-3 
41d6e0766006 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25014
diff changeset
   128
    "
41d6e0766006 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25014
diff changeset
   129
!
41d6e0766006 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25014
diff changeset
   130
14445
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   131
value:valueArg error:errorArg
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
    "return a new measurementValue with a given value and an error (fraction)"
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
14445
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   134
    ^ self new value:valueArg error:errorArg
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
25254
41d6e0766006 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25014
diff changeset
   136
    "
41d6e0766006 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25014
diff changeset
   137
     10 with an error of 20%:
41d6e0766006 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25014
diff changeset
   138
        MeasurementValue value:10 error:0.2 
41d6e0766006 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25014
diff changeset
   139
     pi within 1%:
41d6e0766006 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25014
diff changeset
   140
        MeasurementValue value:(Float pi) error:1e-1 
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
    "
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
14445
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   144
value:valueArg minValue:minArg maxValue:maxArg
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
    "return a new measurementValue with a given value and an error given as min-max values.
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
     Use this, if the error is not the same in both directions"
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
14445
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   148
    ^ self new value:valueArg minValue:minArg maxValue:maxArg
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
14445
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   150
    "an order of magnitude error:
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   151
21929
1b3b40b8b16c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18832
diff changeset
   152
     MeasurementValue value:5 minValue:1 maxValue:10 
1b3b40b8b16c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18832
diff changeset
   153
1b3b40b8b16c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18832
diff changeset
   154
     10 percent:
1b3b40b8b16c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18832
diff changeset
   155
     
1b3b40b8b16c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18832
diff changeset
   156
     MeasurementValue value:10 minValue:9 maxValue:11   
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
    "
21929
1b3b40b8b16c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18832
diff changeset
   158
1b3b40b8b16c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 18832
diff changeset
   159
    "Modified (comment): / 01-07-2017 / 19:28:32 / cg"
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
! !
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
25014
a75b53bdb6c3 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 21929
diff changeset
   162
!MeasurementValue class methodsFor:'coercing & converting'!
a75b53bdb6c3 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 21929
diff changeset
   163
a75b53bdb6c3 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 21929
diff changeset
   164
coerce:aNumber
a75b53bdb6c3 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 21929
diff changeset
   165
    "convert the argument aNumber into an instance of the receiver's class and return it."
a75b53bdb6c3 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 21929
diff changeset
   166
a75b53bdb6c3 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 21929
diff changeset
   167
    ^ MeasurementValue value:aNumber minValue:aNumber maxValue:aNumber
a75b53bdb6c3 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 21929
diff changeset
   168
! !
a75b53bdb6c3 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 21929
diff changeset
   169
11465
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   170
!MeasurementValue class methodsFor:'constants'!
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   171
11466
3b67c6756dad *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11465
diff changeset
   172
unity
3b67c6756dad *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11465
diff changeset
   173
    "return the neutral element for multiplication"
3b67c6756dad *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11465
diff changeset
   174
3b67c6756dad *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11465
diff changeset
   175
    ^ 1
3b67c6756dad *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11465
diff changeset
   176
3b67c6756dad *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11465
diff changeset
   177
    "
3b67c6756dad *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11465
diff changeset
   178
     self unity
3b67c6756dad *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11465
diff changeset
   179
    "
3b67c6756dad *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11465
diff changeset
   180
!
3b67c6756dad *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11465
diff changeset
   181
11465
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   182
zero
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   183
    "return the neutral element for addition (0 +/- 0)"
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   184
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   185
    MeasurementValueZero isNil ifTrue:[
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   186
        MeasurementValueZero := self value:0 minValue:0 maxValue:0
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   187
    ].
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   188
    ^ MeasurementValueZero
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   189
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   190
    "
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   191
     self zero
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   192
    "
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   193
! !
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   194
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
!MeasurementValue methodsFor:'accessing'!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
maxValue
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   198
    "the maximum possible value, considerung what has been measured and what the measurement error is"
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   199
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
    ^ maxValue
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
minValue
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   204
    "the minimum possible value, considerung what has been measured and what the measurement error is"
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   205
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
    ^ minValue
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
value
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   210
    "the measured value"
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   212
    ^ value
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
! !
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
!MeasurementValue methodsFor:'arithmetic'!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
* aNumber
11726
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   218
    "return the product of the receiver and the argument.
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   219
     Care for the error to propagate into the result."
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   220
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
    ^ MeasurementValue new
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   222
        value:(value * aNumber value)
14445
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   223
        minValue:((minValue * aNumber minValue) min:(maxValue * aNumber minValue))
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   224
        maxValue:((maxValue * aNumber maxValue) max:(minValue * aNumber maxValue))
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   225
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   226
    "
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   227
     (MeasurementValue value:-10 error:0.2) * (MeasurementValue value:-10 error:0.2) 
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   228
     (MeasurementValue value:-10 error:0.2) * 2 
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   229
    "
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
+ aNumber
11726
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   233
    "return the sum of the receiver and the argument.
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   234
     Care for the error to propagate into the result."
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   235
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
    ^ MeasurementValue new
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   237
        value:(value + aNumber value)
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   238
        minValue:(minValue + aNumber minValue)
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   239
        maxValue:(maxValue + aNumber maxValue)
14445
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   240
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   241
    "
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   242
     (MeasurementValue value:-10 error:0.2) + (MeasurementValue value:-10 error:0.2) 
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   243
     (MeasurementValue value:-10 error:0.2) + 2  
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   244
    "
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
- aNumber
11726
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   248
    "return the difference of the receiver and the argument.
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   249
     Care for the error to propagate into the result."
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   250
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
    ^ MeasurementValue new
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   252
        value:(value - aNumber value)
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   253
        minValue:(minValue - aNumber maxValue)
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   254
        maxValue:(maxValue - aNumber minValue)
14445
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   255
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   256
    "
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   257
     (MeasurementValue value:-10 error:0.2) - (MeasurementValue value:-10 error:0.2) 
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   258
     (MeasurementValue value:-10 error:0.2) - 10                                     
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   259
     (MeasurementValue value:10 error:0.2) - 10                                     
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   260
    "
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
/ aNumber
11726
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   264
    "return the quotient of the receiver and the argument.
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   265
     Care for the error to propagate into the result."
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   266
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   267
    ^ MeasurementValue new
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   268
        value:(value / aNumber value)
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   269
        minValue:(minValue / aNumber maxValue)
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   270
        maxValue:(maxValue / aNumber minValue)
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   271
! !
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   272
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   273
!MeasurementValue methodsFor:'coercing & converting'!
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   274
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   275
+/- error
14008
581547d06ef3 comment
Claus Gittinger <cg@exept.de>
parents: 11726
diff changeset
   276
    "return a MeasurementValue with a given error."
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   277
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   278
    "/ what should I do here - take the new error,
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   279
    "/ or multiply them ????
25254
41d6e0766006 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 25014
diff changeset
   280
    self error:'to be implemented'.
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   281
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   282
    minValue := value - error.
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   283
    maxValue := value + error.
14008
581547d06ef3 comment
Claus Gittinger <cg@exept.de>
parents: 11726
diff changeset
   284
581547d06ef3 comment
Claus Gittinger <cg@exept.de>
parents: 11726
diff changeset
   285
    "Modified (comment): / 14-02-2012 / 14:17:39 / cg"
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   286
!
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   287
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   288
coerce:aNumber
18832
885cfb29ed7c #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 16274
diff changeset
   289
    "convert the argument aNumber into an instance of the receiver's class and return it."
11717
62d715950754 comment
Claus Gittinger <cg@exept.de>
parents: 11607
diff changeset
   290
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   291
    ^ MeasurementValue value:aNumber minValue:aNumber maxValue:aNumber
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   292
!
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   293
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   294
generality
11717
62d715950754 comment
Claus Gittinger <cg@exept.de>
parents: 11607
diff changeset
   295
    "return the generality value - see ArithmeticValue>>retry:coercing:"
62d715950754 comment
Claus Gittinger <cg@exept.de>
parents: 11607
diff changeset
   296
18832
885cfb29ed7c #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 16274
diff changeset
   297
    "/ adding 1 to the value's generality has the subtle side effect of enforcing 
11717
62d715950754 comment
Claus Gittinger <cg@exept.de>
parents: 11607
diff changeset
   298
    "/ a call to coerce: for mixed type operations (i.e. Int * MeasurementValue).
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   299
    "/ try it.
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   300
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   301
    ^ value generality + 1 
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   302
! !
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   303
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   304
!MeasurementValue methodsFor:'comparing'!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   305
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   306
< aNumber
11726
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   307
    "return true, if the argument is greater than the receiver.
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   308
     Care for the error - i.e. compare against my maximum-value"
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   309
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   310
    ^ maxValue < aNumber
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   311
!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   312
11465
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   313
= aNumber
11726
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   314
    "hard to tell, what we want here...
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   315
     How about: aNumber between:minValue and:maxValue ???"
11465
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   316
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   317
    ^ value = aNumber value
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   318
    and:[ minValue = aNumber minValue
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   319
    and:[ maxValue = aNumber maxValue ]]
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   320
!
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   321
16274
598ee861547a class: MeasurementValue
Stefan Vogel <sv@exept.de>
parents: 14445
diff changeset
   322
hash
598ee861547a class: MeasurementValue
Stefan Vogel <sv@exept.de>
parents: 14445
diff changeset
   323
    ^ value hash
598ee861547a class: MeasurementValue
Stefan Vogel <sv@exept.de>
parents: 14445
diff changeset
   324
!
598ee861547a class: MeasurementValue
Stefan Vogel <sv@exept.de>
parents: 14445
diff changeset
   325
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   326
lessFromFloat:aFloat
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   327
    "aFloat < self ?"
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   328
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   329
    ^ aFloat < minValue
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   330
!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   331
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   332
lessFromInteger:anInteger
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
    "anInteger < self ?"
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   334
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   335
    ^ anInteger < minValue
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   336
! !
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   337
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   338
!MeasurementValue methodsFor:'printing & storing'!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   339
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   340
printOn:aStream
11459
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   341
    aStream nextPutAll:'('.
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   342
    (maxValue-value) = (value-minValue) ifTrue:[
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   343
        value storeOn:aStream.
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   344
        aStream nextPutAll:' +/- '.
14445
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   345
        (maxValue-value) abs storeOn:aStream
11459
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   346
    ] ifFalse:[
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   347
        aStream nextPutAll:'MeasurementValue value:'.
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   348
        value storeOn:aStream.
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   349
        aStream nextPutAll:' minValue:'.
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   350
        minValue storeOn:aStream.
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   351
        aStream nextPutAll:' maxValue:'.
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   352
        maxValue storeOn:aStream.
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   353
    ].
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   354
    ')' printOn:aStream.
11459
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   355
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   356
    "
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   357
     (5 +/- 1) storeString 
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   358
     (MeasurementValue value:5 minValue:3 maxValue:8) storeString 
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   359
    "
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   360
! !
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   361
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   362
!MeasurementValue methodsFor:'private accessing'!
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   363
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   364
value:valueArg error:errorFraction 
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   365
    self 
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   366
        value:valueArg
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   367
        minValue:(valueArg * (1-errorFraction))
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   368
        maxValue:(valueArg * (1+errorFraction)). 
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   369
!
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   370
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   371
value:valueArg minValue:minValueArg maxValue:maxValueArg 
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   372
    value := valueArg.
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   373
    minValue := minValueArg.
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   374
    maxValue := maxValueArg.
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   375
! !
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   376
14445
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   377
!MeasurementValue methodsFor:'queries'!
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   378
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   379
error
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   380
    "the relative error.
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   381
     If the error is different in the min/max direction, the larger error is returned here"
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   382
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   383
    ^ self errorHigh max:(self errorLow)
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   384
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   385
    "
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   386
     (MeasurementValue value:10 error:0.2) errorLow 
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   387
     (MeasurementValue value:10 error:0.2) errorHigh 
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   388
     (MeasurementValue value:10 error:0.2) error 
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   389
    "
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   390
!
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   391
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   392
errorHigh
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   393
    "the relative error on the max side"
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   394
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   395
    ^ (value - maxValue) abs / value
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   396
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   397
    "
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   398
     (MeasurementValue value:10 error:0.2) errorLow  
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   399
     (MeasurementValue value:10 error:0.2) errorHigh 
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   400
     (MeasurementValue value:10 error:0.2) error     
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   401
     (MeasurementValue value:20 error:0.2) errorLow   
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   402
     (MeasurementValue value:20 minValue:1 maxValue:100) errorLow   
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   403
     (MeasurementValue value:20 minValue:1 maxValue:100) errorHigh  
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   404
     (MeasurementValue value:20 minValue:1 maxValue:100) error  
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   405
    "
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   406
!
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   407
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   408
errorLow
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   409
    "the relative error on the min side"
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   410
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   411
    ^ (value - minValue) abs / value
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   412
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   413
    "
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   414
     (MeasurementValue value:10 error:0.2) errorLow  
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   415
     (MeasurementValue value:10 error:0.2) errorHigh 
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   416
     (MeasurementValue value:10 error:0.2) error     
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   417
     (MeasurementValue value:20 error:0.2) errorLow   
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   418
     (MeasurementValue value:20 minValue:1 maxValue:100) errorLow   
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   419
     (MeasurementValue value:20 minValue:1 maxValue:100) errorHigh  
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   420
     (MeasurementValue value:20 minValue:1 maxValue:100) error  
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   421
    "
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   422
! !
Claus Gittinger <cg@exept.de>
parents: 14008
diff changeset
   423
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   424
!MeasurementValue methodsFor:'testing'!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   425
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   426
between:min and:max
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   427
    minValue < min ifTrue:[^ false].
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   428
    maxValue > max ifTrue:[^ false].
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   429
    ^ true
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   430
! !
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   431
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   432
!MeasurementValue class methodsFor:'documentation'!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   433
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   434
version
18832
885cfb29ed7c #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 16274
diff changeset
   435
    ^ '$Header$'
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   436
! !
16274
598ee861547a class: MeasurementValue
Stefan Vogel <sv@exept.de>
parents: 14445
diff changeset
   437