ArithmeticValue.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Tue, 22 Sep 2015 16:28:42 +0100
branchjv
changeset 18759 c1217211909c
parent 18120 e3a375d5f6a8
child 18858 2968df243134
permissions -rw-r--r--
Changed identification strings to contain jv-branch ...to make explicit that this distribution is not the official one used by eXept and therefore that eXept is not to be blamed in case of any problem.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17662
0fd098ccf3ff class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 17336
diff changeset
     1
"{ Encoding: utf8 }"
0fd098ccf3ff class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 17336
diff changeset
     2
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     3
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
 COPYRIGHT (c) 1993 by Claus Gittinger
213
3b56a17534fd *** empty log message ***
claus
parents: 155
diff changeset
     5
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
"
5948
1fc30f692713 new class based exceptions
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
    14
"{ Package: 'stx:libbasic' }"
1fc30f692713 new class based exceptions
Claus Gittinger <cg@exept.de>
parents: 5238
diff changeset
    15
17336
3cfe5fb7201c class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 17223
diff changeset
    16
"{ NameSpace: Smalltalk }"
3cfe5fb7201c class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 17223
diff changeset
    17
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    18
Magnitude subclass:#ArithmeticValue
1172
b135d4ae4bf2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    19
	instanceVariableNames:''
b135d4ae4bf2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    20
	classVariableNames:'DivisionByZeroSignal DomainErrorSignal OverflowSignal
6342
fbbe62d5b17c Remove obsolete (since years) AnyArithmeticSignal definitions.
Stefan Vogel <sv@exept.de>
parents: 6156
diff changeset
    21
		UnderflowSignal ArithmeticSignal UnorderedSignal
fbbe62d5b17c Remove obsolete (since years) AnyArithmeticSignal definitions.
Stefan Vogel <sv@exept.de>
parents: 6156
diff changeset
    22
		ConversionErrorSignal'
1172
b135d4ae4bf2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    23
	poolDictionaries:''
b135d4ae4bf2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
    24
	category:'Magnitude-Numbers'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    25
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    26
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    27
!ArithmeticValue class methodsFor:'documentation'!
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    28
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    29
copyright
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    30
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    31
 COPYRIGHT (c) 1993 by Claus Gittinger
213
3b56a17534fd *** empty log message ***
claus
parents: 155
diff changeset
    32
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    33
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    34
 This software is furnished under a license and may be used
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    35
 only in accordance with the terms of that license and with the
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    36
 inclusion of the above copyright notice.   This software may not
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    37
 be provided or otherwise made available to, or used by, any
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    38
 other person.  No title to or ownership of the software is
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    39
 hereby transferred.
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    40
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    41
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    42
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    43
documentation
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    44
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    45
    ArithmeticValue is an abstract superclass for all things responding to
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
    46
    arithmetic messages. It was inserted into the hierarchy, to allow objects
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
    47
    like matrices, functions etc. to share the arithmetic methods defined here.
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
    48
5955
4d973d840a00 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    49
    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
    50
    variables and signal accessors remain here for backward compatibility.
4d973d840a00 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
    51
1283
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    52
    [class variables:]
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
    53
	ArithmeticSignal        <Error>         parent of all arithmetic signals
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
    54
						(never raised itself)
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
    55
						New: now a reference to ArithmeticError
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    56
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
    57
	DomainErrorSignal       <Error>         raised upon float errors
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
    58
						(for example range in trigonometric)
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
    59
						New: now a reference to DomainError
1283
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    60
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
    61
	DivisionByZeroSignal    <Error>         raised when division by 0 is attempted
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
    62
						New: now a reference to ZeroDivide
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
    63
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
    64
	OverflowSignal          <Error>         raised on overflow/underflow conditions
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
    65
	UnderflowSignal                         in float arithmetic.
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
    66
						Notice: some OperatingSystems do not
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
    67
						provide enough information for ST/X to
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
    68
						extract the real reason for the floatException
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
    69
						thus raising DomainErrorSignal in these cases.
155
edd7fc34e104 *** empty log message ***
claus
parents: 92
diff changeset
    70
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1283
diff changeset
    71
    [author:]
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
    72
	Claus Gittinger
1295
83f594f05c52 documentation
Claus Gittinger <cg@exept.de>
parents: 1283
diff changeset
    73
1283
2c533653efa3 commentary
Claus Gittinger <cg@exept.de>
parents: 1210
diff changeset
    74
    [See also:]
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
    75
	Number
82
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    76
"
0147b4f725ae *** empty log message ***
claus
parents: 77
diff changeset
    77
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    78
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    79
!ArithmeticValue class methodsFor:'Signal constants'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    80
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    81
arithmeticSignal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    82
    "return the parent of all arithmetic signals"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    83
7403
857702a5a921 signals vs. errors
Claus Gittinger <cg@exept.de>
parents: 7399
diff changeset
    84
    ^ ArithmeticError
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    85
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    86
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    87
divisionByZeroSignal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    88
    "return the signal which is raised on division by zero"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    89
7403
857702a5a921 signals vs. errors
Claus Gittinger <cg@exept.de>
parents: 7399
diff changeset
    90
    ^ ZeroDivide
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
    91
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    92
a27a279701f8 Initial revision
claus
parents:
diff changeset
    93
domainErrorSignal
a27a279701f8 Initial revision
claus
parents:
diff changeset
    94
    "return the signal which is raised on math errors
a27a279701f8 Initial revision
claus
parents:
diff changeset
    95
     (such as log of 0 etc.)"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    96
7403
857702a5a921 signals vs. errors
Claus Gittinger <cg@exept.de>
parents: 7399
diff changeset
    97
    ^ DomainError
857702a5a921 signals vs. errors
Claus Gittinger <cg@exept.de>
parents: 7399
diff changeset
    98
!
857702a5a921 signals vs. errors
Claus Gittinger <cg@exept.de>
parents: 7399
diff changeset
    99
857702a5a921 signals vs. errors
Claus Gittinger <cg@exept.de>
parents: 7399
diff changeset
   100
imaginaryResultSignal
857702a5a921 signals vs. errors
Claus Gittinger <cg@exept.de>
parents: 7399
diff changeset
   101
    "return the signal which is raised when an imaginary result would be created
857702a5a921 signals vs. errors
Claus Gittinger <cg@exept.de>
parents: 7399
diff changeset
   102
     (such as when taking the sqrt of a negative number)"
857702a5a921 signals vs. errors
Claus Gittinger <cg@exept.de>
parents: 7399
diff changeset
   103
857702a5a921 signals vs. errors
Claus Gittinger <cg@exept.de>
parents: 7399
diff changeset
   104
    ^ ImaginaryResultError
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   105
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   106
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   107
operationNotPossibleSignal
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   108
    ^ Error
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   109
!
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   110
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   111
overflowSignal
a27a279701f8 Initial revision
claus
parents:
diff changeset
   112
    "return the signal which is raised on overflow conditions (in floats)"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   113
7403
857702a5a921 signals vs. errors
Claus Gittinger <cg@exept.de>
parents: 7399
diff changeset
   114
    ^ OverflowError
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   115
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   116
5955
4d973d840a00 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   117
rangeErrorSignal
4d973d840a00 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   118
    "return the parent of the overflow/underflow signals"
4d973d840a00 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   119
4d973d840a00 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   120
    ^ RangeError
4d973d840a00 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   121
!
4d973d840a00 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5954
diff changeset
   122
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   123
undefinedResultSignal
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   124
    ^ Error
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   125
!
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   126
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   127
underflowSignal
a27a279701f8 Initial revision
claus
parents:
diff changeset
   128
    "return the signal which is raised on underflow conditions (in floats)"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   129
7403
857702a5a921 signals vs. errors
Claus Gittinger <cg@exept.de>
parents: 7399
diff changeset
   130
    ^ UnderflowError
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   131
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   132
345
claus
parents: 326
diff changeset
   133
unorderedSignal
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   134
    "return the signal which is raised when numbers are compared,
345
claus
parents: 326
diff changeset
   135
     for which no ordering is defined (for example: complex numbers)"
claus
parents: 326
diff changeset
   136
7403
857702a5a921 signals vs. errors
Claus Gittinger <cg@exept.de>
parents: 7399
diff changeset
   137
    ^ UnorderedNumbersError
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   138
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   139
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   140
!ArithmeticValue class methodsFor:'class initialization'!
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   141
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   142
initialize
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   143
    "setup the signals"
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   144
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   145
    "/ notice that we now use class based exceptions;
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   146
    "/ however, for backward compatibility, the class variables
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   147
    "/ referring to those are kept for a while, for subclass compatibility.
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   148
    "/ Please convert your code to access those via the Signal-constants class
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   149
    "/ messages (accesors) instead of referring to the class variables.
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   150
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   151
    ArithmeticSignal := ArithmeticError.
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   152
    DomainErrorSignal := DomainError.
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   153
    DivisionByZeroSignal := ZeroDivide.
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   154
    UnorderedSignal := UnorderedNumbersError.
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   155
    ConversionErrorSignal := ConversionError.
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   156
    OverflowSignal := OverflowError.
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   157
    UnderflowSignal := UnderflowError.
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   158
! !
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   159
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   160
!ArithmeticValue class methodsFor:'constants'!
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   161
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   162
NaN
8850
b9a04c753bfa comments
Claus Gittinger <cg@exept.de>
parents: 8757
diff changeset
   163
    "return the constant NaN (not a Number)."
b9a04c753bfa comments
Claus Gittinger <cg@exept.de>
parents: 8757
diff changeset
   164
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   165
    ^ NotANumber new
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   166
!
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   167
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   168
infinity
8850
b9a04c753bfa comments
Claus Gittinger <cg@exept.de>
parents: 8757
diff changeset
   169
    "return something which represents infinity (for my instances)"
