ArithmeticValue.st
author Stefan Vogel <sv@exept.de>
Fri, 11 Apr 2003 18:47:17 +0200
changeset 7205 903fef64420c
parent 7142 7a6297c86ef4
child 7228 b7c66af018f8
permissions -rw-r--r--
#errorSignal -> #description
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
5948
1fc30f692713 new class based exceptions
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
    13
"{ Package: 'stx:libbasic' }"
1fc30f692713 new class based exceptions
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
    14
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    15
Magnitude subclass:#ArithmeticValue
1172
b135d4ae4bf2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    16
	instanceVariableNames:''
b135d4ae4bf2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    17
	classVariableNames:'DivisionByZeroSignal DomainErrorSignal OverflowSignal
6342
fbbe62d5b17c Remove obsolete (since years) AnyArithmeticSignal definitions.
Stefan Vogel <sv@exept.de>
parents: 6156
diff changeset
    18
		UnderflowSignal ArithmeticSignal UnorderedSignal
fbbe62d5b17c Remove obsolete (since years) AnyArithmeticSignal definitions.
Stefan Vogel <sv@exept.de>
parents: 6156
diff changeset
    19
		ConversionErrorSignal'
1172
b135d4ae4bf2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    20
	poolDictionaries:''
b135d4ae4bf2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    21
	category:'Magnitude-Numbers'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    22
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    23
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    24
!ArithmeticValue class methodsFor:'documentation'!
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    25
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    26
copyright
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    27
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    28
 COPYRIGHT (c) 1993 by Claus Gittinger
213
3b56a17534fd *** empty log message ***
claus
parents: 155
diff changeset
    29
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    30
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    31
 This software is furnished under a license and may be used
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    32
 only in accordance with the terms of that license and with the
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    33
 inclusion of the above copyright notice.   This software may not
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    34
 be provided or otherwise made available to, or used by, any
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    35
 other person.  No title to or ownership of the software is
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    36
 hereby transferred.
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    37
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    38
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    39
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    40
documentation
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    41
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    42
    ArithmeticValue is an abstract superclass for all things responding to
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
    43
    arithmetic messages. It was inserted into the hierarchy, to allow objects
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
    44
    like matrices, functions etc. to share the arithmetic methods defined here.
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
    45
5955
4d973d840a00 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    46
    Notice, that what used to be signals are now exception classes - the class
4d973d840a00 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    47
    variables and signal accessors remain here for backward compatibility.
4d973d840a00 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    48
1283
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    49
    [class variables:]
6691
48ba39288455 error notifiers are now initialized there
Claus Gittinger <cg@exept.de>
parents: 6342
diff changeset
    50
        ArithmeticSignal        <Error>         parent of all arithmetic signals
1283
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    51
                                                (never raised itself)
5957
bfe534c912f6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5955
diff changeset
    52
                                                New: now a reference to ArithmeticError
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    53
6691
48ba39288455 error notifiers are now initialized there
Claus Gittinger <cg@exept.de>
parents: 6342
diff changeset
    54
        DomainErrorSignal       <Error>         raised upon float errors
1283
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    55
                                                (for example range in trigonometric)
5957
bfe534c912f6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5955
diff changeset
    56
                                                New: now a reference to DomainError
1283
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    57
6691
48ba39288455 error notifiers are now initialized there
Claus Gittinger <cg@exept.de>
parents: 6342
diff changeset
    58
        DivisionByZeroSignal    <Error>         raised when division by 0 is attempted
5957
bfe534c912f6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5955
diff changeset
    59
                                                New: now a reference to ZeroDivide
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
    60
6691
48ba39288455 error notifiers are now initialized there
Claus Gittinger <cg@exept.de>
parents: 6342
diff changeset
    61
        OverflowSignal          <Error>         raised on overflow/underflow conditions
1283
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    62
        UnderflowSignal                         in float arithmetic. 
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    63
                                                Notice: some OperatingSystems do not 
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    64
                                                provide enough information for ST/X to 
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    65
                                                extract the real reason for the floatException
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    66
                                                thus raising DomainErrorSignal in these cases.
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
    67
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1283
diff changeset
    68
    [author:]
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1283
diff changeset
    69
        Claus Gittinger
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1283
diff changeset
    70
1283
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    71
    [See also:]
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    72
        Number
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    73
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    74
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    75
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    76
!ArithmeticValue class methodsFor:'initialization'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    77
5954
d706efecb134 ZeroDivide has a parameter
Claus Gittinger <cg@exept.de>
parents: 5948
diff changeset
    78
initialize
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    79
    "setup the signals"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    80
6691
48ba39288455 error notifiers are now initialized there
Claus Gittinger <cg@exept.de>
parents: 6342
diff changeset
    81
    "/ notice that we now use class based exceptions;
48ba39288455 error notifiers are now initialized there
Claus Gittinger <cg@exept.de>
parents: 6342
diff changeset
    82
    "/ however, for backward compatibility, the class variables
48ba39288455 error notifiers are now initialized there
Claus Gittinger <cg@exept.de>
parents: 6342
diff changeset
    83
    "/ referring to those are kept for a while, for subclass compatibility.
48ba39288455 error notifiers are now initialized there
Claus Gittinger <cg@exept.de>
parents: 6342
diff changeset
    84
    "/ Please convert your code to access those via the Signal-constants class
48ba39288455 error notifiers are now initialized there
Claus Gittinger <cg@exept.de>
parents: 6342
diff changeset
    85
    "/ messages (accesors) instead of referring to the class variables.
