Class Number

Description

This is a partial port of the Squeak/Smalltalk Number class.

Class Number holds the most general methods for dealing with numbers. Subclasses Float, Fraction, and Integer, and their subclasses, provide concrete representations of a numeric quantity.

All of Number's subclasses participate in a simple type coercion mechanism that supports mixed-mode arithmetic and comparisons. It works as follows: If self<typeA> op: arg<typeB> fails because of incompatible types, then it is retried in the following guise: (arg adaptTypeA: self) op: arg adaptToTypeA. This gives the arg of typeB an opportunity to resolve the incompatibility, knowing exactly what two types are involved. If self is more general, then arg will be converted, and viceVersa. This mechanism is extensible to any new number classes that one might wish to add to Squeak. The only requirement is that every subclass of Number must support a pair of conversion methods specific to each of the other subclasses of Number.

To create new Number subclass instances, use one of the static instance-creation methods, NOT 'new Integer', etc:

    Located in /harmoni/core/Primitives/Numbers/Number.class.php (line 46)

    SObject
       |
       --Magnitude
          |
          --Number
    Direct descendents
    Class Description
    Float A simple Float data type.
    Integer A simple Integer data type.
    Method Summary
    Methods
    abs (line 208)

    Answer a Number that is the absolute value (positive magnitude) of the receiver.

    • since: 7/14/05
    • access: public
    object Number abs ()
    asDouble (line 338)

    Answer a double-precision floating-point number approximating the receiver.

    • since: 7/14/05
    • access: public
    Double asDouble ()
    asFloat (line 350)

    Answer a floating-point number approximating the receiver.

    • since: 7/14/05
    • access: public
    object Float asFloat ()
    asInteger (line 362)

    Answer an Integer nearest the receiver toward zero.

    • since: 7/14/05
    • access: public
    object Integer asInteger ()
    asNumber (line 373)

    Answer a number.

    • since: 7/14/05
    • access: public
    object Number asNumber ()
    ceiling (line 287)

    Answer the integer nearest the receiver toward positive infinity.

    • since: 7/14/05
    • access: public
    object Number ceiling ()
    dividedBy (line 164)

    Answer the result of dividing the receiver and aNumber.

    • since: 7/14/05
    • access: public
    object Number dividedBy (object Number $aNumber)

    Redefined in descendants as:
    floor (line 304)

    Answer the integer nearest the receiver toward negative infinity.

    • since: 7/14/05
    • access: public
    object Number floor ()
    fromString (line 86)

    Answer a new object with the value specified

    • since: 3/14/06
    • access: public
    object Number fromString (string $string, [optional $class = 'Number'])
    • string $string
    • optional $class: string $class The class to instantiate. Do NOT use outside of this package.

    Redefined in descendants as:
    isEqualTo (line 407)

    Answer whether the receiver and the argument are the same.

    If = is redefined in any subclass, consider also redefining the message hash.

    • since: 7/11/05
    • access: public
    boolean isEqualTo (object $anObject)
    • object $anObject

    Redefinition of:
    Magnitude::isEqualTo()
    Test if this is equal to aMagnitude.
    isLessThan (line 389)

    Test if this is less than aMagnitude.

    • since: 5/4/05
    • access: public
    boolean isLessThan (object Magnitude $aMagnitude)

    Redefinition of:
    Magnitude::isLessThan()
    Test if this is less than aMagnitude.
    minus (line 139)

    Answer the difference of the receiver and aNumber.

    • since: 7/14/05
    • access: public
    object Number minus (object Number $aNumber)
    modIntegerQuotient (line 179)

    Integer quotient defined by division with truncation toward negative infinity. 9//4 = 2, -9//4 = -3. -0.9//0.4 = -3. Modulo (\\) answers the remainder from this division.

    • since: 7/14/05
    • access: public
    object Number modIntegerQuotient (object Number $aNumber)
    modulo (line 194)

    modulo. Remainder defined in terms of the integerQutient (\\). Answer a Number with the same sign as aNumber.

    e.g. 9\\4 = 1, -9\\4 = 3, 9\\-4 = -3, 0.9\\0.4 = 0.1.

    • since: 7/14/05
    • access: public
    object Number modulo (object Number $aNumber)
    multipliedBy (line 151)

    Answer the result of multiplying the receiver and aNumber.

    • since: 7/14/05
    • access: public
    object Number multipliedBy (object Number $aNumber)

    Redefined in descendants as:
    negated (line 223)

    Answer a Number that is the negation of the receiver.

    • since: 7/14/05
    • access: public
    object Number negated ()
    plus (line 126)

    Answer the sum of the receiver and aNumber.

    • since: 7/14/05
    • access: public
    object Number plus (object Number $aNumber)

    Redefined in descendants as:
    printableString (line 427)

    Answer a String whose characters are a description of the receiver.

    Override this method as needed to provide a better representation

    • since: 7/11/05
    • access: public
    string printableString ()

    Redefinition of:
    SObject::printableString()
    Answer a String whose characters are a description of the receiver.

    Redefined in descendants as:
    reciprical (line 267)

    Answer 1 divided by the receiver. Create an error notification if the receiver is 0.

    • since: 7/14/05
    • access: public
    object Number reciprical (object Number $aNumber)
    remainder (line 253)

    Remainder defined in terms of quo:. Answer a Number with the same sign as self. e.g. 9 rem: 4 = 1, -9 rem: 4 = -1. 0.9 rem: 0.4 = 0.1.

    • since: 7/14/05
    • access: public
    object Number remainder (object Number $aNumber)
    remIntegerQuotient (line 239)

    Integer quotient defined by division with truncation toward zero.

    -9 quo: 4 = -2 -0.9 quo: 0.4 = -2. rem: answers the remainder from this division.

    • since: 7/14/05
    • access: public
    object Number remIntegerQuotient (object Number $aNumber)
    truncated (line 323)

    Answer an integer nearest the receiver toward zero.

    • since: 7/14/05
    • access: public
    object Number truncated ()
    value (line 438)

    Answer the PHP primitive value of the reciever.

    • return: may be an int, float, double, etcetera
    • since: 7/14/05
    • access: public
    mixed value ()

    Redefined in descendants as:
    withValue (line 64)

    Answer a new object with the value specified

    • since: 7/14/05
    • access: public
    object Number withValue (mixed $value, [optional $class = 'Number'])
    • mixed $value
    • optional $class: string $class The class to instantiate. Do NOT use outside of this package.

    Redefined in descendants as:
    zero (line 108)

    Answer a new object with the value zero

    • since: 7/14/05
    • access: public
    object Number zero ([optional $class = 'Number'])
    • optional $class: string $class The class to instantiate. Do NOT use outside of this package.

    Redefined in descendants as:
    _setValue (line 454)

    Set the internal value to a PHP primitive.

    • since: 7/14/05
    • access: private
    void _setValue (mixed $value)
    • mixed $value

    Redefined in descendants as:

    Inherited Methods

    Inherited From Magnitude

    Magnitude::isBetween()
    Magnitude::isEqualTo()
    Magnitude::isGreaterThan()
    Magnitude::isGreaterThanOrEqualTo()
    Magnitude::isLessThan()
    Magnitude::isLessThanOrEqualTo()
    Magnitude::max()
    Magnitude::min()

    Inherited From SObject

    SObject::asA()
    SObject::asString()
    SObject::copy()
    SObject::copySameFrom()
    SObject::copyTwoLevel()
    SObject::deepCopy()
    SObject::isEqual()
    SObject::isEqualTo()
    SObject::isNotEqualTo()
    SObject::isNotReferenceTo()
    SObject::isReferenceTo()
    SObject::newFrom()
    SObject::postCopy()
    SObject::printableString()
    SObject::shallowCopy()
    SObject::_deepCopyArray()

    Documentation generated on Wed, 19 Sep 2007 10:25:17 -0400 by phpDocumentor 1.3.0RC3