b9a04c753bfa comments
Claus Gittinger <cg@exept.de>
parents: 8757
diff changeset
   170
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   171
    ^ Infinity positive
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   172
!
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   173
7538
dd0131e05cf0 Define #nan for VW-compatibility
Stefan Vogel <sv@exept.de>
parents: 7471
diff changeset
   174
nan
dd0131e05cf0 Define #nan for VW-compatibility
Stefan Vogel <sv@exept.de>
parents: 7471
diff changeset
   175
    "VW compatibility"
dd0131e05cf0 Define #nan for VW-compatibility
Stefan Vogel <sv@exept.de>
parents: 7471
diff changeset
   176
dd0131e05cf0 Define #nan for VW-compatibility
Stefan Vogel <sv@exept.de>
parents: 7471
diff changeset
   177
    ^ self NaN
dd0131e05cf0 Define #nan for VW-compatibility
Stefan Vogel <sv@exept.de>
parents: 7471
diff changeset
   178
!
dd0131e05cf0 Define #nan for VW-compatibility
Stefan Vogel <sv@exept.de>
parents: 7471
diff changeset
   179
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   180
negativeInfinity
8850
b9a04c753bfa comments
Claus Gittinger <cg@exept.de>
parents: 8757
diff changeset
   181
    "return something which represents negative infinity (for my instances)"
b9a04c753bfa comments
Claus Gittinger <cg@exept.de>
parents: 8757
diff changeset
   182
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   183
    ^ Infinity negative
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   184
!
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   185
7726
a3bb3ae6c02e Define #unity
Stefan Vogel <sv@exept.de>
parents: 7635
diff changeset
   186
unity
11467
f2bdc4080cac comments
Claus Gittinger <cg@exept.de>
parents: 11227
diff changeset
   187
    "return something which represents the unity element (for my instances).
f2bdc4080cac comments
Claus Gittinger <cg@exept.de>
parents: 11227
diff changeset
   188
     That is the neutral element for multiplication."
8850
b9a04c753bfa comments
Claus Gittinger <cg@exept.de>
parents: 8757
diff changeset
   189
7726
a3bb3ae6c02e Define #unity
Stefan Vogel <sv@exept.de>
parents: 7635
diff changeset
   190
    self subclassResponsibility
a3bb3ae6c02e Define #unity
Stefan Vogel <sv@exept.de>
parents: 7635
diff changeset
   191
!
a3bb3ae6c02e Define #unity
Stefan Vogel <sv@exept.de>
parents: 7635
diff changeset
   192
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   193
zero
11467
f2bdc4080cac comments
Claus Gittinger <cg@exept.de>
parents: 11227
diff changeset
   194
    "return something which represents the zero element (for my instances).
f2bdc4080cac comments
Claus Gittinger <cg@exept.de>
parents: 11227
diff changeset
   195
     That is the neutral element for addition."
8850
b9a04c753bfa comments
Claus Gittinger <cg@exept.de>
parents: 8757
diff changeset
   196
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   197
    self subclassResponsibility
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   198
! !
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   199
17223
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   200
!ArithmeticValue class methodsFor:'error reporting'!
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   201
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   202
raise:aSignalSymbolOrErrorClass receiver:someNumber selector:sel arguments:argArray errorString:text 
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   203
    "ST-80 compatible signal raising. Provided for PD numeric classes.
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   204
     aSignalSymbolOrErrorClass is either an Error-subclass, or
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   205
     the selector which is sent to myself, to retrieve the Exception class / Signal."
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   206
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   207
    <context: #return>
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   208
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   209
    |msg signalOrException|
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   210
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   211
    msg := MessageSend
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   212
                receiver:someNumber
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   213
                selector:sel
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   214
                arguments:argArray.
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   215
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   216
    aSignalSymbolOrErrorClass isSymbol ifTrue:[
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   217
        signalOrException := self perform:aSignalSymbolOrErrorClass.
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   218
    ] ifFalse:[
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   219
        signalOrException := aSignalSymbolOrErrorClass.    "/ assume its an Error-Subclass
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   220
    ].
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   221
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   222
    ^ signalOrException
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   223
         raiseRequestWith:msg 
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   224
         errorString:text 
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   225
         in:thisContext sender
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   226
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   227
    "
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   228
     Number 
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   229
        raise:#domainErrorSignal
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   230
        receiver:1.0
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   231
        selector:#foo 
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   232
        errorString:'foo bar test'
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   233
    "
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   234
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   235
    "Modified: / 16.11.2001 / 14:12:09 / cg"
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   236
! !
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
   237
8892
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8850
diff changeset
   238
!ArithmeticValue class methodsFor:'queries'!
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8850
diff changeset
   239
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8850
diff changeset
   240
isAbstract
11227
c4f57b8aca5a comment
Claus Gittinger <cg@exept.de>
parents: 11133
diff changeset
   241
    "Return if this class is an abstract class.
c4f57b8aca5a comment
Claus Gittinger <cg@exept.de>
parents: 11133
diff changeset
   242
     True is returned for ArithmeticValue here; false for subclasses.
c4f57b8aca5a comment
Claus Gittinger <cg@exept.de>
parents: 11133
diff changeset
   243
     Abstract subclasses must redefine again."
c4f57b8aca5a comment
Claus Gittinger <cg@exept.de>
parents: 11133
diff changeset
   244
8892
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8850
diff changeset
   245
    ^ self == ArithmeticValue
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8850
diff changeset
   246
! !
5d05a7f150a5 +isAbstract
Claus Gittinger <cg@exept.de>
parents: 8850
diff changeset
   247
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   248
!ArithmeticValue methodsFor:'arithmetic'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   249
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   250
* something
11735
60aa644effbe comment
Claus Gittinger <cg@exept.de>
parents: 11725
diff changeset
   251
    "return the product of the receiver and the argument."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   252
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   253
    ^ self subclassResponsibility
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   254
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   255
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   256
+ something
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   257
    "return the sum of the receiver and the argument"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   258
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   259
    ^ self subclassResponsibility
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   260
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   261
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   262
- something
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   263
    "return the difference of the receiver and the argument"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   264
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   265
    ^ self subclassResponsibility
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
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   268
/ something
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   269
    "return the quotient of the receiver and the argument"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   270
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   271
    ^ self subclassResponsibility
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   272
!
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
// something
1881
0c6ba2c134c1 fixed #rounded
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   275
    "return the integer quotient of dividing the receiver by aNumber with
0c6ba2c134c1 fixed #rounded
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
   276
     truncation towards negative infinity."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   277
3982
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   278
    "/ Note: '^ (self / something) floor' may lead to infinite recursion
1172
b135d4ae4bf2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   279
b135d4ae4bf2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   280
    ^ self subclassResponsibility
b135d4ae4bf2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 701
diff changeset
   281
3982
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   282
    "Modified: / 5.11.1996 / 11:46:27 / cg"
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   283
    "Modified: / 12.2.1998 / 16:31:36 / stefan"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   284
!
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
\\ something
3982
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   287
    "return the receiver modulo something.
17038
e5e3568f805e class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 16657
diff changeset
   288
     The remainder has the same sign as the argument, something.
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 5987
diff changeset
   289
     The following is always true:
17038
e5e3568f805e class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 16657
diff changeset
   290
        (receiver // something) * something + (receiver \\ something) = receiver
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 5987
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
    ^ self - ((self // something) * something)
3134
22c7071ff004 Fix typo.
Stefan Vogel <sv@exept.de>
parents: 1888
diff changeset
   294
3982
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   295
   "
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   296
     0.9 \\ 0.4
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   297
     0.9 \\ -0.4
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   298
    -0.9 \\ 0.4
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   299
    -0.9 \\ -0.4
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   300
   "
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   301
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   302
    "Modified: / 12.2.1998 / 19:14:37 / stefan"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   303
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   304
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   305
abs
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   306
    "return the absolute value of the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   307
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   308
    (self negative) ifTrue:[^ self negated].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   309
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   310
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   311
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   312
dist:arg
8757
Claus Gittinger <cg@exept.de>
parents: 8633
diff changeset
   313
    "return the distance between arg and the receiver."
Claus Gittinger <cg@exept.de>
parents: 8633
diff changeset
   314
Claus Gittinger <cg@exept.de>
parents: 8633
diff changeset
   315
    ^ (arg - self) abs
Claus Gittinger <cg@exept.de>
parents: 8633
diff changeset
   316
Claus Gittinger <cg@exept.de>
parents: 8633
diff changeset
   317
    "
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   318
     (1%1) dist:(0%0)
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   319
     (1@1) dist:(0@0)
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   320
     (1) dist:(0)
8757
Claus Gittinger <cg@exept.de>
parents: 8633
diff changeset
   321
    "
Claus Gittinger <cg@exept.de>
parents: 8633
diff changeset
   322
!
Claus Gittinger <cg@exept.de>
parents: 8633
diff changeset
   323
16121
7b441c381015 class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 15279
diff changeset
   324
modulusOf:aNumber
7b441c381015 class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 15279
diff changeset
   325
    "return aNumber modulo the reciever.
7b441c381015 class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 15279
diff changeset
   326
     The remainder has the same sign as something.
7b441c381015 class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 15279
diff changeset
   327
     Defined for protocol compatibility with ModuloNumber."
7b441c381015 class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 15279
diff changeset
   328
7b441c381015 class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 15279
diff changeset
   329
    ^ aNumber \\ self
7b441c381015 class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 15279
diff changeset
   330
!
7b441c381015 class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 15279
diff changeset
   331
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   332
negated
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   333
    "return the receiver negated"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   334
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   335
    ^ self class zero - self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   336
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   337
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   338
quo:something
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   339
    "Return the integer quotient of dividing the receiver by the argument
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 5987
diff changeset
   340
     with truncation towards zero.
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 5987
diff changeset
   341
     The following is always true:
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   342
	(receiver quo: aNumber) * aNumber + (receiver rem: aNumber) = receiver
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 5987
diff changeset
   343
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   344
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   345
    ^ (self / something) truncated
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   346
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   347
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   348
reciprocal
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   349
    "return the receivers reciprocal"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   350
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   351
    ^ self class unity / self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   352
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   353
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   354
rem:something
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   355
    "Return the integer remainder of dividing the receiver by the argument
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   356
     with truncation towards zero.
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 5987
diff changeset
   357
     The remainder has the same sign as the receiver.
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 5987
diff changeset
   358
     The following is always true:
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   359
	(receiver quo: something) * something + (receiver rem: something) = receiver
6067
e4c03d14a5de comment
Claus Gittinger <cg@exept.de>
parents: 5987
diff changeset
   360
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   361
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   362
    ^ self - ((self quo:something) * something)
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   363
!
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   364
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   365
uncheckedDivide:aNumber
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   366
    "return the quotient of the receiver and the argument, aNumber.
7471
c5d4bd612d9f comments
Claus Gittinger <cg@exept.de>
parents: 7468
diff changeset
   367
     Do not check for divide by zero (return NaN or Infinity).
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   368
     This operation is provided for emulators of other languages/semantics,
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   369
     where no exception is raised for these results (i.e. Java).
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   370
     Its only defined if the arguments type is the same as the receivers."
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   371
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   372
    aNumber isZero ifTrue:[
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   373
	self isZero ifTrue:[^ self class NaN].
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   374
	self negative ifTrue:[^ self class negativeInfinity].
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   375
	^ self class infinity.
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   376
    ].
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   377
    ^ self / aNumber
701
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
12578
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   380
!ArithmeticValue methodsFor:'arithmetic destructive'!
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   381
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   382
*= aNumber
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   383
    "Return the product of self multiplied by aNumber.
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   384
     The receiver MAY, but NEED NOT be changed to contain the product.
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   385
     So this method must be used as: 'a := a *= 5'.
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   386
     This method can be redefined for constructed datatypes to do optimisations"
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   387
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   388
    ^ self * aNumber
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   389
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   390
    "Created: / 28.4.1999 / 11:46:11 / stefan"
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   391
    "Modified: / 28.4.1999 / 11:53:28 / stefan"
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   392
!
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   393
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   394
+= aNumber
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   395
    "Return the sum of self and aNumber.
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   396
     The receiver MAY, but NEED NOT be changed to contain the sum.
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   397
     So this method must be used as: 'a := a += 5'.
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   398
     This method can be redefined for constructed datatypes to do optimisations"
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   399
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   400
    ^ self + aNumber
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   401
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   402
    "Created: / 28.4.1999 / 10:13:41 / stefan"
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   403
    "Modified: / 28.4.1999 / 11:54:11 / stefan"
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   404
!
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   405
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   406
-= aNumber
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   407
    "Return the difference of self and aNumber.
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   408
     The receiver MAY, but NEED NOT be changed to contain the difference.
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   409
     So this method must be used as: 'a := a -= 5'.
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   410
     This method can be redefined for constructed datatypes to do optimisations"
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   411
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   412
    ^ self - aNumber
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   413
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   414
    "Created: / 28.4.1999 / 10:13:58 / stefan"
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   415
    "Modified: / 28.4.1999 / 11:54:37 / stefan"
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   416
!
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   417
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   418
/= aNumber
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   419
    "Return the quotient of self and aNumber.
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   420
     The receiver MAY, but NEED NOT be changed to contain the quotient.
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   421
     So this method must be used as: 'a := a /= 5'.
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   422
     This method can be redefined for constructed datatypes to do optimisations"
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   423
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   424
    ^ self / aNumber
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   425
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   426
    "Created: / 28.4.1999 / 11:46:22 / stefan"
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   427
    "Modified: / 28.4.1999 / 11:55:06 / stefan"
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   428
!
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   429
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   430
div2
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   431
    "Return the quotient of self divided by 2.
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   432
     The receiver MAY, but NEED NOT be changed to contain the result.
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   433
     So this method must be used as: 'a := a div2.
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   434
     This method can be redefined for constructed datatypes to do optimisations"
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   435
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   436
    ^ self // 2
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   437
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   438
    "Created: / 28.4.1999 / 10:12:44 / stefan"
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   439
    "Modified: / 28.4.1999 / 11:56:09 / stefan"
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   440
!
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   441
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   442
mul2
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   443
    "Return the product of self multiplied by 2.
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   444
     The receiver MAY, but NEED NOT be changed to contain the result.
15279
7dd8da92779e class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 14747
diff changeset
   445
     So this method must be used as: a := a mul2.
12578
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   446
     This method can be redefined for constructed datatypes to do optimisations"
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   447
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   448
    ^ self * 2
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   449
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   450
    "Created: / 28.4.1999 / 10:12:55 / stefan"
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   451
    "Modified: / 28.4.1999 / 11:56:38 / stefan"
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   452
! !
6cb12eb8eb59 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 12576
diff changeset
   453
5238
f7a816a660a3 categories
Claus Gittinger <cg@exept.de>
parents: 4995
diff changeset
   454
!ArithmeticValue methodsFor:'coercing & converting'!
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   455
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   456
coerce:aNumber
11725
ad5591683279 comment
Claus Gittinger <cg@exept.de>
parents: 11467
diff changeset
   457
    "convert the argument aNumber into an instance of the receivers class and return it."
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   458
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   459
    ^ self subclassResponsibility
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   460
!
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   461
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   462
generality
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   463
    "return a number giving the receivers generality, that number is
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   464
     used to convert one of the arguments in a mixed expression.
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   465
     The generality has to be defined in subclasses,
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   466
     such that gen(a) > gen(b) iff, conversion of b into a's class
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   467
     does not cut precision. For example, Integer has 40, Float has 80,
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   468
     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
   469
     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
   470
     which converts the lower-precision number to the higher precision
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   471
     numbers class, when mixed-type arithmetic is performed."
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   472
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   473
    ^ self subclassResponsibility
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   474
3982
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   475
    "Modified: / 5.11.1996 / 15:05:30 / cg"
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   476
    "Modified: / 13.2.1998 / 15:36:01 / stefan"
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   477
!
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   478
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   479
retry:aSymbol coercing:aNumber
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   480
    "arithmetic represented by the binary operator, aSymbol,
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   481
     could not be performed with the receiver and the argument, aNumber,
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   482
     because of the differences in representation.
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   483
     Coerce either the receiver or the argument, depending on which has higher
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   484
     generality, and try again.
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   485
     If the operation is compare for same value (=), return false if
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   486
     the argument is not a Number.
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   487
     If the generalities are the same, create an error message, since this
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   488
     means that a subclass has not been fully implemented."
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   489
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   490
    |hasGenerality myGenerality otherGenerality|
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   491
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   492
    hasGenerality := aNumber respondsTo:#generality.
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   493
    hasGenerality ifFalse:[
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   494
	(aSymbol == #=) ifTrue:[
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   495
	    ^ false
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   496
	].
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   497
	(aSymbol == #~=) ifTrue:[
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   498
	    ^ true
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   499
	].
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   500
	^ self error:'retry:coercing: argument is not a number'.
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   501
    ].
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   502
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   503
    myGenerality := self generality.
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   504
    otherGenerality := aNumber generality.
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   505
    (myGenerality > otherGenerality) ifTrue:[
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   506
	^ self perform:aSymbol with:(self coerce:aNumber)
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   507
    ].
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   508
    (myGenerality < otherGenerality) ifTrue:[
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   509
	^ (aNumber coerce:self) perform:aSymbol with:aNumber
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   510
    ].
10324
25973c64a974 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10315
diff changeset
   511
    self error:'retry:coercing: oops - same generality; retry should not happen'
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   512
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   513
    "Modified: 5.11.1996 / 15:03:38 / cg"
16657
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   514
!
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   515
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   516
retry:aSymbol coercing:aNumber with:anArgument
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   517
    "arithmetic represented by the binary operator, aSymbol,
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   518
     could not be performed with the receiver and the argument, aNumber,
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   519
     because of the differences in representation.
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   520
     Coerce either the receiver or the argument, depending on which has higher
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   521
     generality, and try again.
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   522
     If the operation is compare for same value (=), return false if
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   523
     the argument is not a Number.
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   524
     If the generalities are the same, create an error message, since this
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   525
     means that a subclass has not been fully implemented."
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   526
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   527
    |hasGenerality myGenerality otherGenerality|
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   528
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   529
    hasGenerality := aNumber respondsTo:#generality.
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   530
    hasGenerality ifFalse:[
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   531
        ^ self error:'retry:coercing: argument is not a number'.
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   532
    ].
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   533
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   534
    myGenerality := self generality.
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   535
    otherGenerality := aNumber generality.
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   536
    (myGenerality > otherGenerality) ifTrue:[
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   537
        ^ self perform:aSymbol with:(self coerce:aNumber) with:anArgument
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   538
    ].
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   539
    (myGenerality < otherGenerality) ifTrue:[
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   540
        ^ (aNumber coerce:self) perform:aSymbol with:aNumber with:anArgument
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   541
    ].
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   542
    self error:'retry:coercing: oops - same generality; retry should not happen'
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   543
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   544
    "Modified: 5.11.1996 / 15:03:38 / cg"
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   545
! !
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   546
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   547
!ArithmeticValue methodsFor:'converting'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   548
17222
9ff268844b9c class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17189
diff changeset
   549
as32BitIEEEFloatBytesMSB:msb
9ff268844b9c class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17189
diff changeset
   550
    ^ self asShortFloat digitBytesMSB:msb
9ff268844b9c class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17189
diff changeset
   551
9ff268844b9c class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17189
diff changeset
   552
    "
9ff268844b9c class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17189
diff changeset
   553
        2  as32BitIEEEFloatBytesMSB:true
9ff268844b9c class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17189
diff changeset
   554
        2.0  as32BitIEEEFloatBytesMSB:true
9ff268844b9c class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17189
diff changeset
   555
    "
9ff268844b9c class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17189
diff changeset
   556
!
9ff268844b9c class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17189
diff changeset
   557
9ff268844b9c class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17189
diff changeset
   558
as64BitIEEEFloatBytesMSB:msb
9ff268844b9c class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17189
diff changeset
   559
    ^ self asFloat digitBytesMSB:msb
9ff268844b9c class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17189
diff changeset
   560
9ff268844b9c class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17189
diff changeset
   561
    "
9ff268844b9c class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17189
diff changeset
   562
        2  as64BitIEEEFloatBytesMSB:true
9ff268844b9c class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17189
diff changeset
   563
        2.0  as64BitIEEEFloatBytesMSB:true
9ff268844b9c class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17189
diff changeset
   564
    "
9ff268844b9c class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17189
diff changeset
   565
!
9ff268844b9c class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17189
diff changeset
   566
3982
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   567
asDouble
7429
3efb092371a3 comment
Claus Gittinger <cg@exept.de>
parents: 7416
diff changeset
   568
    "ST80 compatibility: return a double with receivers value.
3efb092371a3 comment
Claus Gittinger <cg@exept.de>
parents: 7416
diff changeset
   569
     our floats are the identical to ST80 doubles"
3982
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   570
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   571
   ^ self asFloat
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   572
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   573
    "Created: / 13.2.1998 / 15:40:14 / stefan"
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   574
!
22fdd79b2d9d Define asDouble for ST80 compatibility.
Stefan Vogel <sv@exept.de>
parents: 3654
diff changeset
   575
8202
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   576
asFixedPoint
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   577
    "return the receiver as fixedPoint number.
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   578
     Q: what should the scale be here ?"
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   579
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   580
    ^ self asFraction asFixedPoint
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   581
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   582
    "
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   583
     0.3 asFixedPoint
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   584
     0.5 asFixedPoint
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   585
     (1/5) asFloat asFixedPoint
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   586
     (1/3) asFloat asFixedPoint
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   587
     (2/3) asFloat asFixedPoint
8202
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   588
     (1/8) asFloat asFixedPoint
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   589
     3.14159 asFixedPoint
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   590
     0.0000001 asFraction
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   591
     0.0000001 asFixedPoint
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   592
    "
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   593
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   594
    "Modified: / 25.10.1997 / 15:36:54 / cg"
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   595
!
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   596
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   597
asFixedPoint:scale
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   598
    "return the receiver as fixedPoint number with the given
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   599
     number of post-decimal-digits."
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   600
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   601
    ^ self asFraction asFixedPoint:scale
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   602
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   603
    "
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   604
     0.3 asFixedPoint:4
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   605
     0.3 asFixedPoint:3
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   606
     0.3 asFixedPoint:2
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   607
     0.3 asFixedPoint:1
8202
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   608
     0.3 asFixedPoint:0
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   609
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   610
     0.5 asFixedPoint:3
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   611
     (1/5) asFloat asFixedPoint:1
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   612
     (1/8) asFloat asFixedPoint:1
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   613
     1.0 asFixedPoint:2
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   614
     3.14159 asFixedPoint:2
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   615
     3.14159 asFixedPoint:3
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
   616
     (3.14159 asFixedPoint:2) asFixedPoint:5
8202
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   617
    "
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   618
!
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
   619
12980
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   620
asFixedPointRoundedToScale
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   621
    "return the receiver as fixedPoint number, rounded to its scale."
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   622
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   623
    ^ self asFixedPoint roundedToScale
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   624
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   625
    "
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   626
     0.3 asFixedPoint
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   627
     0.5 asFixedPoint
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   628
     (2/3) asFloat asFixedPoint
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   629
     (1/8) asFloat asFixedPoint
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   630
     3.14159 asFixedPoint
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   631
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   632
     0.3 asFixedPointRoundedToScale
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   633
     0.5 asFixedPointRoundedToScale
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   634
     (2/3) asFloat asFixedPointRoundedToScale
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   635
     (1/8) asFloat asFixedPointRoundedToScale
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   636
     3.14159 asFixedPointRoundedToScale
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   637
    "
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   638
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   639
    "Created: / 02-08-2010 / 13:32:16 / cg"
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   640
!
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   641
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   642
asFixedPointRoundedToScale:scale
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   643
    "return the receiver as fixedPoint number with the given
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   644
     number of post-decimal-digits, rounded to its scale"
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   645
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   646
    ^ (self asFixedPoint:scale) roundedToScale
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   647
17336
3cfe5fb7201c class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 17223
diff changeset
   648
    "
3cfe5fb7201c class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 17223
diff changeset
   649
     3.14159 asFixedPointRoundedToScale:1
3cfe5fb7201c class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 17223
diff changeset
   650
     3.14159 asFixedPointRoundedToScale:2
3cfe5fb7201c class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 17223
diff changeset
   651
     3.14159 asFixedPointRoundedToScale:3
3cfe5fb7201c class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 17223
diff changeset
   652
     3.14159 asFixedPointRoundedToScale:4
3cfe5fb7201c class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 17223
diff changeset
   653
    "
3cfe5fb7201c class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 17223
diff changeset
   654
12980
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   655
    "Created: / 02-08-2010 / 13:33:11 / cg"
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   656
!
Claus Gittinger <cg@exept.de>
parents: 12760
diff changeset
   657
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   658
asFloat
a27a279701f8 Initial revision
claus
parents:
diff changeset
   659
    "return a float with same value"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   660
a27a279701f8 Initial revision
claus
parents:
diff changeset
   661
   ^ self subclassResponsibility
a27a279701f8 Initial revision
claus
parents:
diff changeset
   662
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   663
5986
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   664
asFloatD
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   665
    "return a double precision float with same value.
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   666
     Added for ANSI compatibility"
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   667
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   668
   ^ self asFloat
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   669
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   670
    "Created: / 7.9.2001 / 13:36:48 / cg"
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   671
    "Modified: / 7.9.2001 / 13:38:10 / cg"
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   672
!
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   673
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   674
asFloatE
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   675
    "return a single precision float with same value.
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   676
     Added for ANSI compatibility"
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   677
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   678
   ^ self asShortFloat
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   679
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   680
    "Created: / 7.9.2001 / 13:37:06 / cg"
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   681
    "Modified: / 7.9.2001 / 13:38:15 / cg"
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   682
!
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   683
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   684
asFloatQ
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   685
    "return a quad precision float with same value.
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   686
     Added for ANSI compatibility"
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   687
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   688
   ^ self asLongFloat
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   689
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   690
    "Created: / 7.9.2001 / 13:38:44 / cg"
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   691
!
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   692
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   693
asFraction
a27a279701f8 Initial revision
claus
parents:
diff changeset
   694
    "return a fraction with same value"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   695
a27a279701f8 Initial revision
claus
parents:
diff changeset
   696
   ^ self subclassResponsibility
a27a279701f8 Initial revision
claus
parents:
diff changeset
   697
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   698
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   699
asInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   700
    "return an integer with same value - might truncate"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   702
    ^ self truncated
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   703
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   704
7378
e71a28f6b712 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
   705
asLimitedPrecisionReal
e71a28f6b712 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
   706
    "return a float of any precision with same value"
e71a28f6b712 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
   707
e71a28f6b712 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
   708
   ^ self asFloat
e71a28f6b712 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
   709
!
e71a28f6b712 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7355
diff changeset
   710
5986
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   711
asLongFloat
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   712
    "return a longFloat with same value"
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   713
10315
4be6dacc89ce *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9443
diff changeset
   714
    "WARNING: could loose precision here, if not redefined in concrete classes which
4be6dacc89ce *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9443
diff changeset
   715
     have more than float precision (i.e. LargeIntegers and Fractions)"
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   716
10315
4be6dacc89ce *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9443
diff changeset
   717
    ^ self asFloat asLongFloat "/ subclassResponsibility
5986
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   718
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   719
    "Modified: / 17.4.1996 / 12:21:35 / cg"
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   720
    "Created: / 7.9.2001 / 13:39:31 / cg"
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   721
!
3d8c2676e913 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5957
diff changeset
   722
5987
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   723
asScaledDecimal:scale
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   724
    "return a fixedPoint approximating the receivers value"
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   725
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   726
    ^ self asFixedPoint:scale
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   727
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   728
    "
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   729
     1.234 asScaledDecimal:2
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   730
    "
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   731
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   732
    "Created: / 7.9.2001 / 13:46:26 / cg"
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   733
    "Modified: / 7.9.2001 / 13:46:44 / cg"
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   734
!
Claus Gittinger <cg@exept.de>
parents: 5986
diff changeset
   735
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   736
asShortFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   737
    "return a shortFloat with same value"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   738
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   739
   ^ self asFloat asShortFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   740
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   741
    "Modified: 17.4.1996 / 12:21:35 / cg"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   742
!
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   743
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   744
degreesToRadians
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   745
    "interpreting the receiver as radians, return the degrees"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   746
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   747
    ^ self asFloat degreesToRadians
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   748
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   749
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   750
radiansToDegrees
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   751
    "interpreting the receiver as degrees, return the radians"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   752
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   753
    ^ self asFloat radiansToDegrees
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   754
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   755
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   756
!ArithmeticValue methodsFor:'double dispatching'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   757
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   758
differenceFromComplex:aComplex
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   759
    "the receiver does not know how to subtract from a complex -
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   760
     retry the operation by coercing to higher generality"
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   761
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   762
    ^ aComplex retry:#- coercing:self
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   763
!
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   764
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   765
differenceFromFixedPoint:aFixedPoint
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   766
    "the receiver does not know how to subtract from a fixedPoint number -
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   767
     retry the operation by coercing to higher generality"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   768
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   769
    ^ aFixedPoint retry:#- coercing:self
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   770
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   771
    "Created: 5.11.1996 / 14:55:51 / cg"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   772
!
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   773
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   774
differenceFromFloat:aFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   775
    "the receiver does not know how to subtract from a float -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   776
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   777
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   778
    ^ aFloat retry:#- coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   779
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   780
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   781
differenceFromFraction:aFraction
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   782
    "the receiver does not know how to subtract from a fraction -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   783
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   784
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   785
    ^ aFraction retry:#- coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   786
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   787
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   788
differenceFromInteger:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   789
    "the receiver does not know how to subtract from an integer -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   790
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   791
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   792
    ^ anInteger retry:#- coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   793
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   794
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   795
differenceFromLargeFloat:aLargeFloat
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   796
    "the receiver does not know how to subtract from a largeFloat -
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   797
     retry the operation by coercing to higher generality"
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   798
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   799
    ^ aLargeFloat retry:#- coercing:self
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   800
!
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   801
7399
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
   802
differenceFromLongFloat:aLongFloat
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
   803
    "the receiver does not know how to subtract from a longFloat -
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
   804
     retry the operation by coercing to higher generality"
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
   805
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
   806
    ^ aLongFloat retry:#- coercing:self
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
   807
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
   808
    "Created: 17.4.1996 / 12:33:16 / cg"
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
   809
!
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
   810
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   811
differenceFromShortFloat:aShortFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   812
    "the receiver does not know how to subtract from a shortFloat -
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   813
     retry the operation by coercing to higher generality"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   814
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   815
    ^ aShortFloat retry:#- coercing:self
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   816
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   817
    "Created: 17.4.1996 / 12:33:16 / cg"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   818
!
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   819
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   820
equalFromComplex:aComplex
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   821
    "the receiver does not know how to compare to a complex number -
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   822
     retry the operation by coercing to higher generality"
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   823
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   824
    ^ aComplex retry:#= coercing:self
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   825
!
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   826
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   827
equalFromFixedPoint:aFixedPoint
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   828
    "the receiver does not know how to compare to a fixed point -
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   829
     retry the operation by coercing to higher generality"
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   830
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   831
    ^ aFixedPoint retry:#= coercing:self
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   832
!
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   833
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   834
equalFromFloat:aFloat
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   835
    "the receiver does not know how to compare to a float -
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   836
     retry the operation by coercing to higher generality"
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   837
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   838
    ^ aFloat retry:#= coercing:self
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   839
!
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   840
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   841
equalFromFraction:aFraction
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   842
    "the receiver does not know how to compare to a fraction -
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   843
     retry the operation by coercing to higher generality"
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   844
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   845
    ^ aFraction retry:#= coercing:self
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   846
!
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   847
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   848
equalFromInteger:anInteger
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   849
    "the receiver does not know how to compare to an integer -
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   850
     retry the operation by coercing to higher generality"
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   851
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   852
    ^ anInteger retry:#= coercing:self
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   853
!
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   854
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   855
equalFromLargeFloat:aLargeFloat
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   856
    "the receiver does not know how to compare to a large float -
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   857
     retry the operation by coercing to higher generality"
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   858
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   859
    ^ aLargeFloat retry:#= coercing:self
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   860
!
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   861
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   862
equalFromLongFloat:aLongFloat
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   863
    "the receiver does not know how to compare to a long float -
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   864
     retry the operation by coercing to higher generality"
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   865
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   866
    ^ aLongFloat retry:#= coercing:self
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   867
!
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   868
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   869
equalFromShortFloat:aShortFloat
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   870
    "the receiver does not know how to compare to a short float -
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   871
     retry the operation by coercing to higher generality"
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   872
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   873
    ^ aShortFloat retry:#= coercing:self
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   874
!
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   875
13007
Claus Gittinger <cg@exept.de>
parents: 12980
diff changeset
   876
integerQuotientFromInteger:anInteger
Claus Gittinger <cg@exept.de>
parents: 12980
diff changeset
   877
    "anInteger does not know how to divide by the receiver -
Claus Gittinger <cg@exept.de>
parents: 12980
diff changeset
   878
     retry the operation by coercing to higher generality"
Claus Gittinger <cg@exept.de>
parents: 12980
diff changeset
   879
Claus Gittinger <cg@exept.de>
parents: 12980
diff changeset
   880
    ^ anInteger retry:#// coercing:self
Claus Gittinger <cg@exept.de>
parents: 12980
diff changeset
   881
Claus Gittinger <cg@exept.de>
parents: 12980
diff changeset
   882
    "Created: / 09-08-2010 / 19:49:26 / cg"
Claus Gittinger <cg@exept.de>
parents: 12980
diff changeset
   883
!
Claus Gittinger <cg@exept.de>
parents: 12980
diff changeset
   884
16657
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   885
isAlmostEqualToFromFloat:aFloat nEpsilon:nE
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   886
    "the receiver does not know how to compare to a short float -
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   887
     retry the operation by coercing to higher generality"
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   888
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   889
    ^ aFloat retry:#isAlmostEqualTo:nEpsilon: coercing:self with:nE
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   890
!
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   891
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   892
isAlmostEqualToFromShortFloat:aShortFloat nEpsilon:nE
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   893
    "the receiver does not know how to compare to a short float -
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   894
     retry the operation by coercing to higher generality"
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   895
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   896
    ^ aShortFloat retry:#isAlmostEqualTo:nEpsilon: coercing:self with:nE
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   897
!
a87789caf59d class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 16121
diff changeset
   898
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   899
lessFromFixedPoint:aFixedPoint
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   900
    "the receiver does not know how to compare to a fixedPoint number -
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   901
     retry the operation by coercing to higher generality"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   902
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   903
    ^ aFixedPoint retry:#< coercing:self
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   904
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   905
    "Created: 5.11.1996 / 14:56:12 / cg"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   906
!
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   907
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   908
lessFromFloat:aFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   909
    "the receiver does not know how to compare to a float -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   910
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   911
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   912
    ^ aFloat retry:#< coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   913
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   914
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   915
lessFromFraction:aFraction
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   916
    "the receiver does not know how to compare to a fraction -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   917
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   918
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   919
    ^ aFraction retry:#< coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   920
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   921
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   922
lessFromInteger:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   923
    "the receiver does not know how to compare to an integer -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   924
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   925
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   926
    ^ anInteger retry:#< coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   927
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   928
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   929
lessFromLargeFloat:aLargeFloat
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   930
    "the receiver does not know how to compare to a largeFloat -
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   931
     retry the operation by coercing to higher generality"
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   932
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   933
    ^ aLargeFloat retry:#< coercing:self
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   934
!
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
   935
7399
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
   936
lessFromLongFloat:aLongFloat
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
   937
    "the receiver does not know how to compare to a longFloat -
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
   938
     retry the operation by coercing to higher generality"
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
   939
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
   940
    ^ aLongFloat retry:#< coercing:self
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
   941
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
   942
    "Modified: 17.4.1996 / 12:33:33 / cg"
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
   943
!
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
   944
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   945
lessFromShortFloat:aShortFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   946
    "the receiver does not know how to compare to a shortFloat -
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   947
     retry the operation by coercing to higher generality"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   948
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   949
    ^ aShortFloat retry:#< coercing:self
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   950
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   951
    "Modified: 17.4.1996 / 12:33:33 / cg"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   952
!
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
   953
14002
0f1ef36dc1b6 added: #moduloFromInteger:
Claus Gittinger <cg@exept.de>
parents: 14001
diff changeset
   954
moduloFromInteger:anInteger
0f1ef36dc1b6 added: #moduloFromInteger:
Claus Gittinger <cg@exept.de>
parents: 14001
diff changeset
   955
    "anInteger does not know how to compute the modulo from the receiver -
0f1ef36dc1b6 added: #moduloFromInteger:
Claus Gittinger <cg@exept.de>
parents: 14001
diff changeset
   956
     retry the operation by coercing to higher generality"
0f1ef36dc1b6 added: #moduloFromInteger:
Claus Gittinger <cg@exept.de>
parents: 14001
diff changeset
   957
0f1ef36dc1b6 added: #moduloFromInteger:
Claus Gittinger <cg@exept.de>
parents: 14001
diff changeset
   958
    ^ anInteger retry:#\\ coercing:self
0f1ef36dc1b6 added: #moduloFromInteger:
Claus Gittinger <cg@exept.de>
parents: 14001
diff changeset
   959
0f1ef36dc1b6 added: #moduloFromInteger:
Claus Gittinger <cg@exept.de>
parents: 14001
diff changeset
   960
    "Created: / 12-02-2012 / 20:38:13 / cg"
0f1ef36dc1b6 added: #moduloFromInteger:
Claus Gittinger <cg@exept.de>
parents: 14001
diff changeset
   961
!
0f1ef36dc1b6 added: #moduloFromInteger:
Claus Gittinger <cg@exept.de>
parents: 14001
diff changeset
   962
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   963
productFromComplex:aComplex
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   964
    "the receiver does not know how to multiply a complex -
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   965
     retry the operation by coercing to higher generality"
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   966
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   967
    ^ aComplex retry:#* coercing:self
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   968
!
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
   969
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   970
productFromFixedPoint:aFixedPoint
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   971
    "the receiver does not know how to multiply a fixed point number -
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   972
     retry the operation by coercing to higher generality"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   973
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   974
    ^ aFixedPoint retry:#* coercing:self
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   975
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   976
    "Created: 5.11.1996 / 14:56:28 / cg"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   977
!
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
   978
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   979
productFromFloat:aFloat
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   980
    "the receiver does not know how to multiply a float -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   981
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   982
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   983
    ^ aFloat retry:#* coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   984
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   985
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   986
productFromFraction:aFraction
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   987
    "the receiver does not know how to multiply a fraction -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   988
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   989
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   990
    ^ aFraction retry:#* coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   991
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   992
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   993
productFromInteger:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   994
    "the receiver does not know how to multiply an integer -
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   995
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   996
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
   997
    ^ anInteger retry:#* coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   998
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   999
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1000
productFromLargeFloat:aLargeFloat
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1001
    "the receiver does not know how to multiply a largeFloat -
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1002
     retry the operation by coercing to higher generality"
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1003
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1004
    ^ aLargeFloat retry:#* coercing:self
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1005
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1006
    "Created: 17.4.1996 / 12:33:48 / cg"
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1007
!
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1008
7399
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  1009
productFromLongFloat:aLongFloat
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  1010
    "the receiver does not know how to multiply a longFloat -
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  1011
     retry the operation by coercing to higher generality"
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  1012
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  1013
    ^ aLongFloat retry:#* coercing:self
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  1014
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  1015
    "Created: 17.4.1996 / 12:33:48 / cg"
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  1016
!
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  1017
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
  1018
productFromShortFloat:aShortFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
  1019
    "the receiver does not know how to multiply a shortFloat -
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
  1020
     retry the operation by coercing to higher generality"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
  1021
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
  1022
    ^ aShortFloat retry:#* coercing:self
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
  1023
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
  1024
    "Created: 17.4.1996 / 12:33:48 / cg"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
  1025
!
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
  1026
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
  1027
quotientFromComplex:aComplex
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1028
    "aComplex does not know how to divide by the receiver -
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
  1029
     retry the operation by coercing to higher generality"
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
  1030
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
  1031
    ^ aComplex retry:#/ coercing:self
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
  1032
!
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
  1033
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
  1034
quotientFromFixedPoint:aFixedPoint
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1035
    "aFixedPoint does not know how to divide by the receiver -
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
  1036
     retry the operation by coercing to higher generality"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
  1037
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
  1038
    ^ aFixedPoint retry:#/ coercing:self
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
  1039
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
  1040
    "Created: 5.11.1996 / 14:56:41 / cg"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
  1041
!
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
  1042
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1043
quotientFromFloat:aFloat
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1044
    "aFloat does not know how to divide by the receiver -
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1045
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1046
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1047
    ^ aFloat retry:#/ coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1048
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1049
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1050
quotientFromFraction:aFraction
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1051
    "aFraction does not know how to divide by the receiver -
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1052
     retry the operation by coercing to higher generality"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1053
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1054
    ^ aFraction retry:#/ coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1055
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1056
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1057
quotientFromInteger:anInteger
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1058
    "anInteger does not know how to divide by the receiver -
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1059
     retry the operation by coercing to higher generality"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1060
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1061
    ^ anInteger retry:#/ coercing:self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1062
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1063
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1064
quotientFromLargeFloat:aLargeFloat
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1065
    "aLargeFloat does not know how to divide by the receiver -
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1066
     retry the operation by coercing to higher generality"
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1067
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1068
    ^ aLargeFloat retry:#/ coercing:self
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1069
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1070
    "Created: 17.4.1996 / 12:34:00 / cg"
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1071
!
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1072
7399
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  1073
quotientFromLongFloat:aLongFloat
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1074
    "aLongFloat does not know how to divide by the receiver -
7399
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  1075
     retry the operation by coercing to higher generality"
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  1076
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  1077
    ^ aLongFloat retry:#/ coercing:self
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  1078
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  1079
    "Created: 17.4.1996 / 12:34:00 / cg"
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  1080
!
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  1081
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
  1082
quotientFromShortFloat:aShortFloat
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1083
    "aShortFloat does not know how to divide by the receiver -
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
  1084
     retry the operation by coercing to higher generality"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
  1085
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
  1086
    ^ aShortFloat retry:#/ coercing:self
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
  1087
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
  1088
    "Created: 17.4.1996 / 12:34:00 / cg"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
  1089
!
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
  1090
14747
18be9a3c2324 class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 14497
diff changeset
  1091
remainderFromFloat:aFloat
18be9a3c2324 class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 14497
diff changeset
  1092
    "aFloat does not know how to compute the remainder with the receiver -
18be9a3c2324 class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 14497
diff changeset
  1093
     retry the operation by coercing to higher generality"
18be9a3c2324 class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 14497
diff changeset
  1094
18be9a3c2324 class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 14497
diff changeset
  1095
    ^ aFloat retry:#rem: coercing:self
18be9a3c2324 class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 14497
diff changeset
  1096
!
18be9a3c2324 class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 14497
diff changeset
  1097
18be9a3c2324 class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 14497
diff changeset
  1098
remainderFromShortFloat:aShortFloat
18be9a3c2324 class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 14497
diff changeset
  1099
    "aShortFloat does not know how to compute the remainder with the receiver -
18be9a3c2324 class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 14497
diff changeset
  1100
     retry the operation by coercing to higher generality"
18be9a3c2324 class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 14497
diff changeset
  1101
18be9a3c2324 class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 14497
diff changeset
  1102
    ^ aShortFloat retry:#rem: coercing:self
18be9a3c2324 class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 14497
diff changeset
  1103
!
18be9a3c2324 class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 14497
diff changeset
  1104
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
  1105
sumFromComplex:aComplex
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
  1106
    "the receiver does not know how to add a complex -
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
  1107
     retry the operation by coercing to higher generality"
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
  1108
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
  1109
    ^ aComplex retry:#+ coercing:self
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
  1110
!
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
  1111
1888
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
  1112
sumFromFixedPoint:aFixedPoint
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
  1113
    "the receiver does not know how to add a fixed point number -
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
  1114
     retry the operation by coercing to higher generality"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
  1115
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
  1116
    ^ aFixedPoint retry:#+ coercing:self
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
  1117
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
  1118
    "Created: 5.11.1996 / 14:56:56 / cg"
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
  1119
!
463d49ca22e3 fixedPoint support
Claus Gittinger <cg@exept.de>
parents: 1881
diff changeset
  1120
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1121
sumFromFloat:aFloat
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1122
    "the receiver does not know how to add a float -
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1123
     retry the operation by coercing to higher generality"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1124
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1125
    ^ aFloat retry:#+ coercing:self
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1126
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1127
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1128
sumFromFraction:aFraction
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1129
    "the receiver does not know how to add a fraction -
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1130
     retry the operation by coercing to higher generality"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1131
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1132
    ^ aFraction retry:#+ coercing:self
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1133
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1134
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1135
sumFromInteger:anInteger
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1136
    "the receiver does not know how to add an integer -
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1137
     retry the operation by coercing to higher generality"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1138
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1139
    ^ anInteger retry:#+ coercing:self
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
  1140
!
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
  1141
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1142
sumFromLargeFloat:aLargeFloat
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1143
    "the receiver does not know how to add a largeFloat -
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1144
     retry the operation by coercing to higher generality"
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1145
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1146
    ^ aLargeFloat retry:#+ coercing:self
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1147
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1148
    "Created: 17.4.1996 / 12:34:10 / cg"
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1149
!
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1150
7399
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  1151
sumFromLongFloat:aLongFloat
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  1152
    "the receiver does not know how to add a longFloat -
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  1153
     retry the operation by coercing to higher generality"
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  1154
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  1155
    ^ aLongFloat retry:#+ coercing:self
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  1156
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  1157
    "Created: 17.4.1996 / 12:34:10 / cg"
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  1158
!
43d62fad41b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7393
diff changeset
  1159
1200
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
  1160
sumFromShortFloat:aShortFloat
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
  1161
    "the receiver does not know how to add a shortFloat -
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
  1162
     retry the operation by coercing to higher generality"
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
  1163
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
  1164
    ^ aShortFloat retry:#+ coercing:self
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
  1165
cc16f7a00b52 limited shortFloat support
Claus Gittinger <cg@exept.de>
parents: 1172
diff changeset
  1166
    "Created: 17.4.1996 / 12:34:10 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1167
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1168
7384
ae6b11a3b4d5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7378
diff changeset
  1169
!ArithmeticValue methodsFor:'mathematical functions'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1170
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
  1171
** aNumber
9443
5d3f32a6f43e added **
Claus Gittinger <cg@exept.de>
parents: 9400
diff changeset
  1172
    "Answer the receiver raised to the power of the argument, aNumber."
5d3f32a6f43e added **
Claus Gittinger <cg@exept.de>
parents: 9400
diff changeset
  1173
    "same as Number>>raisedTo:"
5d3f32a6f43e added **
Claus Gittinger <cg@exept.de>
parents: 9400
diff changeset
  1174
5d3f32a6f43e added **
Claus Gittinger <cg@exept.de>
parents: 9400
diff changeset
  1175
    ^self raisedTo: aNumber
5d3f32a6f43e added **
Claus Gittinger <cg@exept.de>
parents: 9400
diff changeset
  1176
5d3f32a6f43e added **
Claus Gittinger <cg@exept.de>
parents: 9400
diff changeset
  1177
    "Created: / 15-07-2006 / 15:11:05 / cg"
5d3f32a6f43e added **
Claus Gittinger <cg@exept.de>
parents: 9400
diff changeset
  1178
    "Modified: / 17-07-2006 / 12:51:33 / cg"
5d3f32a6f43e added **
Claus Gittinger <cg@exept.de>
parents: 9400
diff changeset
  1179
!
5d3f32a6f43e added **
Claus Gittinger <cg@exept.de>
parents: 9400
diff changeset
  1180
7635
fbe7cf11ac9e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  1181
raisedTo: aNumber
8633
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1182
    aNumber isInteger ifTrue:[
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
  1183
	^ self raisedToInteger:aNumber
8633
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1184
    ].
7635
fbe7cf11ac9e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  1185
    ^ self subclassResponsibility
6858
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
  1186
!
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
  1187
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
  1188
raisedToInteger:exp
8633
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1189
    "return the receiver raised to exp"
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1190
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1191
    |result e t|
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1192
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1193
    "use the addition chaining algorithm,
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1194
     which is much faster for big exp-arguments"
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1195
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1196
    result := 1.
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1197
    t := self.
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1198
    exp < 0 ifTrue:[
12760
6482afd031af comment/format in: #raisedToInteger:
Claus Gittinger <cg@exept.de>
parents: 12578
diff changeset
  1199
        e := exp negated.
8633
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1200
    ] ifFalse:[
12760
6482afd031af comment/format in: #raisedToInteger:
Claus Gittinger <cg@exept.de>
parents: 12578
diff changeset
  1201
        e := exp.
8633
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1202
    ].
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1203
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1204
    [e ~~ 0] whileTrue:[
12760
6482afd031af comment/format in: #raisedToInteger:
Claus Gittinger <cg@exept.de>
parents: 12578
diff changeset
  1205
        [(e bitAnd:1) == 0] whileTrue:[
6482afd031af comment/format in: #raisedToInteger:
Claus Gittinger <cg@exept.de>
parents: 12578
diff changeset
  1206
            e := e bitShift:-1.
6482afd031af comment/format in: #raisedToInteger:
Claus Gittinger <cg@exept.de>
parents: 12578
diff changeset
  1207
            t := t * t.
6482afd031af comment/format in: #raisedToInteger:
Claus Gittinger <cg@exept.de>
parents: 12578
diff changeset
  1208
        ].
6482afd031af comment/format in: #raisedToInteger:
Claus Gittinger <cg@exept.de>
parents: 12578
diff changeset
  1209
        e := e - 1.
6482afd031af comment/format in: #raisedToInteger:
Claus Gittinger <cg@exept.de>
parents: 12578
diff changeset
  1210
        result := result * t.
8633
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1211
    ].
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1212
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1213
    (exp < 0) ifTrue:[
12760
6482afd031af comment/format in: #raisedToInteger:
Claus Gittinger <cg@exept.de>
parents: 12578
diff changeset
  1214
        ^ 1 / result
8633
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1215
    ].
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1216
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1217
    ^ result
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1218
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1219
    "
17662
0fd098ccf3ff class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 17336
diff changeset
  1220
     (2.0 raisedToInteger:216)
8633
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1221
     (2 raisedToInteger:216)
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
  1222
     (2 raisedTo:216)
12760
6482afd031af comment/format in: #raisedToInteger:
Claus Gittinger <cg@exept.de>
parents: 12578
diff changeset
  1223
            -> 105312291668557186697918027683670432318895095400549111254310977536
8633
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1224
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
  1225
     (2 raisedToInteger:216) asFloat
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
  1226
     (2 raisedTo:216) asFloat
12760
6482afd031af comment/format in: #raisedToInteger:
Claus Gittinger <cg@exept.de>
parents: 12578
diff changeset
  1227
            -> 1.05312E+65
8633
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1228
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1229
     (2 raisedToInteger:500)
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
  1230
     (2 raisedTo:500)
12760
6482afd031af comment/format in: #raisedToInteger:
Claus Gittinger <cg@exept.de>
parents: 12578
diff changeset
  1231
            -> 3273390607896141870013189696827599152216642046043064789483291368096133796404674554883270092325904157150886684127560071009217256545885393053328527589376
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
  1232
     2 raisedToInteger:10
12760
6482afd031af comment/format in: #raisedToInteger:
Claus Gittinger <cg@exept.de>
parents: 12578
diff changeset
  1233
            -> 1024
8633
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1234
    -2 raisedToInteger:10
12760
6482afd031af comment/format in: #raisedToInteger:
Claus Gittinger <cg@exept.de>
parents: 12578
diff changeset
  1235
            -> 1024
8633
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1236
     -2 raisedToInteger:9
12760
6482afd031af comment/format in: #raisedToInteger:
Claus Gittinger <cg@exept.de>
parents: 12578
diff changeset
  1237
            -> -512
8633
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1238
     10 raisedToInteger:-10
12760
6482afd031af comment/format in: #raisedToInteger:
Claus Gittinger <cg@exept.de>
parents: 12578
diff changeset
  1239
            -> (1/10000000000)
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
  1240
     2 raisedToInteger:0
12760
6482afd031af comment/format in: #raisedToInteger:
Claus Gittinger <cg@exept.de>
parents: 12578
diff changeset
  1241
            -> 1
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
  1242
     2 raisedToInteger:-1
12760
6482afd031af comment/format in: #raisedToInteger:
Claus Gittinger <cg@exept.de>
parents: 12578
diff changeset
  1243
            -> (1/2)
8633
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1244
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1245
     Time millisecondsToRun:[
12760
6482afd031af comment/format in: #raisedToInteger:
Claus Gittinger <cg@exept.de>
parents: 12578
diff changeset
  1246
        10000 timesRepeat:[
6482afd031af comment/format in: #raisedToInteger:
Claus Gittinger <cg@exept.de>
parents: 12578
diff changeset
  1247
            (2 raisedToInteger:500)
6482afd031af comment/format in: #raisedToInteger:
Claus Gittinger <cg@exept.de>
parents: 12578
diff changeset
  1248
        ]
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
  1249
     ]
8633
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1250
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1251
     Time millisecondsToRun:[
12760
6482afd031af comment/format in: #raisedToInteger:
Claus Gittinger <cg@exept.de>
parents: 12578
diff changeset
  1252
        |bigNum|
6482afd031af comment/format in: #raisedToInteger:
Claus Gittinger <cg@exept.de>
parents: 12578
diff changeset
  1253
        bigNum := 2 raisedToInteger:500.
6482afd031af comment/format in: #raisedToInteger:
Claus Gittinger <cg@exept.de>
parents: 12578
diff changeset
  1254
        10 timesRepeat:[
6482afd031af comment/format in: #raisedToInteger:
Claus Gittinger <cg@exept.de>
parents: 12578
diff changeset
  1255
            (bigNum raisedToInteger:500)
6482afd031af comment/format in: #raisedToInteger:
Claus Gittinger <cg@exept.de>
parents: 12578
diff changeset
  1256
        ]
8633
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1257
     ]
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1258
    "
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1259
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1260
    "Created: / 27.4.1999 / 15:19:22 / stefan"
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1261
    "Modified: / 27.4.1999 / 16:16:11 / stefan"
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1262
!
239f2bd03afe raisedTo: / raisedToInteger: moved up
Claus Gittinger <cg@exept.de>
parents: 8449
diff changeset
  1263
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1264
squared
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1265
    "return receiver * receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1266
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1267
    ^ self * self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1268
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1269
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1270
!ArithmeticValue methodsFor:'queries'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1271
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1272
respondsToArithmetic
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1273
    "return true, if the receiver responds to arithmetic messages"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1274
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1275
    ^ true
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1276
! !
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1277
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1278
!ArithmeticValue methodsFor:'testing'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1279
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1280
denominator
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1281
    "return the denominator of the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1282
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1283
    ^ 1
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1284
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1285
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1286
even
17223
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
  1287
    "return true if the receiver is divisible by 2.
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
  1288
     Only defined for whole-numbers."
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1289
17223
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
  1290
    ^ self class
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
  1291
        raise:DomainError
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
  1292
        receiver:self
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
  1293
        selector:#even
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
  1294
        arguments:#()
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
  1295
        errorString:'Receiver must be a whole-number'
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
  1296
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
  1297
    "/ No, this is bad: ^ self truncated asInteger even
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
  1298
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
  1299
    "
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
  1300
        2.4 even
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
  1301
        2.0 even
db522b3aff6f class: ArithmeticValue
Stefan Vogel <sv@exept.de>
parents: 17222
diff changeset
  1302
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1303
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1304
3635
3fcccef48db3 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3393
diff changeset
  1305
isComplex
7355
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
  1306
    "Answer whether the receiver has an imaginary part
96f466eeddf5 double dispatching fixed;
Claus Gittinger <cg@exept.de>
parents: 7228
diff changeset
  1307
     (i.e. if it is a complex number). Always false here."
3635
3fcccef48db3 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3393
diff changeset
  1308
3fcccef48db3 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3393
diff changeset
  1309
    ^ false
3fcccef48db3 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3393
diff changeset
  1310
3fcccef48db3 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3393
diff changeset
  1311
    "Modified: / 9.7.1998 / 10:19:27 / cg"
3fcccef48db3 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3393
diff changeset
  1312
!
3fcccef48db3 complex conversion stuff
Claus Gittinger <cg@exept.de>
parents: 3393
diff changeset
  1313
8979
869510c58b9c Move #isFinite and #isInfinite from Number to ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8892
diff changeset
  1314
isFinite
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
  1315
    "return true, if the receiver is finite
9400
e3d6f81078ce comment
Stefan Vogel <sv@exept.de>
parents: 8979
diff changeset
  1316
     i.e. it can be represented as a rational number."
e3d6f81078ce comment
Stefan Vogel <sv@exept.de>
parents: 8979
diff changeset
  1317
8979
869510c58b9c Move #isFinite and #isInfinite from Number to ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8892
diff changeset
  1318
    ^ true
869510c58b9c Move #isFinite and #isInfinite from Number to ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8892
diff changeset
  1319
!
869510c58b9c Move #isFinite and #isInfinite from Number to ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8892
diff changeset
  1320
869510c58b9c Move #isFinite and #isInfinite from Number to ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8892
diff changeset
  1321
isInfinite
869510c58b9c Move #isFinite and #isInfinite from Number to ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8892
diff changeset
  1322
    ^ false
869510c58b9c Move #isFinite and #isInfinite from Number to ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8892
diff changeset
  1323
!
869510c58b9c Move #isFinite and #isInfinite from Number to ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8892
diff changeset
  1324
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1325
isNegativeInfinity
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1326
    ^ self negative and:[self isInfinite]
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1327
!
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1328
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1329
isNegativeZero
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1330
    "return false - must be redefined by subclasses which can represent a negative zero
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1331
     (i.e. limitedPrecisionReal classes)"
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1332
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1333
    ^ false
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1334
!
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1335
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1336
isPositiveInfinity
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1337
    ^ self positive and:[self isInfinite]
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1338
!
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1339
6156
ff2df95a69bf isReal moved
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
  1340
isReal
ff2df95a69bf isReal moved
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
  1341
    "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
  1342
     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
  1343
ff2df95a69bf isReal moved
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
  1344
    ^ false
ff2df95a69bf isReal moved
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
  1345
ff2df95a69bf isReal moved
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
  1346
    "Modified: / 6.11.2001 / 13:20:20 / cg"
ff2df95a69bf isReal moved
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
  1347
    "Created: / 6.11.2001 / 13:26:29 / cg"
ff2df95a69bf isReal moved
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
  1348
!
ff2df95a69bf isReal moved
Claus Gittinger <cg@exept.de>
parents: 6067
diff changeset
  1349
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1350
isZero
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1351
    "return false - must be redefined by subclasses which can represent a negative zero
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1352
     (i.e. limitedPrecisionReal classes)"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1353
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1354
    ^ self = self class zero
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1355
!
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1356
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1357
negative
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1358
    "return true if the receiver is less than zero"
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1359
8202
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
  1360
    ^ self < self class zero
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1361
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1362
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1363
numerator
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1364
    "return the numerator of the receiver."
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1365
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1366
    ^ self
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1367
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1368
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1369
odd
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1370
    "return true if the receiver is not divisible by 2"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1371
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1372
    ^ self even not
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1373
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1374
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1375
positive
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1376
    "return true, if the receiver is >= 0"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1377
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1378
    ^ self negative not
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1379
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1380
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1381
sign
7471
c5d4bd612d9f comments
Claus Gittinger <cg@exept.de>
parents: 7468
diff changeset
  1382
    "return the sign of the receiver (-1, 0 or 1)"
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1383
7440
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1384
    |zero|
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1385
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1386
    zero := self class zero.
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1387
    (self < zero) ifTrue:[^ -1].
d96bfc80e75e double dispatching
Claus Gittinger <cg@exept.de>
parents: 7429
diff changeset
  1388
    (zero < self) ifTrue:[^ 1].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1389
    ^ 0
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1390
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1391
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1392
strictlyPositive
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1393
    "return true, if the receiver is > 0"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1394
8202
2a6c8d1e26cb Define #asFixedPoint in ArithmethicValue
Stefan Vogel <sv@exept.de>
parents: 8184
diff changeset
  1395
    ^ self class zero < self
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1396
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1397
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1398
!ArithmeticValue methodsFor:'truncation & rounding'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1399
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1400
ceiling
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1401
    "return the integer nearest the receiver towards positive infinity."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1402
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1403
    |anInteger|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1404
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1405
    anInteger := self // 1.       "truncates towards negative infinity"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1406
    anInteger = self ifTrue:[^ anInteger].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1407
    ^ anInteger + 1
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1408
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1409
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1410
floor
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1411
    "return the receiver truncated towards negative infinity"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1412
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1413
    ^ self // 1
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1414
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1415
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1416
roundTo:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1417
    "return the receiver rounded to multiples of aNumber"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1418
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1419
    ^ (self / aNumber) rounded * aNumber
8449
9ec3ade5a78b +roundUpTo
Claus Gittinger <cg@exept.de>
parents: 8202
diff changeset
  1420
9ec3ade5a78b +roundUpTo
Claus Gittinger <cg@exept.de>
parents: 8202
diff changeset
  1421
    "
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
  1422
     0 roundTo:4
8449
9ec3ade5a78b +roundUpTo
Claus Gittinger <cg@exept.de>
parents: 8202
diff changeset
  1423
     1 roundTo:4
9ec3ade5a78b +roundUpTo
Claus Gittinger <cg@exept.de>
parents: 8202
diff changeset
  1424
     2 roundTo:4
9ec3ade5a78b +roundUpTo
Claus Gittinger <cg@exept.de>
parents: 8202
diff changeset
  1425
     3 roundTo:4
9ec3ade5a78b +roundUpTo
Claus Gittinger <cg@exept.de>
parents: 8202
diff changeset
  1426
     4 roundTo:4
9ec3ade5a78b +roundUpTo
Claus Gittinger <cg@exept.de>
parents: 8202
diff changeset
  1427
     5 roundTo:4
9ec3ade5a78b +roundUpTo
Claus Gittinger <cg@exept.de>
parents: 8202
diff changeset
  1428
     6 roundTo:4
9ec3ade5a78b +roundUpTo
Claus Gittinger <cg@exept.de>
parents: 8202
diff changeset
  1429
     7 roundTo:4
14497
211259d933cb class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 14002
diff changeset
  1430
211259d933cb class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 14002
diff changeset
  1431
     7.123 roundTo:0.1
211259d933cb class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 14002
diff changeset
  1432
     7.523 roundTo:0.1
211259d933cb class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 14002
diff changeset
  1433
     7.583 roundTo:0.1 
211259d933cb class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 14002
diff changeset
  1434
     7.623 roundTo:0.1
211259d933cb class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 14002
diff changeset
  1435
     7.623 roundTo:0.01 
211259d933cb class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 14002
diff changeset
  1436
     7.628 roundTo:0.01 
8449
9ec3ade5a78b +roundUpTo
Claus Gittinger <cg@exept.de>
parents: 8202
diff changeset
  1437
    "
9ec3ade5a78b +roundUpTo
Claus Gittinger <cg@exept.de>
parents: 8202
diff changeset
  1438
!
9ec3ade5a78b +roundUpTo
Claus Gittinger <cg@exept.de>
parents: 8202
diff changeset
  1439
9ec3ade5a78b +roundUpTo
Claus Gittinger <cg@exept.de>
parents: 8202
diff changeset
  1440
roundUpTo:aNumber
9ec3ade5a78b +roundUpTo
Claus Gittinger <cg@exept.de>
parents: 8202
diff changeset
  1441
    "return the receiver rounded up to the next multiple of aNumber"
9ec3ade5a78b +roundUpTo
Claus Gittinger <cg@exept.de>
parents: 8202
diff changeset
  1442
9ec3ade5a78b +roundUpTo
Claus Gittinger <cg@exept.de>
parents: 8202
diff changeset
  1443
    ^ (self / aNumber) ceiling * aNumber
9ec3ade5a78b +roundUpTo
Claus Gittinger <cg@exept.de>
parents: 8202
diff changeset
  1444
9ec3ade5a78b +roundUpTo
Claus Gittinger <cg@exept.de>
parents: 8202
diff changeset
  1445
    "
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
  1446
     0 roundUpTo:4
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
  1447
     1 roundUpTo:4
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
  1448
     2 roundUpTo:4
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
  1449
     3 roundUpTo:4
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
  1450
     4 roundUpTo:4
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
  1451
     5 roundUpTo:4
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
  1452
     6 roundUpTo:4
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
  1453
     7 roundUpTo:4
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
  1454
     8 roundUpTo:4
10911
38e7677d10a7 comment added
Claus Gittinger <cg@exept.de>
parents: 10326
diff changeset
  1455
     (3@4) roundUpTo:8
38e7677d10a7 comment added
Claus Gittinger <cg@exept.de>
parents: 10326
diff changeset
  1456
     (3@4) roundUpTo:(5 @ 4)
38e7677d10a7 comment added
Claus Gittinger <cg@exept.de>
parents: 10326
diff changeset
  1457
     (3@3) roundUpTo:(5 @ 4) 
8449
9ec3ade5a78b +roundUpTo
Claus Gittinger <cg@exept.de>
parents: 8202
diff changeset
  1458
    "
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1459
!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1460
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1461
rounded
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1462
    "return the integer nearest the receiver"
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1463
1881
0c6ba2c134c1 fixed #rounded
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1464
    self negative ifTrue:[
10326
b1103ad3581f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10324
diff changeset
  1465
	^ (self - 0.5) ceiling
1881
0c6ba2c134c1 fixed #rounded
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1466
    ].
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1467
    ^ (self + 0.5) floor
1881
0c6ba2c134c1 fixed #rounded
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1468
0c6ba2c134c1 fixed #rounded
Claus Gittinger <cg@exept.de>
parents: 1295
diff changeset
  1469
    "Modified: 5.11.1996 / 11:31:59 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1470
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1471
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1472
truncateTo:aNumber
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1473
    "return the receiver truncated to multiples of aNumber"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1474
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1475
    ^ ((self / aNumber) floor * aNumber) asInteger
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1476
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1477
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1478
truncated
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1479
    "return the receiver truncated towards zero"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1480
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1481
    self negative ifTrue:[
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1482
	^ self ceiling
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1483
    ].
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1484
    ^ self floor
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1485
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1486
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1487
!ArithmeticValue class methodsFor:'documentation'!
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1488
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1489
version
17662
0fd098ccf3ff class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 17336
diff changeset
  1490
    ^ '$Header: /cvs/stx/stx/libbasic/ArithmeticValue.st,v 1.100 2015-03-25 17:54:48 cg Exp $'
12576
47985f127034 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 11735
diff changeset
  1491
!
47985f127034 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 11735
diff changeset
  1492
47985f127034 category of:6 methods
Claus Gittinger <cg@exept.de>
parents: 11735
diff changeset
  1493
version_CVS
17662
0fd098ccf3ff class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 17336
diff changeset
  1494
    ^ '$Header: /cvs/stx/stx/libbasic/ArithmeticValue.st,v 1.100 2015-03-25 17:54:48 cg Exp $'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1495
! !
6858
13919a7544b6 raisedToInteger pushed up
Claus Gittinger <cg@exept.de>
parents: 6691
diff changeset
  1496
14747
18be9a3c2324 class: ArithmeticValue
Claus Gittinger <cg@exept.de>
parents: 14497
diff changeset
  1497
701
a309e3ef7faf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 528
diff changeset
  1498
ArithmeticValue initialize!