MeasurementValue.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 29 Sep 2011 16:44:37 +0100
branchjv
changeset 17869 9610c6c94e71
parent 17865 598963c6ff8e
child 17892 d86c8bd5ece3
permissions -rw-r--r--
(none)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 2007 by eXept Software AG
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
"{ Package: 'stx:libbasic' }"
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
Number subclass:#MeasurementValue
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
	instanceVariableNames:'value minValue maxValue'
11465
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
    16
	classVariableNames:'MeasurementValueZero'
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	poolDictionaries:''
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	category:'Magnitude-Numbers'
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!MeasurementValue class methodsFor:'documentation'!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
copyright
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
"
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
 COPYRIGHT (c) 2007 by eXept Software AG
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
              All Rights Reserved
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
 This software is furnished under a license and may be used
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
 only in accordance with the terms of that license and with the
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 be provided or otherwise made available to, or used by, any
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 other person.  No title to or ownership of the software is
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 hereby transferred.
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
"
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
documentation
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
"
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
    A MeasurementValue is a numeric value with an error, such as returned
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
    by measurement devices (Volt-Meter). For example, if a measurement-device has
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
    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
    42
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
    Arithmetic operations keep track of the error; if any operand is a MeasurementValue,
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
    the operation returns a MeasurementValue as result.
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
    This class is possibly unfinished and needs more arithmetic methods.
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
    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
    48
11456
3ab3ea28c8f4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10825
diff changeset
    49
    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
    50
    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
    51
    the positive and negative directions.
11607
39bd3dc180df comment
Claus Gittinger <cg@exept.de>
parents: 11606
diff changeset
    52
    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
    53
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
    [author:]
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
        Claus Gittinger
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
    [see also:]
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
        Number
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
        Float ShortFloat Fraction FixedPoint Integer Complex
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
        FloatArray DoubleArray
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
"
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
examples
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
"
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    66
    Notice, how the errors accumulate...
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    67
                                                                        [exBegin]
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
    |voltage current power|
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
    voltage := MeasurementValue value:10 error:0.05.
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
    current := MeasurementValue value:2 error:0.1.
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
    power := voltage * current.
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    73
    power.                   
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    74
    power minValue.
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    75
    power maxValue.
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    76
                                                                        [exEnd]
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    77
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    78
                                                                        [exBegin]
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    79
    |voltage current power|
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    80
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    81
    voltage := MeasurementValue value:10 error:0.05.
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    82
    current := 2.
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    83
    power := voltage * current.
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
    power
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    85
                                                                        [exEnd]
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    86
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    87
                                                                        [exBegin]
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    88
    |voltage doubleVoltage|
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    89
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    90
    voltage := MeasurementValue value:10 error:0.1.
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    91
    doubleVoltage := 2 * voltage.
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    92
    doubleVoltage
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
    93
                                                                        [exEnd]
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
"
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
! !
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
!MeasurementValue class methodsFor:'instance creation'!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
value:arg1 error:arg2
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
    "return a new measurementValue with a given value and an error (fraction)"
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
    ^ self new value:arg1 error:arg2
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
    "
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
     MeasurementValue value:10 error:0.2 
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
    "
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
value:arg1 minValue:arg2 maxValue:arg3
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
    "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
   111
     Use this, if the error is not the same in both directions"
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
    ^ self new value:arg1 minValue:arg2 maxValue:arg3
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
    "a power of 10 error:
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
     MeasurementValue value:5 minValue:1 maxValue:10   
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
    "
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
! !
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
11465
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   120
!MeasurementValue class methodsFor:'constants'!
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   121
11466
3b67c6756dad *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11465
diff changeset
   122
unity
3b67c6756dad *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11465
diff changeset
   123
    "return the neutral element for multiplication"
3b67c6756dad *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11465
diff changeset
   124
3b67c6756dad *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11465
diff changeset
   125
    ^ 1
3b67c6756dad *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11465
diff changeset
   126
