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