eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'ArithmeticValue':

Home

everywhere
www.exept.de
for:
[back]

Class: ArithmeticValue


Inheritance:

   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

Description:


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.


Related information:

    Number

Class protocol:

Signal constants
o  arithmeticSignal
return the parent of all arithmetic signals

o  divisionByZeroSignal
return the signal which is raised on division by zero

o  domainErrorSignal
return the signal which is raised on math errors
(such as log of 0 etc.)

o  imaginaryResultSignal
return the signal which is raised when an imaginary result would be created
(such as when taking the sqrt of a negative number)

o  operationNotPossibleSignal

o  overflowSignal
return the signal which is raised on overflow conditions (in floats)

o  rangeErrorSignal
return the parent of the overflow/underflow signals

o  undefinedResultSignal

o  underflowSignal
return the signal which is raised on underflow conditions (in floats)

o  unorderedSignal
return the signal which is raised when numbers are compared,
for which no ordering is defined (for example: complex numbers)

class initialization
o  initialize
setup the signals

constants
o  NaN
return the constant NaN (not a Number).

o  infinity
return something which represents infinity (for my instances)

o  nan
VW compatibility

o  negativeInfinity
return something which represents negative infinity (for my instances)

o  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 **

o  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
o  isAbstract
Return if this class is an abstract class.
True is returned for ArithmeticValue here; false for subclasses.
Abstract subclasses must redefine again.


Instance protocol:

JavaScript support
o  js_add: aNumber
For JavaScript only:
Generated for +-operator in javascript.

arithmetic
o  * something
return the product of the receiver and the argument.

** This method raises an error - it must be redefined in concrete classes **

o  + something
return the sum of the receiver and the argument

** This method raises an error - it must be redefined in concrete classes **

o  - something
return the difference of the receiver and the argument

** This method raises an error - it must be redefined in concrete classes **

o  / something
return the quotient of the receiver and the argument

** This method raises an error - it must be redefined in concrete classes **

o  // 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 **

o  \\ 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

o  abs
return the absolute value of the receiver

o  dist: arg
return the distance between arg and the receiver.

o  negated
return the receiver negated

o  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

o  reciprocal
return the receivers reciprocal

o  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

o  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
o  *= 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

o  += 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

o  -= 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

o  /= 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

o  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

o  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
o  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 **

o  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 **

o  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
o  asDouble
ST80 compatibility: return a double with receivers value.
our floats are the identical to ST80 doubles

o  asFixedPoint
return the receiver as fixedPoint number.
Q: what should the scale be here ?

o  asFixedPoint: scale
return the receiver as fixedPoint number with the given
number of post-decimal-digits.

o  asFloat
return a float with same value

** This method raises an error - it must be redefined in concrete classes **

o  asFloatD
return a double precision float with same value.
Added for ANSI compatibility

o  asFloatE
return a single precision float with same value.
Added for ANSI compatibility

o  asFloatQ
return a quad precision float with same value.
Added for ANSI compatibility

o  asFraction
return a fraction with same value

** This method raises an error - it must be redefined in concrete classes **

o  asInteger
return an integer with same value - might truncate

o  asLimitedPrecisionReal
return a float of any precision with same value

o  asLongFloat
return a longFloat with same value

o  asScaledDecimal: scale
return a fixedPoint approximating the receivers value

o  asShortFloat
return a shortFloat with same value

o  degreesToRadians
interpreting the receiver as radians, return the degrees

o  radiansToDegrees
interpreting the receiver as degrees, return the radians

double dispatching
o  differenceFromComplex: aComplex
the receiver does not know how to subtract from a complex -
retry the operation by coercing to higher generality

o  differenceFromFixedPoint: aFixedPoint
the receiver does not know how to subtract from a fixedPoint number -
retry the operation by coercing to higher generality

o  differenceFromFloat: aFloat
the receiver does not know how to subtract from a float -
retry the operation by coercing to higher generality

o  differenceFromFraction: aFraction
the receiver does not know how to subtract from a fraction -
retry the operation by coercing to higher generality

o  differenceFromInteger: anInteger
the receiver does not know how to subtract from an integer -
retry the operation by coercing to higher generality

o  differenceFromLargeFloat: aLargeFloat
the receiver does not know how to subtract from a largeFloat -
retry the operation by coercing to higher generality

o  differenceFromLongFloat: aLongFloat
the receiver does not know how to subtract from a longFloat -
retry the operation by coercing to higher generality

o  differenceFromShortFloat: aShortFloat
the receiver does not know how to subtract from a shortFloat -
retry the operation by coercing to higher generality

o  equalFromComplex: aComplex
the receiver does not know how to compare to a complex number -
retry the operation by coercing to higher generality

o  equalFromFixedPoint: aFixedPoint
the receiver does not know how to compare to a fixed point -
retry the operation by coercing to higher generality

o  equalFromFloat: aFloat
the receiver does not know how to compare to a float -
retry the operation by coercing to higher generality

o  equalFromFraction: aFraction
the receiver does not know how to compare to a fraction -
retry the operation by coercing to higher generality

o  equalFromInteger: anInteger
the receiver does not know how to compare to an integer -
retry the operation by coercing to higher generality

o  equalFromLargeFloat: aLargeFloat
the receiver does not know how to compare to a large float -
retry the operation by coercing to higher generality

o  equalFromLongFloat: aLongFloat
the receiver does not know how to compare to a long float -
retry the operation by coercing to higher generality

o  equalFromShortFloat: aShortFloat
the receiver does not know how to compare to a short float -
retry the operation by coercing to higher generality

o  lessFromFixedPoint: aFixedPoint
the receiver does not know how to compare to a fixedPoint number -
retry the operation by coercing to higher generality

