|
|
Class: ArithmeticValue
Object
|
+--Magnitude
|
+--ArithmeticValue
|
+--Number
|
+--Point
- Package:
- stx:libbasic
- Category:
- Magnitude-Numbers
- Version:
- rev:
1.85
date: 2010/03/06 10:06:53
- user: cg
- file: ArithmeticValue.st directory: libbasic
- module: stx stc-classLibrary: libbasic
- Author:
- Claus Gittinger
ArithmeticValue is an abstract superclass for all things responding to
arithmetic messages. It was inserted into the hierarchy, to allow objects
like matrices, functions etc. to share the arithmetic methods defined here.
Notice, that what used to be signals are now exception classes - the class
variables and signal accessors remain here for backward compatibility.
[class variables:]
ArithmeticSignal <Error> parent of all arithmetic signals
(never raised itself)
New: now a reference to ArithmeticError
DomainErrorSignal <Error> raised upon float errors
(for example range in trigonometric)
New: now a reference to DomainError
DivisionByZeroSignal <Error> raised when division by 0 is attempted
New: now a reference to ZeroDivide
OverflowSignal <Error> raised on overflow/underflow conditions
UnderflowSignal in float arithmetic.
Notice: some OperatingSystems do not
provide enough information for ST/X to
extract the real reason for the floatException
thus raising DomainErrorSignal in these cases.
Number
Signal constants
-
arithmeticSignal
-
return the parent of all arithmetic signals
-
divisionByZeroSignal
-
return the signal which is raised on division by zero
-
domainErrorSignal
-
return the signal which is raised on math errors
(such as log of 0 etc.)
-
imaginaryResultSignal
-
return the signal which is raised when an imaginary result would be created
(such as when taking the sqrt of a negative number)
-
operationNotPossibleSignal
-
-
overflowSignal
-
return the signal which is raised on overflow conditions (in floats)
-
rangeErrorSignal
-
return the parent of the overflow/underflow signals
-
undefinedResultSignal
-
-
underflowSignal
-
return the signal which is raised on underflow conditions (in floats)
-
unorderedSignal
-
return the signal which is raised when numbers are compared,
for which no ordering is defined (for example: complex numbers)
class initialization
-
initialize
-
setup the signals
constants
-
NaN
-
return the constant NaN (not a Number).
-
infinity
-
return something which represents infinity (for my instances)
-
nan
-
VW compatibility
-
negativeInfinity
-
return something which represents negative infinity (for my instances)
-
unity
-
return something which represents the unity element (for my instances).
That is the neutral element for multiplication.
** This method raises an error - it must be redefined in concrete classes **
-
zero
-
return something which represents the zero element (for my instances).
That is the neutral element for addition.
** This method raises an error - it must be redefined in concrete classes **
queries
-
isAbstract
-
Return if this class is an abstract class.
True is returned for ArithmeticValue here; false for subclasses.
Abstract subclasses must redefine again.
JavaScript support
-
js_add: aNumber
-
For JavaScript only:
Generated for +-operator in javascript.
arithmetic
-
* something
-
return the product of the receiver and the argument.
** This method raises an error - it must be redefined in concrete classes **
-
+ something
-
return the sum of the receiver and the argument
** This method raises an error - it must be redefined in concrete classes **
-
- something
-
return the difference of the receiver and the argument
** This method raises an error - it must be redefined in concrete classes **
-
/ something
-
return the quotient of the receiver and the argument
** This method raises an error - it must be redefined in concrete classes **
-
// something
-
return the integer quotient of dividing the receiver by aNumber with
truncation towards negative infinity.
** This method raises an error - it must be redefined in concrete classes **
-
\\ something
-
return the receiver modulo something.
The remainder has the same sign as something.
The following is always true:
(receiver // something) * something + (receiver \\ something) = receiver
-
abs
-
return the absolute value of the receiver
-
dist: arg
-
return the distance between arg and the receiver.
-
negated
-
return the receiver negated
-
quo: something
-
Return the integer quotient of dividing the receiver by the argument
with truncation towards zero.
The following is always true:
(receiver quo: aNumber) * aNumber + (receiver rem: aNumber) = receiver
-
reciprocal
-
return the receivers reciprocal
-
rem: something
-
Return the integer remainder of dividing the receiver by the argument
with truncation towards zero.
The remainder has the same sign as the receiver.
The following is always true:
(receiver quo: something) * something + (receiver rem: something) = receiver
-
uncheckedDivide: aNumber
-
return the quotient of the receiver and the argument, aNumber.
Do not check for divide by zero (return NaN or Infinity).
This operation is provided for emulators of other languages/semantics,
where no exception is raised for these results (i.e. Java).
Its only defined if the arguments type is the same as the receivers.
arithmetic destructive
-
*= aNumber
-
Return the product of self multiplied by aNumber.
The receiver MAY, but NEED NOT be changed to contain the product.
So this method must be used as: 'a := a *= 5'.
This method can be redefined for constructed datatypes to do optimisations
-
+= aNumber
-
Return the sum of self and aNumber.
The receiver MAY, but NEED NOT be changed to contain the sum.
So this method must be used as: 'a := a += 5'.
This method can be redefined for constructed datatypes to do optimisations
-
-= aNumber
-
Return the difference of self and aNumber.
The receiver MAY, but NEED NOT be changed to contain the difference.
So this method must be used as: 'a := a -= 5'.
This method can be redefined for constructed datatypes to do optimisations
-
/= aNumber
-
Return the quotient of self and aNumber.
The receiver MAY, but NEED NOT be changed to contain the quotient.
So this method must be used as: 'a := a /= 5'.
This method can be redefined for constructed datatypes to do optimisations
-
div2
-
Return the quotient of self divided by 2.
The receiver MAY, but NEED NOT be changed to contain the result.
So this method must be used as: 'a := a div2.
This method can be redefined for constructed datatypes to do optimisations
-
mul2
-
Return the product of self multiplied by 2.
The receiver MAY, but NEED NOT be changed to contain the result.
So this method must be used as: 'a := a mul2.
This method can be redefined for constructed datatypes to do optimisations
coercing & converting
-
coerce: aNumber
-
convert the argument aNumber into an instance of the receivers class and return it.
** This method raises an error - it must be redefined in concrete classes **
-
generality
-
return a number giving the receivers generality, that number is
used to convert one of the arguments in a mixed expression.
The generality has to be defined in subclasses,
such that gen(a) > gen(b) iff, conversion of b into a's class
does not cut precision. For example, Integer has 40, Float has 80,
meaning that if we convert a Float to an Integer, some precision may
be lost. The generality is used by ArithmeticValue>>retry:coercing:,
which converts the lower-precision number to the higher precision
numbers class, when mixed-type arithmetic is performed.
** This method raises an error - it must be redefined in concrete classes **
-
retry: aSymbol coercing: aNumber
-
arithmetic represented by the binary operator, aSymbol,
could not be performed with the receiver and the argument, aNumber,
because of the differences in representation.
Coerce either the receiver or the argument, depending on which has higher
generality, and try again.
If the operation is compare for same value (=), return false if
the argument is not a Number.
If the generalities are the same, create an error message, since this
means that a subclass has not been fully implemented.
converting
-
asDouble
-
ST80 compatibility: return a double with receivers value.
our floats are the identical to ST80 doubles
-
asFixedPoint
-
return the receiver as fixedPoint number.
Q: what should the scale be here ?
-
asFixedPoint: scale
-
return the receiver as fixedPoint number with the given
number of post-decimal-digits.
-
asFloat
-
return a float with same value
** This method raises an error - it must be redefined in concrete classes **
-
asFloatD
-
return a double precision float with same value.
Added for ANSI compatibility
-
asFloatE
-
return a single precision float with same value.
Added for ANSI compatibility
-
asFloatQ
-
return a quad precision float with same value.
Added for ANSI compatibility
-
asFraction
-
return a fraction with same value
** This method raises an error - it must be redefined in concrete classes **
-
asInteger
-
return an integer with same value - might truncate
-
asLimitedPrecisionReal
-
return a float of any precision with same value
-
asLongFloat
-
return a longFloat with same value
-
asScaledDecimal: scale
-
return a fixedPoint approximating the receivers value
-
asShortFloat
-
return a shortFloat with same value
-
degreesToRadians
-
interpreting the receiver as radians, return the degrees
-
radiansToDegrees
-
interpreting the receiver as degrees, return the radians
double dispatching
-
differenceFromComplex: aComplex
-
the receiver does not know how to subtract from a complex -
retry the operation by coercing to higher generality
-
differenceFromFixedPoint: aFixedPoint
-
the receiver does not know how to subtract from a fixedPoint number -
retry the operation by coercing to higher generality
-
differenceFromFloat: aFloat
-
the receiver does not know how to subtract from a float -
retry the operation by coercing to higher generality
-
differenceFromFraction: aFraction
-
the receiver does not know how to subtract from a fraction -
retry the operation by coercing to higher generality
-
differenceFromInteger: anInteger
-
the receiver does not know how to subtract from an integer -
retry the operation by coercing to higher generality
-
differenceFromLargeFloat: aLargeFloat
-
the receiver does not know how to subtract from a largeFloat -
retry the operation by coercing to higher generality
-
differenceFromLongFloat: aLongFloat
-
the receiver does not know how to subtract from a longFloat -
retry the operation by coercing to higher generality
-
differenceFromShortFloat: aShortFloat
-
the receiver does not know how to subtract from a shortFloat -
retry the operation by coercing to higher generality
-
equalFromComplex: aComplex
-
the receiver does not know how to compare to a complex number -
retry the operation by coercing to higher generality
-
equalFromFixedPoint: aFixedPoint
-
the receiver does not know how to compare to a fixed point -
retry the operation by coercing to higher generality
-
equalFromFloat: aFloat
-
the receiver does not know how to compare to a float -
retry the operation by coercing to higher generality
-
equalFromFraction: aFraction
-
the receiver does not know how to compare to a fraction -
retry the operation by coercing to higher generality
-
equalFromInteger: anInteger
-
the receiver does not know how to compare to an integer -
retry the operation by coercing to higher generality
-
equalFromLargeFloat: aLargeFloat
-
the receiver does not know how to compare to a large float -
retry the operation by coercing to higher generality
-
equalFromLongFloat: aLongFloat
-
the receiver does not know how to compare to a long float -
retry the operation by coercing to higher generality
-
equalFromShortFloat: aShortFloat
-
the receiver does not know how to compare to a short float -
retry the operation by coercing to higher generality
-
lessFromFixedPoint: aFixedPoint
-
the receiver does not know how to compare to a fixedPoint number -
retry the operation by coercing to higher generality
-
lessFromFloat: aFloat
-
the receiver does not know how to compare to a float -
retry the operation by coercing to higher generality
-
lessFromFraction: aFraction
-
the receiver does not know how to compare to a fraction -
retry the operation by coercing to higher generality
-
lessFromInteger: anInteger
-
the receiver does not know how to compare to an integer -
retry the operation by coercing to higher generality
-
lessFromLargeFloat: aLargeFloat
-
the receiver does not know how to compare to a largeFloat -
retry the operation by coercing to higher generality
-
lessFromLongFloat: aLongFloat
-
the receiver does not know how to compare to a longFloat -
retry the operation by coercing to higher generality
-
lessFromShortFloat: aShortFloat
-
the receiver does not know how to compare to a shortFloat -
retry the operation by coercing to higher generality
-
productFromComplex: aComplex
-
the receiver does not know how to multiply a complex -
retry the operation by coercing to higher generality
-
productFromFixedPoint: aFixedPoint
-
the receiver does not know how to multiply a fixed point number -
retry the operation by coercing to higher generality
-
productFromFloat: aFloat
-
the receiver does not know how to multiply a float -
retry the operation by coercing to higher generality
-
productFromFraction: aFraction
-
the receiver does not know how to multiply a fraction -
retry the operation by coercing to higher generality
-
productFromInteger: anInteger
-
the receiver does not know how to multiply an integer -
retry the operation by coercing to higher generality
-
productFromLargeFloat: aLargeFloat
-
the receiver does not know how to multiply a largeFloat -
retry the operation by coercing to higher generality
-
productFromLongFloat: aLongFloat
-
the receiver does not know how to multiply a longFloat -
retry the operation by coercing to higher generality
-
productFromShortFloat: aShortFloat
-
the receiver does not know how to multiply a shortFloat -
retry the operation by coercing to higher generality
-
quotientFromComplex: aComplex
-
aComplex does not know how to divide by the receiver -
retry the operation by coercing to higher generality
-
quotientFromFixedPoint: aFixedPoint
-
aFixedPoint does not know how to divide by the receiver -
retry the operation by coercing to higher generality
-
quotientFromFloat: aFloat
-
aFloat does not know how to divide by the receiver -
retry the operation by coercing to higher generality
-
quotientFromFraction: aFraction
-
aFraction does not know how to divide by the receiver -
retry the operation by coercing to higher generality
-
quotientFromInteger: anInteger
-
anInteger does not know how to divide by the receiver -
retry the operation by coercing to higher generality
-
quotientFromLargeFloat: aLargeFloat
-
aLargeFloat does not know how to divide by the receiver -
retry the operation by coercing to higher generality
-
quotientFromLongFloat: aLongFloat
-
aLongFloat does not know how to divide by the receiver -
retry the operation by coercing to higher generality
-
quotientFromShortFloat: aShortFloat
-
aShortFloat does not know how to divide by the receiver -
retry the operation by coercing to higher generality
-
sumFromComplex: aComplex
-
the receiver does not know how to add a complex -
retry the operation by coercing to higher generality
-
sumFromFixedPoint: aFixedPoint
-
the receiver does not know how to add a fixed point number -
retry the operation by coercing to higher generality
-
sumFromFloat: aFloat
-
the receiver does not know how to add a float -
retry the operation by coercing to higher generality
-
sumFromFraction: aFraction
-
the receiver does not know how to add a fraction -
retry the operation by coercing to higher generality
-
sumFromInteger: anInteger
-
the receiver does not know how to add an integer -
retry the operation by coercing to higher generality
-
sumFromLargeFloat: aLargeFloat
-
the receiver does not know how to add a largeFloat -
retry the operation by coercing to higher generality
-
sumFromLongFloat: aLongFloat
-
the receiver does not know how to add a longFloat -
retry the operation by coercing to higher generality
-
sumFromShortFloat: aShortFloat
-
the receiver does not know how to add a shortFloat -
retry the operation by coercing to higher generality
mathematical functions
-
** aNumber
-
Answer the receiver raised to the power of the argument, aNumber.
-
raisedTo: aNumber
-
** This method raises an error - it must be redefined in concrete classes **
-
raisedToInteger: exp
-
return the receiver raised to exp
-
squared
-
return receiver * receiver
queries
-
respondsToArithmetic
-
return true, if the receiver responds to arithmetic messages
testing
-
denominator
-
return the denominator of the receiver
-
even
-
return true if the receiver is divisible by 2
-
isComplex
-
Answer whether the receiver has an imaginary part
(i.e. if it is a complex number). Always false here.
-
isFinite
-
return true, if the receiver is finite
i.e. it can be represented as a rational number.
-
isInfinite
-
-
isNegativeInfinity
-
-
isNegativeZero
-
return false - must be redefined by subclasses which can represent a negative zero
(i.e. limitedPrecisionReal classes)
-
isPositiveInfinity
-
-
isReal
-
return true, if the receiver is some kind of real number (as opposed to a complex);
false is returned here - the method is only redefined in Number (and Complex).
-
isZero
-
return false - must be redefined by subclasses which can represent a negative zero
(i.e. limitedPrecisionReal classes)
-
negative
-
return true if the receiver is less than zero
-
numerator
-
return the numerator of the receiver.
-
odd
-
return true if the receiver is not divisible by 2
-
positive
-
return true, if the receiver is >= 0
-
sign
-
return the sign of the receiver (-1, 0 or 1)
-
strictlyPositive
-
return true, if the receiver is > 0
truncation & rounding
-
ceiling
-
return the integer nearest the receiver towards positive infinity.
-
floor
-
return the receiver truncated towards negative infinity
-
roundTo: aNumber
-
return the receiver rounded to multiples of aNumber
-
roundUpTo: aNumber
-
return the receiver rounded up to the next multiple of aNumber
-
rounded
-
return the integer nearest the receiver
-
truncateTo: aNumber
-
return the receiver truncated to multiples of aNumber
-
truncated
-
return the receiver truncated towards zero
|