3b67c6756dad *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11465
diff changeset
   127
    "
3b67c6756dad *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11465
diff changeset
   128
     self unity
3b67c6756dad *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11465
diff changeset
   129
    "
3b67c6756dad *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11465
diff changeset
   130
!
3b67c6756dad *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 11465
diff changeset
   131
11465
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   132
zero
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   133
    "return the neutral element for addition (0 +/- 0)"
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   134
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   135
    MeasurementValueZero isNil ifTrue:[
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   136
        MeasurementValueZero := self value:0 minValue:0 maxValue:0
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   137
    ].
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   138
    ^ MeasurementValueZero
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   139
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   140
    "
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   141
     self zero
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   142
    "
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   143
! !
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   144
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
!MeasurementValue methodsFor:'accessing'!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
maxValue
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   148
    "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
   149
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
    ^ maxValue
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
minValue
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   154
    "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
   155
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
    ^ minValue
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
value
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   160
    "the measured value"
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   162
    ^ value
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
! !
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
!MeasurementValue methodsFor:'arithmetic'!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
* aNumber
11726
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   168
    "return the product of the receiver and the argument.
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   169
     Care for the error to propagate into the result."
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   170
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
    ^ MeasurementValue new
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   172
        value:(value * aNumber value)
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   173
        minValue:(minValue * aNumber minValue)
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   174
        maxValue:(maxValue * aNumber maxValue)
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
+ aNumber
11726
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   178
    "return the sum of the receiver and the argument.
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   179
     Care for the error to propagate into the result."
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   180
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
    ^ MeasurementValue new
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   182
        value:(value + aNumber value)
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   183
        minValue:(minValue + aNumber minValue)
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   184
        maxValue:(maxValue + aNumber maxValue)
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
- aNumber
11726
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   188
    "return the difference of the receiver and the argument.
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   189
     Care for the error to propagate into the result."
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   190
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
    ^ MeasurementValue new
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   192
        value:(value - aNumber value)
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   193
        minValue:(minValue - aNumber maxValue)
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   194
        maxValue:(maxValue - aNumber minValue)
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
/ aNumber
11726
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   198
    "return the quotient of the receiver and the argument.
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   199
     Care for the error to propagate into the result."
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   200
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   201
    ^ MeasurementValue new
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   202
        value:(value / aNumber value)
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   203
        minValue:(minValue / aNumber maxValue)
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   204
        maxValue:(maxValue / aNumber minValue)
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   205
! !
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   206
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   207
!MeasurementValue methodsFor:'coercing & converting'!
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   208
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   209
+/- error
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   210
    "return a MeasurementValue with the given error."
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   211
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   212
    "/ what should I do here - take the new error,
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   213
    "/ or multiply them ????
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   214
    self error.
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   216
    minValue := value - error.
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   217
    maxValue := value + error.
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   218
!
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   219
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   220
coerce:aNumber
11717
62d715950754 comment
Claus Gittinger <cg@exept.de>
parents: 11607
diff changeset
   221
    "convert the argument aNumber into an instance of the receivers class and return it."
62d715950754 comment
Claus Gittinger <cg@exept.de>
parents: 11607
diff changeset
   222
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   223
    ^ MeasurementValue value:aNumber minValue:aNumber maxValue:aNumber
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   224
!
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   225
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   226
generality
11717
62d715950754 comment
Claus Gittinger <cg@exept.de>
parents: 11607
diff changeset
   227
    "return the generality value - see ArithmeticValue>>retry:coercing:"
62d715950754 comment
Claus Gittinger <cg@exept.de>
parents: 11607
diff changeset
   228
62d715950754 comment
Claus Gittinger <cg@exept.de>
parents: 11607
diff changeset
   229
    "/ adding 1 to the values generality has the subtle side effect of enforcing 
