ArithVal.st
author Claus Gittinger <cg@exept.de>
Fri, 18 Apr 1997 21:05:22 +0200
changeset 2568 9b7a3a08b8ca
parent 1888 463d49ca22e3
child 3134 22c7071ff004
permissions -rw-r--r--
added #rootsOfTheWorld for ST-80 compatibility
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1993 by Claus Gittinger
213
3b56a17534fd *** empty log message ***
claus
parents: 155
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
Magnitude subclass:#ArithmeticValue
1172
b135d4ae4bf2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    14
	instanceVariableNames:''
b135d4ae4bf2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    15
	classVariableNames:'DivisionByZeroSignal DomainErrorSignal OverflowSignal
b135d4ae4bf2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    16
		UnderflowSignal ArithmeticSignal AnyArithmeticSignal
b135d4ae4bf2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    17
		UnorderedSignal'
b135d4ae4bf2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    18
	poolDictionaries:''
b135d4ae4bf2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    19
	category:'Magnitude-Numbers'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    20
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    22
!ArithmeticValue class methodsFor:'documentation'!
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    23
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    24
copyright
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    25
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    26
 COPYRIGHT (c) 1993 by Claus Gittinger
213
3b56a17534fd *** empty log message ***
claus
parents: 155
diff changeset
    27
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    28
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    29
 This software is furnished under a license and may be used
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    30
 only in accordance with the terms of that license and with the
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    32
 be provided or otherwise made available to, or used by, any
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    33
 other person.  No title to or ownership of the software is
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    34
 hereby transferred.
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    35
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    36
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    37
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    38
documentation
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    39
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    40
    ArithmeticValue is an abstract superclass for all things responding to
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
    41
    arithmetic messages. It was inserted into the hierarchy, to allow objects
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
    42
    like matrices, functions etc. to share the arithmetic methods defined here.
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
    43
1283
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    44
    [class variables:]
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    45
        ArithmeticSignal        <Signal>        parent of all arithmetic signals
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    46
                                                (never raised itself)
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    47
1283
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    48
        DomainErrorSignal       <Signal>        raised upon float errors
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    49
                                                (for example range in trigonometric)
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    50
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    51
        DivisionByZeroSignal    <Signal>        raised when division by 0 is attempted
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
    52