5948
1fc30f692713 new class based exceptions
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
    86
6691
48ba39288455 error notifiers are now initialized there
Claus Gittinger <cg@exept.de>
parents: 6342
diff changeset
    87
    ArithmeticSignal := ArithmeticError.
48ba39288455 error notifiers are now initialized there
Claus Gittinger <cg@exept.de>
parents: 6342
diff changeset
    88
    DomainErrorSignal := DomainError.
48ba39288455 error notifiers are now initialized there
Claus Gittinger <cg@exept.de>
parents: 6342
diff changeset
    89
    DivisionByZeroSignal := ZeroDivide.
48ba39288455 error notifiers are now initialized there
Claus Gittinger <cg@exept.de>
parents: 6342
diff changeset
    90
    UnorderedSignal := UnorderedNumbersError.
48ba39288455 error notifiers are now initialized there
Claus Gittinger <cg@exept.de>
parents: 6342
diff changeset
    91
    ConversionErrorSignal := ConversionError.
48ba39288455 error notifiers are now initialized there
Claus Gittinger <cg@exept.de>
parents: 6342
diff changeset
    92
    OverflowSignal := OverflowError.
48ba39288455 error notifiers are now initialized there
Claus Gittinger <cg@exept.de>
parents: 6342
diff changeset
    93
    UnderflowSignal := UnderflowError.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    94
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
    95
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    96
!ArithmeticValue class methodsFor:'Signal constants'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    97
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    98
arithmeticSignal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    99
    "return the parent of all arithmetic signals"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   100
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   101
    ^ ArithmeticSignal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   102
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   103
4995
9556c41783f5 added a conversionErrorSignal
Claus Gittinger <cg@exept.de>
parents: 4453
diff changeset
   104
conversionErrorSignal
9556c41783f5 added a conversionErrorSignal
Claus Gittinger <cg@exept.de>
parents: 4453
diff changeset
   105
    "return the signal which is raised when a conversion fails
9556c41783f5 added a conversionErrorSignal
Claus Gittinger <cg@exept.de>
parents: 4453
diff changeset
   106
     (such as bcd decoding of an invalid BCD number)"
9556c41783f5 added a conversionErrorSignal
Claus Gittinger <cg@exept.de>
parents: 4453
diff changeset
   107
9556c41783f5 added a conversionErrorSignal
Claus Gittinger <cg@exept.de>
parents: 4453
diff changeset
   108
    ^ ConversionErrorSignal
9556c41783f5 added a conversionErrorSignal
Claus Gittinger <cg@exept.de>
parents: 4453
diff changeset
   109
9556c41783f5 added a conversionErrorSignal
Claus Gittinger <cg@exept.de>
parents: 4453
diff changeset
   110
    "Created: / 15.11.1999 / 20:34:18 / cg"
9556c41783f5 added a conversionErrorSignal
Claus Gittinger <cg@exept.de>
parents: 4453
diff changeset
   111
!
9556c41783f5 added a conversionErrorSignal
Claus Gittinger <cg@exept.de>
parents: 4453
diff changeset
   112
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   113
divisionByZeroSignal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   114
    "return the signal which is raised on division by zero"
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
    ^ DivisionByZeroSignal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   117
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   118
a27a279701f8 Initial revision
claus
parents:
diff changeset
   119
domainErrorSignal
a27a279701f8 Initial revision
claus
parents:
diff changeset
   120
    "return the signal which is raised on math errors
a27a279701f8 Initial revision
claus
parents:
diff changeset
   121
     (such as log of 0 etc.)"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   122
a27a279701f8 Initial revision
claus
parents:
diff changeset
   123
    ^ DomainErrorSignal
a27a279701f8 Initial revision
claus
parents:
diff changeset
   124
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   125
a27a279701f8 Initial revision
claus
parents:
diff changeset
   126
overflowSignal
a27a279701f8 Initial revision
claus
parents:
diff changeset
   127
    "return the signal which is raised on overflow conditions (in floats)"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   128
a27a279701f8 Initial revision
claus
parents:
diff changeset
   129
    ^ OverflowSignal
a27a279701f8 Initial revision
claus
parents:
diff changeset
   130
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   131
5955
4d973d840a00 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   132
rangeErrorSignal
4d973d840a00 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   133
    "return the parent of the overflow/underflow signals"
4d973d840a00 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   134
4d973d840a00 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   135
    ^ RangeError
4d973d840a00 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   136
!
4d973d840a00 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   137
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   138
underflowSignal
a27a279701f8 Initial revision
claus
parents:
diff changeset
   139
    "return the signal which is raised on underflow conditions (in floats)"
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
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   143
345
claus
parents: 326
diff changeset
   144
unorderedSignal
claus
parents: 326
diff changeset
   145
    "return the signal which is raised when numbers are compared, 
claus
parents: 326
diff changeset
   146
     for which no ordering is defined (for example: complex numbers)"
claus
parents: 326
diff changeset
   147