62d715950754 comment
Claus Gittinger <cg@exept.de>
parents: 11607
diff changeset
   230
    "/ 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
   231
    "/ try it.
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   232
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   233
    ^ value generality + 1 
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
! !
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
!MeasurementValue methodsFor:'comparing'!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
< aNumber
11726
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   239
    "return true, if the argument is greater than the receiver.
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   240
     Care for the error - i.e. compare against my maximum-value"
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   241
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
    ^ maxValue < aNumber
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
11465
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   245
= aNumber
11726
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   246
    "hard to tell, what we want here...
074852a9f820 comment
Claus Gittinger <cg@exept.de>
parents: 11717
diff changeset
   247
     How about: aNumber between:minValue and:maxValue ???"
11465
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   248
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   249
    ^ value = aNumber value
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   250
    and:[ minValue = aNumber minValue
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   251
    and:[ maxValue = aNumber maxValue ]]
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   252
!
3f5fc7aace0f changed #'='
Claus Gittinger <cg@exept.de>
parents: 11459
diff changeset
   253
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
lessFromFloat:aFloat
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   255
    "aFloat < self ?"
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
    ^ aFloat < minValue
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
lessFromInteger:anInteger
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
    "anInteger < self ?"
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
    ^ anInteger < minValue
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
! !
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   266
!MeasurementValue methodsFor:'printing & storing'!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   267
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
printOn:aStream
11459
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   269
    aStream nextPutAll:'('.
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   270
    (maxValue-value) = (value-minValue) ifTrue:[
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   271
        value storeOn:aStream.
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   272
        aStream nextPutAll:' +/- '.
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   273
        (maxValue-value) storeOn:aStream
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   274
    ] ifFalse:[
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   275
        aStream nextPutAll:'MeasurementValue value:'.
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   276
        value storeOn:aStream.
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   277
        aStream nextPutAll:' minValue:'.
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   278
        minValue storeOn:aStream.
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   279
        aStream nextPutAll:' maxValue:'.
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   280
        maxValue storeOn:aStream.
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   281
    ].
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   282
    ')' printOn:aStream.
11459
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   283
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   284
    "
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   285
     (5 +/- 1) storeString 
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   286
     (MeasurementValue value:5 minValue:3 maxValue:8) storeString 
01ad9aa9217d better printing
Claus Gittinger <cg@exept.de>
parents: 11457
diff changeset
   287
    "
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   288
! !
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   289
11457
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   290
!MeasurementValue methodsFor:'private accessing'!
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   291
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   292
value:valueArg error:errorFraction 
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   293
    self 
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   294
        value:valueArg
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   295
        minValue:(valueArg * (1-errorFraction))
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   296
        maxValue:(valueArg * (1+errorFraction)). 
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   297
!
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   298
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   299
value:valueArg minValue:minValueArg maxValue:maxValueArg 
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   300
    value := valueArg.
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   301
    minValue := minValueArg.
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   302
    maxValue := maxValueArg.
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   303
! !
5ff638783ee0 double dispatch (actually coercing) support
Claus Gittinger <cg@exept.de>
parents: 11456
diff changeset
   304
10825
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   305
!MeasurementValue methodsFor:'testing'!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   306
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   307
between:min and:max
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   308
    minValue < min ifTrue:[^ false].
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   309
    maxValue > max ifTrue:[^ false].
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   310
    ^ true
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   311
! !
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   312
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   313
!MeasurementValue class methodsFor:'documentation'!
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   314
332b3ea2f8d6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   315
version
17869
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17865
diff changeset
   316
    ^ '$Id: MeasurementValue.st 10700 2011-09-29 15:44:37Z vranyj1 $'
17865
598963c6ff8e Recommited from itself
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17846
diff changeset
   317
!
598963c6ff8e Recommited from itself
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17846
diff changeset
   318
598963c6ff8e Recommited from itself
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17846
diff changeset
   319
version_SVN
17869
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17865
diff changeset
   320
    ^ '$Id: MeasurementValue.st 10700 2011-09-29 15:44:37Z vranyj1 $'
17846
24edc476ac18 Merged with /trunk
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 17845
diff changeset
   321
! !