1283
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    53
        OverflowSignal          <Signal>        raised on overflow/underflow conditions
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    54
        UnderflowSignal                         in float arithmetic. 
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    55
                                                Notice: some OperatingSystems do not 
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    56
                                                provide enough information for ST/X to 
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    57
                                                extract the real reason for the floatException
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    58
                                                thus raising DomainErrorSignal in these cases.
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
    59
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1283
diff changeset
    60
    [author:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1283
diff changeset
    61
        Claus Gittinger
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1283
diff changeset
    62
1283
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    63
    [See also:]
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    64
        Number
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    65
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    66
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    67
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    68
!ArithmeticValue class methodsFor:'initialization'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    69
a27a279701f8 Initial revision
claus
parents:
diff changeset
    70
initialize
a27a279701f8 Initial revision
claus
parents:
diff changeset
    71
    "setup the signals"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    72
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 3
diff changeset
    73
    DomainErrorSignal isNil ifTrue:[
302
1f76060d58a4 *** empty log message ***
claus
parents: 213
diff changeset
    74
	ArithmeticSignal := ErrorSignal newSignalMayProceed:false.
213
3b56a17534fd *** empty log message ***
claus
parents: 155
diff changeset
    75
	ArithmeticSignal nameClass:self message:#arithmeticSignal.
3b56a17534fd *** empty log message ***
claus
parents: 155
diff changeset
    76
	ArithmeticSignal notifierString:'arithmetic error'.
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
    77
213
3b56a17534fd *** empty log message ***
claus
parents: 155
diff changeset
    78
	DomainErrorSignal := ArithmeticSignal newSignalMayProceed:false.
3b56a17534fd *** empty log message ***
claus
parents: 155
diff changeset
    79
	DomainErrorSignal nameClass:self message:#domainErrorSignal.
3b56a17534fd *** empty log message ***
claus
parents: 155
diff changeset
    80
	DomainErrorSignal notifierString:'domain error'.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    81
213
3b56a17534fd *** empty log message ***
claus
parents: 155
diff changeset
    82
	DivisionByZeroSignal := ArithmeticSignal newSignalMayProceed:false.
3b56a17534fd *** empty log message ***
claus
parents: 155
diff changeset
    83
	DivisionByZeroSignal nameClass:self message:#divisionByZeroSignal.
3b56a17534fd *** empty log message ***
claus
parents: 155
diff changeset
    84
	DivisionByZeroSignal notifierString:'division by zero'.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    85
213
3b56a17534fd *** empty log message ***
claus
parents: 155
diff changeset
    86
	OverflowSignal := ArithmeticSignal newSignalMayProceed:false.
3b56a17534fd *** empty log message ***
claus
parents: 155
diff changeset
    87
	OverflowSignal nameClass:self message:#overflowSignal.
3b56a17534fd *** empty log message ***
claus
parents: 155
diff changeset
    88
	OverflowSignal notifierString:'overflow'.
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 3
diff changeset
    89
213
3b56a17534fd *** empty log message ***
claus
parents: 155
diff changeset
    90
	UnderflowSignal := ArithmeticSignal newSignalMayProceed:false.
3b56a17534fd *** empty log message ***
claus
parents: 155
diff changeset
    91
	UnderflowSignal nameClass:self message:#underflowSignal.
3b56a17534fd *** empty log message ***
claus
parents: 155
diff changeset
    92
	UnderflowSignal notifierString:'underflow'.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    93
345
claus
parents: 326
diff changeset
    94
	UnorderedSignal := ArithmeticSignal newSignalMayProceed:false.
claus
parents: 326
diff changeset
    95
	UnorderedSignal nameClass:self message:#unorderedSignal.
claus
parents: 326
diff changeset
    96
	UnorderedSignal notifierString:'unordered'.
claus
parents: 326
diff changeset
    97
213
3b56a17534fd *** empty log message ***
claus
parents: 155
diff changeset
    98
	AnyArithmeticSignal := SignalSet with:DomainErrorSignal
3b56a17534fd *** empty log message ***
claus
parents: 155
diff changeset
    99
					 with:DivisionByZeroSignal
3b56a17534fd *** empty log message ***
claus
parents: 155
diff changeset
   100
					 with:OverflowSignal
345
claus
parents: 326
diff changeset
   101
					 with:UnderflowSignal
claus
parents: 326
diff changeset
   102
					 with:UnorderedSignal.
54
06dbdeeed4f9 *** empty log message ***
claus
parents: 3
diff changeset
   103
    ]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   104
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   105
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   106
!ArithmeticValue class methodsFor:'Signal constants'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   107
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   108
anyArithmeticSignal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   109
    "return a signalSet with all possible arithmetic signals.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   110
     OBSOLETE: this will vanish, since starting with 2.10.3, signal parents
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   111
	       have been added."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   112
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   113
    ^ AnyArithmeticSignal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   114
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   115
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   116
arithmeticSignal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   117
    "return the parent of all arithmetic signals"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   118
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   119
    ^ ArithmeticSignal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   120
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   121
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   122
divisionByZeroSignal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   123
    "return the signal which is raised on division by zero"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   124
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   125
    ^ DivisionByZeroSignal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   126
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   127
a27a279701f8 Initial revision
claus
parents:
diff changeset
   128
domainErrorSignal
a27a279701f8 Initial revision
claus
parents:
diff changeset
   129
    "return the signal which is raised on math errors
a27a279701f8 Initial revision
claus
parents:
diff changeset
   130
     (such as log of 0 etc.)"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   131
a27a279701f8 Initial revision
claus
parents:
diff changeset
   132
    ^ DomainErrorSignal
a27a279701f8 Initial revision
claus
parents:
diff changeset
   133
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   134
a27a279701f8 Initial revision
claus
parents:
diff changeset
   135
overflowSignal
a27a279701f8 Initial revision
claus
parents:
diff changeset
   136
    "return the signal which is raised on overflow conditions (in floats)"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   137
a27a279701f8 Initial revision
claus
parents:
diff changeset
   138
    ^ OverflowSignal
a27a279701f8 Initial revision
claus
parents:
diff changeset
   139
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   140
a27a279701f8 Initial revision
claus
parents:
diff changeset
   141
underflowSignal
a27a279701f8 Initial revision
claus
parents:
diff changeset
   142
    "return the signal which is raised on underflow conditions (in floats)"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   143
a27a279701f8 Initial revision
claus
parents:
diff changeset
   144
    ^ UnderflowSignal
a27a279701f8 Initial revision
claus
parents:
diff changeset
   145
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   146
345
claus
parents: 326
diff changeset
   147
unorderedSignal
claus
parents: 326
diff changeset
   148
    "return the signal which is raised when numbers are compared, 
claus
parents: 326
diff changeset
   149
     for which no ordering is defined (for example: complex numbers)"
claus
parents: 326
diff changeset
   150
claus
parents: 326
diff changeset
   151
    ^ UnderflowSignal
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   152
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   153
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   154
!ArithmeticValue methodsFor:'arithmetic'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   155
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   156
* something
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   157
    "return the product of the receiver and the argument"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   158
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   159
    ^ self subclassResponsibility
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   160
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   161
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   162
+ something
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   163
    "return the sum of the receiver and the argument"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   164
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   165
    ^ self subclassResponsibility
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   166
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   167
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   168
- something
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   169
    "return the difference of the receiver and the argument"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   170
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   171
    ^ self subclassResponsibility
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   172
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   173
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   174
/ something
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   175
    "return the quotient of the receiver and the argument"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   176
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   177
    ^ self subclassResponsibility
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   178
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   179
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   180
// something
1881
0c6ba2c134c1 fixed #rounded
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   181
    "return the integer quotient of dividing the receiver by aNumber with
0c6ba2c134c1 fixed #rounded
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   182
     truncation towards negative infinity."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   183
1172
b135d4ae4bf2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   184
    "/ changed: the code below may lead to infinite recursion
b135d4ae4bf2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   185
b135d4ae4bf2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   186
    ^ self subclassResponsibility
b135d4ae4bf2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   187
"/    ^ (self / something) floor
b135d4ae4bf2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   188
1881
0c6ba2c134c1 fixed #rounded
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   189
    "Modified: 5.11.1996 / 11:46:27 / cg"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   190
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   191
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   192
\\ something
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   193
    "return the integer modulu of the receiver and the argument"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   194
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   195
    ^ self - ((self // something) * something)
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   196
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   197
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   198
abs
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   199
    "return the absolute value of the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   200
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   201
    (self negative) ifTrue:[^ self negated].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   202
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   203
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   204
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   205
negated
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   206
    "return the receiver negated"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   207
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   208
    ^ self class zero - self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   209
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   210
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   211
quo:something
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   212
    "Return the integer quotient of dividing the receiver by the argument
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   213
     with truncation towards zero."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   214
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   215
    ^ (self / something) truncated
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   216
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   217
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   218
reciprocal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   219
    "return the receivers reciprocal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   220
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   221
    ^ self class unity / self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   222
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   223
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   224
rem:something
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   225
    "Return the integer remainder of dividing the receiver by the argument
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   226
     with truncation towards zero.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   227
     The remainder has the same sign as the receiver."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   228
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   229
    ^ self - ((self quo:something) * something)
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   230
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   231
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   232
!ArithmeticValue methodsFor:'coercing'!
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   233
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   234
coerce:aNumber
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   235
    "convert aNumber into an instance of the receivers class and return it."
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   236
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   237
    ^ self subclassResponsibility
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   238
!
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   239
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   240
generality
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   241
    "return a number giving the receivers generality, that number is
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   242
     used to convert one of the arguments in a mixed expression. 
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   243
     The generality has to be defined in subclasses,
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   244
     such that gen(a) > gen(b) iff, conversion of b into a's class 
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   245
     does not cut precision. For example, Integer has 40, Float has 80,
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   246
     meaning that if we convert a Float to an Integer, some precision may
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   247
     be lost. The generality is used by ArithmeticValue>>retry:coercing:,
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   248
     which converts the lower-prevision number to the higher precision
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   249
     numbers class, when mixed-type arithmetic is performed."
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   250
      
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   251
    ^ self subclassResponsibility
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   252
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   253
    "Modified: 5.11.1996 / 15:05:30 / cg"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   254
!
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   255
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   256
retry:aSymbol coercing:aNumber
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   257
    "arithmetic represented by the binary operator, aSymbol,
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   258
     could not be performed with the receiver and the argument, aNumber, 
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   259
     because of the differences in representation.  
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   260
     Coerce either the receiver or the argument, depending on which has higher 
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   261
     generality, and try again.  
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   262
     If the operation is compare for same value (=), return false if
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   263
     the argument is not a Number. 
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   264
     If the generalities are the same, create an error message, since this
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   265
     means that a subclass has not been fully implemented."
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   266
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   267
    |hasGenerality myGenerality otherGenerality|
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   268
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   269
    hasGenerality := aNumber respondsTo:#generality.
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   270
    hasGenerality ifFalse:[
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   271
        (aSymbol == #=) ifTrue:[
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   272
            ^ false
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   273
        ].
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   274
        (aSymbol == #~=) ifTrue:[
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   275
            ^ true
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   276
        ].
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   277
        ^ self error:'retry:coercing: argument is not a number'.
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   278
    ].
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   279
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   280
    myGenerality := self generality.
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   281
    otherGenerality := aNumber generality.
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   282
    (myGenerality > otherGenerality) ifTrue:[
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   283
        ^ self perform:aSymbol with:(self coerce:aNumber)
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   284
    ].
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   285
    (myGenerality < otherGenerality) ifTrue:[
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   286
        ^ (aNumber coerce:self) perform:aSymbol with:aNumber
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   287
    ].
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   288
    self error:'retry:coercing: oops - same generality'
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   289
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   290
    "Modified: 5.11.1996 / 15:03:38 / cg"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   291
! !
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   292
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   293
!ArithmeticValue methodsFor:'comparing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   294
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   295
< something
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   296
    "return true, if the argument is greater than the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   297
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   298
    ^ self subclassResponsibility
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   299
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   300
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   301
<= something
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   302
    "return true, if the argument is greater or equal than the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   303
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   304
    ^ (something < self) not
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   305
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   306
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   307
> something
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   308
    "return true, if the argument is less than the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   309
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   310
    ^ something < self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   311
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   312
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   313
>= something
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   314
    "return true, if the argument is less or equal than the receiver"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   315
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   316
    ^ (self < something) not
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   317
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   318
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   319
compare:arg ifLess:lessBlock ifEqual:equalBlock ifGreater:greaterBlock
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   320
    "three-way compare - thanks to Self for this idea.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   321
     Can be redefined in subclasses to do it with a single comparison if
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   322
     comparison is expensive."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   323
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   324
    self < arg ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   325
	^ lessBlock value
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   326
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   327
    self = arg ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   328
	^ equalBlock value
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   329
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   330
    ^ greaterBlock value
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   331
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   332
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   333
!ArithmeticValue methodsFor:'converting'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   334
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   335
asFloat
a27a279701f8 Initial revision
claus
parents:
diff changeset
   336
    "return a float with same value"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   337
a27a279701f8 Initial revision
claus
parents:
diff changeset
   338
   ^ self subclassResponsibility
a27a279701f8 Initial revision
claus
parents:
diff changeset
   339
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   340
a27a279701f8 Initial revision
claus
parents:
diff changeset
   341
asFraction
a27a279701f8 Initial revision
claus
parents:
diff changeset
   342
    "return a fraction with same value"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   343
a27a279701f8 Initial revision
claus
parents:
diff changeset
   344
   ^ self subclassResponsibility
a27a279701f8 Initial revision
claus
parents:
diff changeset
   345
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   346
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   347
asInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   348
    "return an integer with same value - might truncate"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   349
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   350
    ^ self truncated
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   351
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   352
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   353
asShortFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   354
    "return a shortFloat with same value"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   355
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   356
   ^ self asFloat asShortFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   357
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   358
    "Modified: 17.4.1996 / 12:21:35 / cg"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   359
!
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   360
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   361
degreesToRadians
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   362
    "interpreting the receiver as radians, return the degrees"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   363
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   364
    ^ self asFloat degreesToRadians
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   365
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   366
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   367
radiansToDegrees
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   368
    "interpreting the receiver as degrees, return the radians"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   369
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   370
    ^ self asFloat radiansToDegrees
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   371
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   372
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   373
!ArithmeticValue methodsFor:'double dispatching'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   374
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   375
differenceFromFixedPoint:aFixedPoint
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   376
    "the receiver does not know how to subtract from a fixedPoint number -
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   377
     retry the operation by coercing to higher generality"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   378
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   379
    ^ aFixedPoint retry:#- coercing:self
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   380
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   381
    "Created: 5.11.1996 / 14:55:51 / cg"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   382
!
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   383
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   384
differenceFromFloat:aFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   385
    "the receiver does not know how to subtract from a float -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   386
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   387
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   388
    ^ aFloat retry:#- coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   389
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   390
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   391
differenceFromFraction:aFraction
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   392
    "the receiver does not know how to subtract from a fraction -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   393
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   394
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   395
    ^ aFraction retry:#- coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   396
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   397
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   398
differenceFromInteger:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   399
    "the receiver does not know how to subtract from an integer -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   400
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   401
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   402
    ^ anInteger retry:#- coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   403
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   404
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   405
differenceFromShortFloat:aShortFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   406
    "the receiver does not know how to subtract from a shortFloat -
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   407
     retry the operation by coercing to higher generality"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   408
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   409
    ^ aShortFloat retry:#- coercing:self
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   410
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   411
    "Created: 17.4.1996 / 12:33:16 / cg"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   412
!
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   413
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   414
lessFromFixedPoint:aFixedPoint
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   415
    "the receiver does not know how to compare to a fixedPoint number -
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   416
     retry the operation by coercing to higher generality"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   417
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   418
    ^ aFixedPoint retry:#< coercing:self
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   419
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   420
    "Created: 5.11.1996 / 14:56:12 / cg"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   421
!
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   422
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   423
lessFromFloat:aFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   424
    "the receiver does not know how to compare to a float -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   425
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   426
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   427
    ^ aFloat retry:#< coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   428
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   429
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   430
lessFromFraction:aFraction
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   431
    "the receiver does not know how to compare to a fraction -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   432
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   433
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   434
    ^ aFraction retry:#< coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   435
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   436
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   437
lessFromInteger:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   438
    "the receiver does not know how to compare to an integer -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   439
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   440
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   441
    ^ anInteger retry:#< coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   442
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   443
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   444
lessFromShortFloat:aShortFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   445
    "the receiver does not know how to compare to a shortFloat -
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   446
     retry the operation by coercing to higher generality"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   447
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   448
    ^ aShortFloat retry:#< coercing:self
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   449
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   450
    "Modified: 17.4.1996 / 12:33:33 / cg"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   451
!
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   452
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   453
productFromFixedPoint:aFixedPoint
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   454
    "the receiver does not know how to multiply a fixed point number -
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   455
     retry the operation by coercing to higher generality"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   456
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   457
    ^ aFixedPoint retry:#* coercing:self
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   458
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   459
    "Created: 5.11.1996 / 14:56:28 / cg"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   460
!
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   461
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   462
productFromFloat:aFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   463
    "the receiver does not know how to multiply a float -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   464
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   465
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   466
    ^ aFloat retry:#* coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   467
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   468
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   469
productFromFraction:aFraction
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   470
    "the receiver does not know how to multiply a fraction -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   471
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   472
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   473
    ^ aFraction retry:#* coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   474
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   475
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   476
productFromInteger:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   477
    "the receiver does not know how to multiply an integer -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   478
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   479
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   480
    ^ anInteger retry:#* coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   481
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   482
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   483
productFromShortFloat:aShortFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   484
    "the receiver does not know how to multiply a shortFloat -
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   485
     retry the operation by coercing to higher generality"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   486
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   487
    ^ aShortFloat retry:#* coercing:self
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   488
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   489
    "Created: 17.4.1996 / 12:33:48 / cg"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   490
!
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   491
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   492
quotientFromFixedPoint:aFixedPoint
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   493
    "the receiver does not know how to divide a fixed point number -
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   494
     retry the operation by coercing to higher generality"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   495
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   496
    ^ aFixedPoint retry:#/ coercing:self
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   497
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   498
    "Created: 5.11.1996 / 14:56:41 / cg"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   499
!
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   500
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   501
quotientFromFloat:aFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   502
    "the receiver does not know how to divide a float -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   503
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   504
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   505
    ^ aFloat retry:#/ coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   506
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   507
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   508
quotientFromFraction:aFraction
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   509
    "the receiver does not know how to divide a fraction -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   510
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   511
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   512
    ^ aFraction retry:#/ coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   513
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   514
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   515
quotientFromInteger:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   516
    "the receiver does not know how to divide an integer -
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   517
     retry the operation by coercing to higher generality"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   518
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   519
    ^ anInteger retry:#/ coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   520
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   521
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   522
quotientFromShortFloat:aShortFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   523
    "the receiver does not know how to divide a shortFloat -
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   524
     retry the operation by coercing to higher generality"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   525
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   526
    ^ aShortFloat retry:#/ coercing:self
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   527
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   528
    "Created: 17.4.1996 / 12:34:00 / cg"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   529
!
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   530
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   531
sumFromFixedPoint:aFixedPoint
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   532
    "the receiver does not know how to add a fixed point number -
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   533
     retry the operation by coercing to higher generality"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   534
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   535
    ^ aFixedPoint retry:#+ coercing:self
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   536
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   537
    "Created: 5.11.1996 / 14:56:56 / cg"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   538
!
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   539
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   540
sumFromFloat:aFloat
a27a279701f8 Initial revision
claus
parents:
diff changeset
   541
    "the receiver does not know how to add a float -
a27a279701f8 Initial revision
claus
parents:
diff changeset
   542
     retry the operation by coercing to higher generality"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   543
a27a279701f8 Initial revision
claus
parents:
diff changeset
   544
    ^ aFloat retry:#+ coercing:self
a27a279701f8 Initial revision
claus
parents:
diff changeset
   545
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   546
a27a279701f8 Initial revision
claus
parents:
diff changeset
   547
sumFromFraction:aFraction
a27a279701f8 Initial revision
claus
parents:
diff changeset
   548
    "the receiver does not know how to add a fraction -
a27a279701f8 Initial revision
claus
parents:
diff changeset
   549
     retry the operation by coercing to higher generality"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   550
a27a279701f8 Initial revision
claus
parents:
diff changeset
   551
    ^ aFraction retry:#+ coercing:self
a27a279701f8 Initial revision
claus
parents:
diff changeset
   552
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   553
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   554
sumFromInteger:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   555
    "the receiver does not know how to add an integer -
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   556
     retry the operation by coercing to higher generality"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   557
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   558
    ^ anInteger retry:#+ coercing:self
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   559
!
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   560
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   561
sumFromShortFloat:aShortFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   562
    "the receiver does not know how to add a shortFloat -
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   563
     retry the operation by coercing to higher generality"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   564
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   565
    ^ aShortFloat retry:#+ coercing:self
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   566
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   567
    "Created: 17.4.1996 / 12:34:10 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   568
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   569
a27a279701f8 Initial revision
claus
parents:
diff changeset
   570
!ArithmeticValue methodsFor:'misc math'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   571
a27a279701f8 Initial revision
claus
parents:
diff changeset
   572
exp
a27a279701f8 Initial revision
claus
parents:
diff changeset
   573
    "return e ^ receiver"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   574
a27a279701f8 Initial revision
claus
parents:
diff changeset
   575
    ^ self asFloat exp
a27a279701f8 Initial revision
claus
parents:
diff changeset
   576
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   577
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   578
floorLog:radix
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   579
    "return the logarithm truncated as an integer"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   580
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   581
    ^ (self log:radix) floor
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   582
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   583
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   584
ln
a27a279701f8 Initial revision
claus
parents:
diff changeset
   585
    "return the natural logarithm of the receiver"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   586
a27a279701f8 Initial revision
claus
parents:
diff changeset
   587
    ^ self asFloat ln
a27a279701f8 Initial revision
claus
parents:
diff changeset
   588
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   589
a27a279701f8 Initial revision
claus
parents:
diff changeset
   590
log
a27a279701f8 Initial revision
claus
parents:
diff changeset
   591
    "return log base 10 of the receiver"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   592
a27a279701f8 Initial revision
claus
parents:
diff changeset
   593
    ^ self log:10
a27a279701f8 Initial revision
claus
parents:
diff changeset
   594
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   595
a27a279701f8 Initial revision
claus
parents:
diff changeset
   596
log:aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   597
    "return log base aNumber of the receiver"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   598
a27a279701f8 Initial revision
claus
parents:
diff changeset
   599
    ^ self ln / aNumber ln
a27a279701f8 Initial revision
claus
parents:
diff changeset
   600
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   601
a27a279701f8 Initial revision
claus
parents:
diff changeset
   602
raisedTo:aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   603
    "return the receiver raised to aNumber"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   604
a27a279701f8 Initial revision
claus
parents:
diff changeset
   605
    aNumber = 0 ifTrue:[^ 1].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   606
    aNumber = 1 ifTrue:[^ self].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   607
    aNumber isInteger ifTrue:[
213
3b56a17534fd *** empty log message ***
claus
parents: 155
diff changeset
   608
	^ self raisedToInteger:aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   609
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   610
    ^ self asFloat raisedTo:aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   611
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   612
a27a279701f8 Initial revision
claus
parents:
diff changeset
   613
raisedToInteger:anInteger
a27a279701f8 Initial revision
claus
parents:
diff changeset
   614
    "return the receiver raised to anInteger"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   615
a27a279701f8 Initial revision
claus
parents:
diff changeset
   616
    |count result|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   617
a27a279701f8 Initial revision
claus
parents:
diff changeset
   618
    result := self coerce:1.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   619
    count := anInteger abs.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   620
    count timesRepeat:[result := result * self].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   621
    (anInteger < 0) ifTrue:[
213
3b56a17534fd *** empty log message ***
claus
parents: 155
diff changeset
   622
	^ 1 / result
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   623
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   624
    ^ result
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   625
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   626
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   627
sqrt
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   628
    "return the square root of the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   629
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   630
    ^ self asFloat sqrt
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   631
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   632
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   633
squared
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   634
    "return receiver * receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   635
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   636
    ^ self * self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   637
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   638
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   639
!ArithmeticValue methodsFor:'queries'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   640
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   641
respondsToArithmetic
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   642
    "return true, if the receiver responds to arithmetic messages"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   643
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   644
    ^ true
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   645
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   646
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   647
!ArithmeticValue methodsFor:'testing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   648
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   649
denominator
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   650
    "return the denominator of the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   651
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   652
    ^ 1
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   653
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   654
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   655
even
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   656
    "return true if the receiver is divisible by 2"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   657
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   658
    ^ self truncated asInteger even
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   659
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   660
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   661
negative
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   662
    "return true, if the receiver is < 0"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   663
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   664
    " this would lead to infinite recursion ...
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   665
    ^ (self < 0)
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   666
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   667
    ^ self subclassResponsibility
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   668
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   669
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   670
numerator
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   671
    "return the numerator of the receiver."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   672
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   673
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   674
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   675
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   676
odd
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   677
    "return true if the receiver is not divisible by 2"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   678
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   679
    ^ self even not
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   680
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   681
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   682
positive
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   683
    "return true, if the receiver is >= 0"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   684
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   685
    ^ self negative not
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   686
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   687
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   688
sign
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   689
    "return the sign of the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   690
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   691
    (self < 0) ifTrue:[^ -1].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   692
    (self > 0) ifTrue:[^ 1].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   693
    ^ 0
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   694
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   695
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   696
strictlyPositive
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   697
    "return true, if the receiver is > 0"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   698
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   699
    ^ (self > 0)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   700
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   701
a27a279701f8 Initial revision
claus
parents:
diff changeset
   702
!ArithmeticValue methodsFor:'trigonometric'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   703
a27a279701f8 Initial revision
claus
parents:
diff changeset
   704
arcCos
a27a279701f8 Initial revision
claus
parents:
diff changeset
   705
    "return the arccosine of the receiver (in radians)"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   706
a27a279701f8 Initial revision
claus
parents:
diff changeset
   707
    ^ self asFloat arcCos
a27a279701f8 Initial revision
claus
parents:
diff changeset
   708
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   709
a27a279701f8 Initial revision
claus
parents:
diff changeset
   710
arcSin
a27a279701f8 Initial revision
claus
parents:
diff changeset
   711
    "return the arcsine of the receiver (in radians)"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   712
a27a279701f8 Initial revision
claus
parents:
diff changeset
   713
    ^ self asFloat arcSin
a27a279701f8 Initial revision
claus
parents:
diff changeset
   714
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   715
a27a279701f8 Initial revision
claus
parents:
diff changeset
   716
arcTan
a27a279701f8 Initial revision
claus
parents:
diff changeset
   717
    "return the arctangens of the receiver (in radians)"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   718
a27a279701f8 Initial revision
claus
parents:
diff changeset
   719
    ^ self asFloat arcTan
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   720
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   721
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   722
cos
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   723
    "return the cosine of the receiver (interpreted as radians)"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   724
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   725
    ^ self asFloat cos
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   726
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   727
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   728
sin
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   729
    "return the sine of the receiver (interpreted as radians)"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   730
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   731
    ^ self asFloat sin
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   732
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   733
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   734
tan
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   735
    "return the tangens of the receiver (interpreted as radians)"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   736
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   737
    ^ self asFloat tan
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   738
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   739
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   740
!ArithmeticValue methodsFor:'truncation & rounding'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   741
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   742
ceiling
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   743
    "return the integer nearest the receiver towards positive infinity."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   744
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   745
    |anInteger|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   746
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   747
    anInteger := self // 1.       "truncates towards negative infinity"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   748
    anInteger = self ifTrue:[^ anInteger].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   749
    ^ anInteger + 1
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   750
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   751
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   752
floor
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   753
    "return the receiver truncated towards negative infinity"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   754
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   755
    ^ self // 1
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   756
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   757
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   758
roundTo:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   759
    "return the receiver rounded to multiples of aNumber"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   760
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   761
    ^ (self / aNumber) rounded * aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   762
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   763
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   764
rounded
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   765
    "return the integer nearest the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   766
1881
0c6ba2c134c1 fixed #rounded
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   767
    self negative ifTrue:[
0c6ba2c134c1 fixed #rounded
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   768
        ^ (self - 0.5) ceiling
0c6ba2c134c1 fixed #rounded
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   769
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   770
    ^ (self + 0.5) floor
1881
0c6ba2c134c1 fixed #rounded
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   771
0c6ba2c134c1 fixed #rounded
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   772
    "Modified: 5.11.1996 / 11:31:59 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   773
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   774
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   775
truncateTo:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   776
    "return the receiver truncated to multiples of aNumber"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   777
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   778
    ^ ((self / aNumber) floor * aNumber) asInteger
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   779
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   780
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   781
truncated
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   782
    "return the receiver truncated towards zero"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   783
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   784
    self negative ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   785
	^ self ceiling
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   786
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   787
    ^ self floor
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   788
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   789
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   790
!ArithmeticValue class methodsFor:'documentation'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   791
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   792
version
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   793
    ^ '$Header: /cvs/stx/stx/libbasic/Attic/ArithVal.st,v 1.24 1996-11-05 18:24:43 cg Exp $'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   794
! !
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   795
ArithmeticValue initialize!