o  lessFromFloat: aFloat
the receiver does not know how to compare to a float -
retry the operation by coercing to higher generality

o  lessFromFraction: aFraction
the receiver does not know how to compare to a fraction -
retry the operation by coercing to higher generality

o  lessFromInteger: anInteger
the receiver does not know how to compare to an integer -
retry the operation by coercing to higher generality

o  lessFromLargeFloat: aLargeFloat
the receiver does not know how to compare to a largeFloat -
retry the operation by coercing to higher generality

o  lessFromLongFloat: aLongFloat
the receiver does not know how to compare to a longFloat -
retry the operation by coercing to higher generality

o  lessFromShortFloat: aShortFloat
the receiver does not know how to compare to a shortFloat -
retry the operation by coercing to higher generality

o  productFromComplex: aComplex
the receiver does not know how to multiply a complex -
retry the operation by coercing to higher generality

o  productFromFixedPoint: aFixedPoint
the receiver does not know how to multiply a fixed point number -
retry the operation by coercing to higher generality

o  productFromFloat: aFloat
the receiver does not know how to multiply a float -
retry the operation by coercing to higher generality

o  productFromFraction: aFraction
the receiver does not know how to multiply a fraction -
retry the operation by coercing to higher generality

o  productFromInteger: anInteger
the receiver does not know how to multiply an integer -
retry the operation by coercing to higher generality

o  productFromLargeFloat: aLargeFloat
the receiver does not know how to multiply a largeFloat -
retry the operation by coercing to higher generality

o  productFromLongFloat: aLongFloat
the receiver does not know how to multiply a longFloat -
retry the operation by coercing to higher generality

o  productFromShortFloat: aShortFloat
the receiver does not know how to multiply a shortFloat -
retry the operation by coercing to higher generality

o  quotientFromComplex: aComplex
aComplex does not know how to divide by the receiver -
retry the operation by coercing to higher generality

o  quotientFromFixedPoint: aFixedPoint
aFixedPoint does not know how to divide by the receiver -
retry the operation by coercing to higher generality

o  quotientFromFloat: aFloat
aFloat does not know how to divide by the receiver -
retry the operation by coercing to higher generality

o  quotientFromFraction: aFraction
aFraction does not know how to divide by the receiver -
retry the operation by coercing to higher generality

o  quotientFromInteger: anInteger
anInteger does not know how to divide by the receiver -
retry the operation by coercing to higher generality

o  quotientFromLargeFloat: aLargeFloat
aLargeFloat does not know how to divide by the receiver -
retry the operation by coercing to higher generality

o  quotientFromLongFloat: aLongFloat
aLongFloat does not know how to divide by the receiver -
retry the operation by coercing to higher generality

o  quotientFromShortFloat: aShortFloat
aShortFloat does not know how to divide by the receiver -
retry the operation by coercing to higher generality

o  sumFromComplex: aComplex
the receiver does not know how to add a complex -
retry the operation by coercing to higher generality

o  sumFromFixedPoint: aFixedPoint
the receiver does not know how to add a fixed point number -
retry the operation by coercing to higher generality

o  sumFromFloat: aFloat
the receiver does not know how to add a float -
retry the operation by coercing to higher generality

o  sumFromFraction: aFraction
the receiver does not know how to add a fraction -
retry the operation by coercing to higher generality

o  sumFromInteger: anInteger
the receiver does not know how to add an integer -
retry the operation by coercing to higher generality

o  sumFromLargeFloat: aLargeFloat
the receiver does not know how to add a largeFloat -
retry the operation by coercing to higher generality

o  sumFromLongFloat: aLongFloat
the receiver does not know how to add a longFloat -
retry the operation by coercing to higher generality

o  sumFromShortFloat: aShortFloat
the receiver does not know how to add a shortFloat -
retry the operation by coercing to higher generality

mathematical functions
o  ** aNumber
Answer the receiver raised to the power of the argument, aNumber.

o  raisedTo: aNumber

** This method raises an error - it must be redefined in concrete classes **

o  raisedToInteger: exp
return the receiver raised to exp

o  squared
return receiver * receiver

queries
o  respondsToArithmetic
return true, if the receiver responds to arithmetic messages

testing
o  denominator
return the denominator of the receiver

o  even
return true if the receiver is divisible by 2

o  isComplex
Answer whether the receiver has an imaginary part
(i.e. if it is a complex number). Always false here.

o  isFinite
return true, if the receiver is finite
i.e. it can be represented as a rational number.

o  isInfinite

o  isNegativeInfinity

o  isNegativeZero
return false - must be redefined by subclasses which can represent a negative zero
(i.e. limitedPrecisionReal classes)

o  isPositiveInfinity

o  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).

o  isZero
return false - must be redefined by subclasses which can represent a negative zero
(i.e. limitedPrecisionReal classes)

o  negative
return true if the receiver is less than zero

o  numerator
return the numerator of the receiver.

o  odd
return true if the receiver is not divisible by 2

o  positive
return true, if the receiver is >= 0

o  sign
return the sign of the receiver (-1, 0 or 1)

o  strictlyPositive
return true, if the receiver is > 0

truncation & rounding
o  ceiling
return the integer nearest the receiver towards positive infinity.

o  floor
return the receiver truncated towards negative infinity

o  roundTo: aNumber
return the receiver rounded to multiples of aNumber

o  roundUpTo: aNumber
return the receiver rounded up to the next multiple of aNumber

o  rounded
return the integer nearest the receiver

o  truncateTo: aNumber
return the receiver truncated to multiples of aNumber

o  truncated
return the receiver truncated towards zero



ST/X 6.1.1; WebServer 1.620 at exept:8081; Wed, 23 May 2012 07:48:26 GMT