3393
f07a758f8c69 oops - unorderedSignal did not
Claus Gittinger <cg@exept.de>
parents: 3134
diff changeset
   148
    ^ UnorderedSignal
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   149
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   150
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   151
!ArithmeticValue methodsFor:'arithmetic'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   152
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   153
* something
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   154
    "return the product of the receiver and the argument"
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
    ^ self subclassResponsibility
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   157
!
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
+ something
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   160
    "return the sum of the receiver and the argument"
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
    ^ self subclassResponsibility
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   163
!
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
- something
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   166
    "return the difference of the receiver and the argument"
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
    ^ self subclassResponsibility
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   169
!
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
/ something
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   172
    "return the quotient of the receiver and the argument"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   173
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   174
    ^ self subclassResponsibility
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   175
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   176
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   177
// something
1881
0c6ba2c134c1 fixed #rounded
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   178
    "return the integer quotient of dividing the receiver by aNumber with
0c6ba2c134c1 fixed #rounded
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   179
     truncation towards negative infinity."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   180
3982
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   181
    "/ Note: '^ (self / something) floor' may lead to infinite recursion
1172
b135d4ae4bf2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   182
b135d4ae4bf2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   183
    ^ self subclassResponsibility
b135d4ae4bf2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   184
3982
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   185
    "Modified: / 5.11.1996 / 11:46:27 / cg"
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   186
    "Modified: / 12.2.1998 / 16:31:36 / stefan"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   187
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   188
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   189
\\ something
3982
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   190
    "return the receiver modulo something.
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 5987
diff changeset
   191
     The remainder has the same sign as something.
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 5987
diff changeset
   192
     The following is always true:
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 5987
diff changeset
   193
        (receiver // something) * something + (receiver \\ something) = receiver
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 5987
diff changeset
   194
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   195
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   196
    ^ self - ((self // something) * something)
3134
22c7071ff004 Fix typo.
Stefan Vogel <sv@exept.de>
parents: 1888
diff changeset
   197
3982
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   198
   "
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   199
     0.9 \\ 0.4
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   200
     0.9 \\ -0.4
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   201
    -0.9 \\ 0.4
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   202
    -0.9 \\ -0.4
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   203
   "
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   204
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   205
    "Modified: / 12.2.1998 / 19:14:37 / stefan"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   206
!
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
abs
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   209
    "return the absolute value of the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   210
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   211
    (self negative) ifTrue:[^ self negated].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   212
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   213
!
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
negated
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   216
    "return the receiver negated"
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
    ^ self class zero - self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   219
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   220
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   221
quo:something
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   222
    "Return the integer quotient of dividing the receiver by the argument
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 5987
diff changeset
   223
     with truncation towards zero.
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 5987
diff changeset
   224
     The following is always true:
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 5987
diff changeset
   225
        (receiver quo: aNumber) * aNumber + (receiver rem: aNumber) = receiver
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 5987
diff changeset
   226
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   227
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   228
    ^ (self / something) truncated
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   229
!
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
reciprocal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   232
    "return the receivers reciprocal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   233
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   234
    ^ self class unity / self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   235
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   236
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   237
rem:something
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   238
    "Return the integer remainder of dividing the receiver by the argument
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   239
     with truncation towards zero.
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 5987
diff changeset
   240
     The remainder has the same sign as the receiver.
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 5987
diff changeset
   241
     The following is always true:
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 5987
diff changeset
   242
        (receiver quo: something) * something + (receiver rem: something) = receiver
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 5987
diff changeset
   243
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   244
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   245
    ^ self - ((self quo:something) * something)
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   246
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   247
5238
f7a816a660a3 categories
Claus Gittinger <cg@exept.de>
parents: 4995
diff changeset
   248
!ArithmeticValue methodsFor:'coercing & converting'!
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   249
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   250
coerce:aNumber
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   251
    "convert aNumber into an instance of the receivers class and return it."
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
    ^ self subclassResponsibility
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
generality
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   257
    "return a number giving the receivers generality, that number is
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   258
     used to convert one of the arguments in a mixed expression. 
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   259
     The generality has to be defined in subclasses,
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   260
     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
   261
     does not cut precision. For example, Integer has 40, Float has 80,
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   262
     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
   263
     be lost. The generality is used by ArithmeticValue>>retry:coercing:,
3982
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   264
     which converts the lower-precision number to the higher precision
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   265
     numbers class, when mixed-type arithmetic is performed."
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
    ^ self subclassResponsibility
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   268
3982
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   269
    "Modified: / 5.11.1996 / 15:05:30 / cg"
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   270
    "Modified: / 13.2.1998 / 15:36:01 / stefan"
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   271
!
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   272
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   273
retry:aSymbol coercing:aNumber
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   274
    "arithmetic represented by the binary operator, aSymbol,
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   275
     could not be performed with the receiver and the argument, aNumber, 
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   276
     because of the differences in representation.  
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   277
     Coerce either the receiver or the argument, depending on which has higher 
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   278
     generality, and try again.  
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   279
     If the operation is compare for same value (=), return false if
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   280
     the argument is not a Number. 
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   281
     If the generalities are the same, create an error message, since this
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   282
     means that a subclass has not been fully implemented."
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   283
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   284
    |hasGenerality myGenerality otherGenerality|
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   285
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   286
    hasGenerality := aNumber respondsTo:#generality.
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   287
    hasGenerality ifFalse:[
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   288
        (aSymbol == #=) ifTrue:[
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   289
            ^ false
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   290
        ].
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   291
        (aSymbol == #~=) ifTrue:[
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   292
            ^ true
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   293
        ].
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   294
        ^ self error:'retry:coercing: argument is not a number'.
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   295
    ].
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   296
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   297
    myGenerality := self generality.
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   298
    otherGenerality := aNumber generality.
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   299
    (myGenerality > otherGenerality) ifTrue:[
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   300
        ^ self perform:aSymbol with:(self coerce:aNumber)
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   301
    ].
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   302
    (myGenerality < otherGenerality) ifTrue:[
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   303
        ^ (aNumber coerce:self) perform:aSymbol with:aNumber
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   304
    ].
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   305
    self error:'retry:coercing: oops - same generality'
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   306
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   307
    "Modified: 5.11.1996 / 15:03:38 / cg"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   308
! !
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   309
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   310
!ArithmeticValue methodsFor:'comparing'!
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
< something
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   313
    "return true, if the argument is greater than the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   314
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   315
    ^ self subclassResponsibility
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   316
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   317
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   318
<= something
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   319
    "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
   320
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   321
    ^ (something < self) not
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   322
!
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
> something
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   325
    "return true, if the argument is less than the receiver"
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
    ^ something < self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   328
!
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
>= something
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   331
    "return true, if the argument is less or equal than the receiver"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   332
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   333
    ^ (self < something) not
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   334
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   335
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   336
compare:arg ifLess:lessBlock ifEqual:equalBlock ifGreater:greaterBlock
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   337
    "three-way compare - thanks to Self for this idea.
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   338
     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
   339
     comparison is expensive."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   340
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   341
    self < arg ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   342
	^ lessBlock value
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   343
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   344
    self = arg ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   345
	^ equalBlock value
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   346
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   347
    ^ greaterBlock value
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   348
! !
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
!ArithmeticValue methodsFor:'converting'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   351
3982
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   352
asDouble
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   353
    "ST80 compatibility: return our floats are the identical to ST80 doubles"
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   354
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   355
   ^ self asFloat
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   356
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   357
    "Created: / 13.2.1998 / 15:40:14 / stefan"
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   358
!
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   359
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   360
asFloat
a27a279701f8 Initial revision
claus
parents:
diff changeset
   361
    "return a float with same value"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   362
a27a279701f8 Initial revision
claus
parents:
diff changeset
   363
   ^ self subclassResponsibility
a27a279701f8 Initial revision
claus
parents:
diff changeset
   364
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   365
5986
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   366
asFloatD
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   367
    "return a double precision float with same value.
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   368
     Added for ANSI compatibility"
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   369
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   370
   ^ self asFloat
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   371
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   372
    "Created: / 7.9.2001 / 13:36:48 / cg"
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   373
    "Modified: / 7.9.2001 / 13:38:10 / cg"
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   374
!
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   375
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   376
asFloatE
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   377
    "return a single precision float with same value.
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   378
     Added for ANSI compatibility"
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   379
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   380
   ^ self asShortFloat
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   381
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   382
    "Created: / 7.9.2001 / 13:37:06 / cg"
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   383
    "Modified: / 7.9.2001 / 13:38:15 / cg"
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   384
!
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   385
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   386
asFloatQ
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   387
    "return a quad precision float with same value.
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   388
     Added for ANSI compatibility"
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   389
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   390
   ^ self asLongFloat
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   391
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   392
    "Created: / 7.9.2001 / 13:38:44 / cg"
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   393
!
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   394
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   395
asFraction
a27a279701f8 Initial revision
claus
parents:
diff changeset
   396
    "return a fraction with same value"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   397
a27a279701f8 Initial revision
claus
parents:
diff changeset
   398
   ^ self subclassResponsibility
a27a279701f8 Initial revision
claus
parents:
diff changeset
   399
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   400
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   401
asInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   402
    "return an integer with same value - might truncate"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   403
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   404
    ^ self truncated
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   405
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   406
5986
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   407
asLongFloat
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   408
    "return a longFloat with same value"
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   409
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   410
   ^ self subclassResponsibility
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   411
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   412
    "Modified: / 17.4.1996 / 12:21:35 / cg"
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   413
    "Created: / 7.9.2001 / 13:39:31 / cg"
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   414
!
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   415
5987
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   416
asScaledDecimal:scale
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   417
    "return a fixedPoint approximating the receivers value"
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   418
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   419
    ^ self asFixedPoint:scale
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   420
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   421
    "
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   422
     1.234 asScaledDecimal:2
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   423
    "
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   424
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   425
    "Created: / 7.9.2001 / 13:46:26 / cg"
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   426
    "Modified: / 7.9.2001 / 13:46:44 / cg"
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   427
!
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   428
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   429
asShortFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   430
    "return a shortFloat with same value"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   431
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   432
   ^ self asFloat asShortFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   433
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   434
    "Modified: 17.4.1996 / 12:21:35 / cg"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   435
!
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   436
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   437
degreesToRadians
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   438
    "interpreting the receiver as radians, return the degrees"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   439
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   440
    ^ self asFloat degreesToRadians
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   441
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   442
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   443
radiansToDegrees
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   444
    "interpreting the receiver as degrees, return the radians"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   445
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   446
    ^ self asFloat radiansToDegrees
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   447
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   448
4138
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   449
!ArithmeticValue methodsFor:'destructive arithmethic'!
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   450
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   451
*= aNumber
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   452
    "Return the product of self multiplied by aNumber. 
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   453
     Self MAY, but NEED NOT be changed to contain the product.
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   454
     So this method must be used: 'a := a *= 5'.
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   455
     This method can be redefined for constructed datatypes
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   456
     to do optimisations"
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   457
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   458
    ^ self * aNumber
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   459
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   460
    "Created: / 28.4.1999 / 11:46:11 / stefan"
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   461
    "Modified: / 28.4.1999 / 11:53:28 / stefan"
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   462
!
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   463
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   464
+= aNumber
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   465
    "Return the sum of self and aNumber. 
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   466
     Self MAY, but NEED NOT be changed to contain the product.
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   467
     So this method must be used: 'a := a += 5'.
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   468
     This method can be redefined for constructed datatypes
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   469
     to do optimisations"
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   470
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   471
    ^ self + aNumber
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   472
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   473
    "Created: / 28.4.1999 / 10:13:41 / stefan"
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   474
    "Modified: / 28.4.1999 / 11:54:11 / stefan"
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   475
!
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   476
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   477
-= aNumber
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   478
    "Return the difference of self and aNumber. 
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   479
     Self MAY, but NEED NOT be changed to contain the product.
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   480
     So this method must be used: 'a := a -= 5'.
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   481
     This method can be redefined for constructed datatypes
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   482
     to do optimisations"
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   483
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   484
    ^ self - aNumber
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   485
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   486
    "Created: / 28.4.1999 / 10:13:58 / stefan"
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   487
    "Modified: / 28.4.1999 / 11:54:37 / stefan"
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   488
!
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   489
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   490
/= aNumber
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   491
    "Return the quotient of self and aNumber. 
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   492
     Self MAY, but NEED NOT be changed to contain the product.
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   493
     So this method must be used: 'a := a /= 5'.
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   494
     This method can be redefined for constructed datatypes
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   495
     to do optimisations"
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   496
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   497
    ^ self / aNumber
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   498
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   499
    "Created: / 28.4.1999 / 11:46:22 / stefan"
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   500
    "Modified: / 28.4.1999 / 11:55:06 / stefan"
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   501
!
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   502
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   503
div2
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   504
    "Return the quotient of self divided by 2. 
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   505
     Self MAY, but NEED NOT be changed to contain the product.
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   506
     So this method must be used: 'a := a div2.
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   507
     This method can be redefined for constructed datatypes
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   508
     to do optimisations"
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   509
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   510
    ^ self // 2
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   511
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   512
    "Created: / 28.4.1999 / 10:12:44 / stefan"
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   513
    "Modified: / 28.4.1999 / 11:56:09 / stefan"
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   514
!
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   515
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   516
mul2
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   517
    "Return the product of self multiplied by 2. 
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   518
     Self MAY, but NEED NOT be changed to contain the product.
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   519
     So this method must be used: 'a := a mul2.
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   520
     This method can be redefined for constructed datatypes
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   521
     to do optimisations"
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   522
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   523
    ^ self * 2
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   524
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   525
    "Created: / 28.4.1999 / 10:12:55 / stefan"
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   526
    "Modified: / 28.4.1999 / 11:56:38 / stefan"
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   527
! !
c5030c520941 New methods for destructive arithmethics like +=, -= ...
Stefan Vogel <sv@exept.de>
parents: 3982
diff changeset
   528
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   529
!ArithmeticValue methodsFor:'double dispatching'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   530
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   531
differenceFromFixedPoint:aFixedPoint
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   532
    "the receiver does not know how to subtract from a fixedPoint 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:55:51 / 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
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   540
differenceFromFloat:aFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   541
    "the receiver does not know how to subtract from a float -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   542
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   543
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   544
    ^ aFloat retry:#- coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   545
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   546
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   547
differenceFromFraction:aFraction
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   548
    "the receiver does not know how to subtract from a fraction -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   549
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   550
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   551
    ^ aFraction retry:#- coercing:self
1
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
differenceFromInteger:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   555
    "the receiver does not know how to subtract from an integer -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   556
     retry the operation by coercing to higher generality"
1
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
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   559
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   560
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   561
differenceFromShortFloat:aShortFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   562
    "the receiver does not know how to subtract from 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:33:16 / cg"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   568
!
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   569
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   570
lessFromFixedPoint:aFixedPoint
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   571
    "the receiver does not know how to compare to a fixedPoint number -
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   572
     retry the operation by coercing to higher generality"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   573
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   574
    ^ aFixedPoint retry:#< coercing:self
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   575
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   576
    "Created: 5.11.1996 / 14:56:12 / cg"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   577
!
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   578
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   579
lessFromFloat:aFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   580
    "the receiver does not know how to compare to a float -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   581
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   582
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   583
    ^ aFloat retry:#< coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   584
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   585
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   586
lessFromFraction:aFraction
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   587
    "the receiver does not know how to compare to a fraction -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   588
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   589
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   590
    ^ aFraction retry:#< coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   591
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   592
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   593
lessFromInteger:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   594
    "the receiver does not know how to compare to an integer -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   595
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   596
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   597
    ^ anInteger retry:#< coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   598
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   599
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   600
lessFromShortFloat:aShortFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   601
    "the receiver does not know how to compare to a shortFloat -
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   602
     retry the operation by coercing to higher generality"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   603
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   604
    ^ aShortFloat retry:#< coercing:self
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   605
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   606
    "Modified: 17.4.1996 / 12:33:33 / cg"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   607
!
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   608
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   609
productFromFixedPoint:aFixedPoint
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   610
    "the receiver does not know how to multiply a fixed point number -
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   611
     retry the operation by coercing to higher generality"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   612
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   613
    ^ aFixedPoint retry:#* coercing:self
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   614
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   615
    "Created: 5.11.1996 / 14:56:28 / cg"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   616
!
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   617
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   618
productFromFloat:aFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   619
    "the receiver does not know how to multiply a float -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   620
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   621
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   622
    ^ aFloat retry:#* coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   623
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   624
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   625
productFromFraction:aFraction
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   626
    "the receiver does not know how to multiply a fraction -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   627
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   628
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   629
    ^ aFraction retry:#* coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   630
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   631
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   632
productFromInteger:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   633
    "the receiver does not know how to multiply an integer -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   634
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   635
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   636
    ^ anInteger retry:#* coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   637
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   638
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   639
productFromShortFloat:aShortFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   640
    "the receiver does not know how to multiply a shortFloat -
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   641
     retry the operation by coercing to higher generality"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   642
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   643
    ^ aShortFloat retry:#* coercing:self
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   644
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   645
    "Created: 17.4.1996 / 12:33:48 / cg"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   646
!
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   647
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   648
quotientFromFixedPoint:aFixedPoint
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   649
    "the receiver does not know how to divide a fixed point number -
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   650
     retry the operation by coercing to higher generality"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   651
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   652
    ^ aFixedPoint retry:#/ coercing:self
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   653
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   654
    "Created: 5.11.1996 / 14:56:41 / cg"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   655
!
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   656
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   657
quotientFromFloat:aFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   658
    "the receiver does not know how to divide a float -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   659
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   660
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   661
    ^ aFloat retry:#/ coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   662
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   663
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   664
quotientFromFraction:aFraction
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   665
    "the receiver does not know how to divide a fraction -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   666
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   667
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   668
    ^ aFraction retry:#/ coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   669
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   670
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   671
quotientFromInteger:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   672
    "the receiver does not know how to divide an integer -
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   673
     retry the operation by coercing to higher generality"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   674
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   675
    ^ anInteger retry:#/ coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   676
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   677
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   678
quotientFromShortFloat:aShortFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   679
    "the receiver does not know how to divide a shortFloat -
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   680
     retry the operation by coercing to higher generality"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   681
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   682
    ^ aShortFloat retry:#/ coercing:self
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   683
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   684
    "Created: 17.4.1996 / 12:34:00 / cg"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   685
!
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   686
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   687
sumFromFixedPoint:aFixedPoint
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   688
    "the receiver does not know how to add a fixed point number -
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   689
     retry the operation by coercing to higher generality"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   690
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   691
    ^ aFixedPoint retry:#+ coercing:self
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   692
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   693
    "Created: 5.11.1996 / 14:56:56 / cg"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   694
!
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   695
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   696
sumFromFloat:aFloat
a27a279701f8 Initial revision
claus
parents:
diff changeset
   697
    "the receiver does not know how to add a float -
a27a279701f8 Initial revision
claus
parents:
diff changeset
   698
     retry the operation by coercing to higher generality"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   699
a27a279701f8 Initial revision
claus
parents:
diff changeset
   700
    ^ aFloat retry:#+ coercing:self
a27a279701f8 Initial revision
claus
parents:
diff changeset
   701
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   702
a27a279701f8 Initial revision
claus
parents:
diff changeset
   703
sumFromFraction:aFraction
a27a279701f8 Initial revision
claus
parents:
diff changeset
   704
    "the receiver does not know how to add a fraction -
a27a279701f8 Initial revision
claus
parents:
diff changeset
   705
     retry the operation by coercing to higher generality"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   706
a27a279701f8 Initial revision
claus
parents:
diff changeset
   707
    ^ aFraction retry:#+ coercing:self
a27a279701f8 Initial revision
claus
parents:
diff changeset
   708
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   709
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   710
sumFromInteger:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   711
    "the receiver does not know how to add an integer -
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   712
     retry the operation by coercing to higher generality"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   713
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   714
    ^ anInteger retry:#+ coercing:self
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   715
!
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   716
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   717
sumFromShortFloat:aShortFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   718
    "the receiver does not know how to add a shortFloat -
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   719
     retry the operation by coercing to higher generality"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   720
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   721
    ^ aShortFloat retry:#+ coercing:self
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   722
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   723
    "Created: 17.4.1996 / 12:34:10 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   724
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   725
a27a279701f8 Initial revision
claus
parents:
diff changeset
   726
!ArithmeticValue methodsFor:'misc math'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   727
6858
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   728
** aNumber
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   729
    "return the receiver raised to aNumber"
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   730
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   731
    ^ self raisedTo:aNumber
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   732
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   733
    "
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   734
     2 ** 4    
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   735
     10 ** 4    
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   736
    "
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   737
!
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   738
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   739
exp
a27a279701f8 Initial revision
claus
parents:
diff changeset
   740
    "return e ^ receiver"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   741
a27a279701f8 Initial revision
claus
parents:
diff changeset
   742
    ^ self asFloat exp
a27a279701f8 Initial revision
claus
parents:
diff changeset
   743
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   744
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   745
floorLog:radix
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   746
    "return the logarithm truncated as an integer"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   747
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   748
    ^ (self log:radix) floor
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   749
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   750
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   751
ln
a27a279701f8 Initial revision
claus
parents:
diff changeset
   752
    "return the natural logarithm of the receiver"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   753
a27a279701f8 Initial revision
claus
parents:
diff changeset
   754
    ^ self asFloat ln
a27a279701f8 Initial revision
claus
parents:
diff changeset
   755
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   756
a27a279701f8 Initial revision
claus
parents:
diff changeset
   757
log
a27a279701f8 Initial revision
claus
parents:
diff changeset
   758
    "return log base 10 of the receiver"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   759
a27a279701f8 Initial revision
claus
parents:
diff changeset
   760
    ^ self log:10
a27a279701f8 Initial revision
claus
parents:
diff changeset
   761
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   762
a27a279701f8 Initial revision
claus
parents:
diff changeset
   763
log:aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   764
    "return log base aNumber of the receiver"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   765
a27a279701f8 Initial revision
claus
parents:
diff changeset
   766
    ^ self ln / aNumber ln
a27a279701f8 Initial revision
claus
parents:
diff changeset
   767
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   768
a27a279701f8 Initial revision
claus
parents:
diff changeset
   769
raisedTo:aNumber
a27a279701f8 Initial revision
claus
parents:
diff changeset
   770
    "return the receiver raised to aNumber"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   771
a27a279701f8 Initial revision
claus
parents:
diff changeset
   772
    aNumber = 0 ifTrue:[^ 1].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   773
    aNumber = 1 ifTrue:[^ self].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   774
    aNumber isInteger ifTrue:[
6858
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   775
        ^ self raisedToInteger:aNumber
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   776
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   777
    ^ self asFloat raisedTo:aNumber
6858
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   778
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   779
    "
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   780
     2 raisedTo: 4    
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   781
     10 raisedTo: 4    
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   782
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   783
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   784
6858
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   785
raisedToInteger:exp 
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   786
    "return the receiver raised to exp"
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   787
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   788
    |result e t 
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   789
    |
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   790
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   791
    "use the addition chaining algorithm"
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   792
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   793
    result := 1.
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   794
    t := self.
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   795
    exp < 0 ifTrue:[
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   796
        e := exp negated.
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   797
    ] ifFalse:[
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   798
        e := exp.
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   799
    ].
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   800
6858
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   801
    [e ~~ 0] whileTrue:[
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   802
        [(e bitAnd:1) == 0] whileTrue:[
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   803
            e := e bitShift:-1.
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   804
            t := t * t.
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   805
        ].
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   806
        e := e - 1.
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   807
        result := result * t.
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   808
    ].
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   809
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   810
    (exp < 0) ifTrue:[
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   811
        ^ 1 / result
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   812
    ].
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   813
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   814
    ^ result
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   815
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   816
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   817
    "
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   818
     (2 raisedToInteger:216)
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   819
     (2 raisedTo:216) 
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   820
-> 105312291668557186697918027683670432318895095400549111254310977536     
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   821
6858
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   822
     (2 raisedToInteger:216) asFloat     
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   823
     (2 raisedTo:216) asFloat     
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   824
-> 1.05312E+65
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   825
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   826
     (2 raisedToInteger:500)
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   827
     (2 raisedTo:500) 
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   828
-> 3273390607896141870013189696827599152216642046043064789483291368096133796404674554883270092325904157150886684127560071009217256545885393053328527589376
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   829
     2 raisedToInteger:10 
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   830
-> 1024
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   831
    -2 raisedToInteger:10
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   832
-> 1024
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   833
     -2 raisedToInteger:9
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   834
-> -512
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   835
     10 raisedToInteger:-10
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   836
-> (1/10000000000)
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   837
     2 raisedToInteger:0 
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   838
-> 1
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   839
     2 raisedToInteger:-1 
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   840
-> (1/2)
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   841
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   842
     Time millisecondsToRun:[
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   843
        10000 timesRepeat:[
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   844
            (2 raisedToInteger:500)
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   845
        ]
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   846
     ]  
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   847
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   848
     Time millisecondsToRun:[
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   849
        |bigNum|
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   850
        bigNum := 2 raisedToInteger:500.
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   851
        10 timesRepeat:[
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   852
            (bigNum raisedToInteger:500)
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   853
        ]
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   854
     ]
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   855
    "
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   856
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   857
    "Created: / 27.4.1999 / 15:19:22 / stefan"
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
   858
    "Modified: / 27.4.1999 / 16:16:11 / stefan"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   859
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   860
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   861
sqrt
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   862
    "return the square root of the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   863
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   864
    ^ self asFloat sqrt
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   865
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   866
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   867
squared
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   868
    "return receiver * receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   869
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   870
    ^ self * self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   871
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   872
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   873
!ArithmeticValue methodsFor:'queries'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   874
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   875
respondsToArithmetic
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   876
    "return true, if the receiver responds to arithmetic messages"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   877
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   878
    ^ true
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   879
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   880
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   881
!ArithmeticValue methodsFor:'testing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   882
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   883
denominator
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   884
    "return the denominator of the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   885
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   886
    ^ 1
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   887
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   888
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   889
even
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   890
    "return true if the receiver is divisible by 2"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   891
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   892
    ^ self truncated asInteger even
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   893
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   894
3635
3fcccef48db3 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3393
diff changeset
   895
isComplex
3fcccef48db3 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3393
diff changeset
   896
    "Answer whether the receiver has an imaginary part"
3fcccef48db3 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3393
diff changeset
   897
3fcccef48db3 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3393
diff changeset
   898
    ^ false
3fcccef48db3 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3393
diff changeset
   899
3fcccef48db3 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3393
diff changeset
   900
    "Modified: / 9.7.1998 / 10:19:27 / cg"
3fcccef48db3 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3393
diff changeset
   901
!
3fcccef48db3 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3393
diff changeset
   902
6156
ff2df95a69bf isReal moved
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
   903
isReal
ff2df95a69bf isReal moved
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
   904
    "return true, if the receiver is some kind of real number (as opposed to a complex);
ff2df95a69bf isReal moved
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
   905
     false is returned here - the method is only redefined in Number (and Complex)."
ff2df95a69bf isReal moved
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
   906
ff2df95a69bf isReal moved
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
   907
    ^ false
ff2df95a69bf isReal moved
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
   908
ff2df95a69bf isReal moved
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
   909
    "Modified: / 6.11.2001 / 13:20:20 / cg"
ff2df95a69bf isReal moved
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
   910
    "Created: / 6.11.2001 / 13:26:29 / cg"
ff2df95a69bf isReal moved
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
   911
!
ff2df95a69bf isReal moved
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
   912
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   913
negative
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   914
    "return true, if the receiver is < 0"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   915
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   916
    " this would lead to infinite recursion ...
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   917
    ^ (self < 0)
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   918
    "
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   919
    ^ self subclassResponsibility
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   920
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   921
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   922
numerator
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   923
    "return the numerator of the receiver."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   924
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   925
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   926
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   927
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   928
odd
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   929
    "return true if the receiver is not divisible by 2"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   930
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   931
    ^ self even not
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   932
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   933
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   934
positive
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   935
    "return true, if the receiver is >= 0"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   936
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   937
    ^ self negative not
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   938
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   939
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   940
sign
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   941
    "return the sign of the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   942
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   943
    (self < 0) ifTrue:[^ -1].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   944
    (self > 0) ifTrue:[^ 1].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   945
    ^ 0
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   946
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   947
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   948
strictlyPositive
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   949
    "return true, if the receiver is > 0"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   950
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   951
    ^ (self > 0)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   952
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   953
a27a279701f8 Initial revision
claus
parents:
diff changeset
   954
!ArithmeticValue methodsFor:'trigonometric'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   955
a27a279701f8 Initial revision
claus
parents:
diff changeset
   956
arcCos
a27a279701f8 Initial revision
claus
parents:
diff changeset
   957
    "return the arccosine of the receiver (in radians)"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   958
a27a279701f8 Initial revision
claus
parents:
diff changeset
   959
    ^ self asFloat arcCos
a27a279701f8 Initial revision
claus
parents:
diff changeset
   960
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   961
a27a279701f8 Initial revision
claus
parents:
diff changeset
   962
arcSin
a27a279701f8 Initial revision
claus
parents:
diff changeset
   963
    "return the arcsine of the receiver (in radians)"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   964
a27a279701f8 Initial revision
claus
parents:
diff changeset
   965
    ^ self asFloat arcSin
a27a279701f8 Initial revision
claus
parents:
diff changeset
   966
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   967
a27a279701f8 Initial revision
claus
parents:
diff changeset
   968
arcTan
a27a279701f8 Initial revision
claus
parents:
diff changeset
   969
    "return the arctangens of the receiver (in radians)"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   970
a27a279701f8 Initial revision
claus
parents:
diff changeset
   971
    ^ self asFloat arcTan
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   972
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   973
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   974
cos
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   975
    "return the cosine of the receiver (interpreted as radians)"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   976
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   977
    ^ self asFloat cos
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   978
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   979
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   980
sin
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   981
    "return the sine of the receiver (interpreted as radians)"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   982
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   983
    ^ self asFloat sin
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   984
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   985
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   986
tan
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   987
    "return the tangens of the receiver (interpreted as radians)"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   988
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   989
    ^ self asFloat tan
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   990
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   991
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   992
!ArithmeticValue methodsFor:'truncation & rounding'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   993
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   994
ceiling
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   995
    "return the integer nearest the receiver towards positive infinity."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   996
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   997
    |anInteger|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   998
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   999
    anInteger := self // 1.       "truncates towards negative infinity"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1000
    anInteger = self ifTrue:[^ anInteger].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1001
    ^ anInteger + 1
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1002
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1003
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1004
floor
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1005
    "return the receiver truncated towards negative infinity"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1006
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1007
    ^ self // 1
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1008
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1009
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1010
roundTo:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1011
    "return the receiver rounded to multiples of aNumber"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1012
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1013
    ^ (self / aNumber) rounded * aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1014
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1015
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1016
rounded
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1017
    "return the integer nearest the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1018
1881
0c6ba2c134c1 fixed #rounded
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1019
    self negative ifTrue:[
0c6ba2c134c1 fixed #rounded
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1020
        ^ (self - 0.5) ceiling
0c6ba2c134c1 fixed #rounded
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1021
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1022
    ^ (self + 0.5) floor
1881
0c6ba2c134c1 fixed #rounded
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1023
0c6ba2c134c1 fixed #rounded
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1024
    "Modified: 5.11.1996 / 11:31:59 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1025
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1026
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1027
truncateTo:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1028
    "return the receiver truncated to multiples of aNumber"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1029
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1030
    ^ ((self / aNumber) floor * aNumber) asInteger
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1031
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1032
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1033
truncated
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1034
    "return the receiver truncated towards zero"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1035
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1036
    self negative ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1037
	^ self ceiling
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1038
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1039
    ^ self floor
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1040
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1041
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1042
!ArithmeticValue class methodsFor:'documentation'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1043
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1044
version
7142
7a6297c86ef4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6858
diff changeset
  1045
    ^ '$Header: /cvs/stx/stx/libbasic/ArithmeticValue.st,v 1.45 2003-03-31 09:53:22 cg Exp $'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1046
! !
6858
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
  1047
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1048
ArithmeticValue initialize!