edu.vub.at.objects
Interface Numeric

All Known Subinterfaces:
Fraction, Number

 Numeric

ATNumeric is the public interface common to numbers and fractions. This interface extends ATExpression as a number or fraction can also be output by the parser as a literal.

Author:
tvc

Method Summary
 Numeric /(Numeric other)
          Division infix operator ("/").
 Boolean =(Numeric other)
          Returns true if the receiver is equal to the numeric data type passed as argument.
 Boolean >=(Numeric other)
          Returns true if the receiver is greater than or equal to the numeric data type passed as argument.
 Boolean >(Numeric other)
          Returns true if the receiver is greater than the numeric data type passed as argument.
 Numeric <=>(Numeric other)
          Generalized equality infix operator.
 Boolean <=(Numeric other)
          Returns true if the receiver is smaller than or equal to the numeric data type passed as argument.
 Boolean <(Numeric other)
          Returns true if the receiver is smaller than the numeric data type passed as argument.
 Numeric -(Numeric other)
          Subtraction infix operator.
 Boolean !=(Object other)
          Returns true if the receiver is different than the numeric data type passed as argument.
 Numeric +(Numeric other)
          Addition infix operator.
 Numeric *(Numeric other)
          Multiplication infix operator.
 Numeric addFraction(Fraction other)
          Returns the value resulting of the sum of the receiver and a fraction passed as argument.
 Numeric addNumber(Number other)
          Returns the value resulting of the sum of the receiver and a number passed as argument.
 Number ceiling()
          Returns the closest number to negative infinity that is greater than the fraction.
 Fraction cos()
          Returns the trigonometric cosine of the numeric data type representing an angle in radians.
 Numeric divideFraction(Fraction other)
          Returns the value resulting of dividing a number passed as argument by the receiver.
 Numeric divideNumber(Number other)
          Returns the value resulting of dividing a number passed as argument by the receiver.
 Fraction expt(Numeric pow)
          Returns the numeric data type raised to the power of the argument.
 Number floor()
          Returns the closest number to positive infinity that is smaller than the fraction.
 Numeric gequalsFraction(Fraction other)
          Returns the value of evaluating the generalized equality between the numeric data type and a fraction.
 Numeric gequalsNumber(Number other)
          Returns the value of evaluating the generalized equality between the numeric data type and a number.
 Fraction log()
          Returns the natural logarithm (base e) of the numeric data type.
 Number round()
          Returns the closest number to the fraction.
 Fraction sin()
          Returns the trigonometric sine of the numeric data type representing an angle in radians.
 Fraction sqrt()
          Returns the positive square root of the numeric data type.
 Numeric subtractFraction(Fraction other)
          Returns the value resulting of the subtracting the receiver from a fraction passed as argument.
 Numeric subtractNumber(Number other)
          Returns the value resulting of subtracting the receiver from a number passed as argument.
 Fraction tan()
          Returns the trigonometric tangent of the numeric data type representing an angle in radians.
 Numeric timesFraction(Fraction other)
          Returns the value resulting of multiplying the receiver by a fraction passed as argument.
 Numeric timesNumber(Number other)
          Returns the value resulting of multiplying the receiver by a number passed as argument.
 Text toText()
          Converts the numeric value into a text string.
 
Methods inherited from interface edu.vub.at.objects.AbstractGrammar
freeVariables
 
Methods inherited from interface edu.vub.at.objects.Object
super
 

Method Detail

cos

Fraction cos()
Returns the trigonometric cosine of the numeric data type representing an angle in radians.

Returns:
the cosine of the receiver.

sin

Fraction sin()
Returns the trigonometric sine of the numeric data type representing an angle in radians.

Returns:
the sine of the receiver.

tan

Fraction tan()
Returns the trigonometric tangent of the numeric data type representing an angle in radians.

Returns:
the tangent of the receiver.

log

Fraction log()
Returns the natural logarithm (base e) of the numeric data type.

Returns:
the natural logarithm of the receiver or NaN if the receiver is smaller than 0.0.

sqrt

Fraction sqrt()
Returns the positive square root of the numeric data type.

Returns:
the correctly rounded positive square root of a or NaN if the receiver is smaller than zero.

round

Number round()
Returns the closest number to the fraction.

More specifically, rounding a number is equivalent to (fraction + 0.5).floor()

Returns:
an ATNumber resulting of rounding the receiver to the closest number value.

floor

Number floor()
Returns the closest number to positive infinity that is smaller than the fraction.

Returns:
the closest number to positive infinity that is smaller than the fraction.

ceiling

Number ceiling()
Returns the closest number to negative infinity that is greater than the fraction.

Returns:
the closest number to negative infinity that is greater than the fraction.

expt

Fraction expt(Numeric pow)
Returns the numeric data type raised to the power of the argument.

Parameters:
pow - a ATNumeric data type representing the exponent.
Returns:
the receiver raised to the power of the argument.
Throws:
XTypeMismatch - if the exponent is not an ATNumeric object.

+

Numeric +(Numeric other)
Addition infix operator. Returns the value resulting of the sum of the receiver and another numeric data type passed as argument.

More specifically, this operator actually calls:

Parameters:
other - a numeric data type.
Returns:
a ATNumeric resulting of the sum of the receiver and other.

addNumber

Numeric addNumber(Number other)
Returns the value resulting of the sum of the receiver and a number passed as argument.

More specifically, this method returns a Number if both numeric data types to sum are Number objects. Otherwise, an Fraction is returned.

Note that this is a double-dispatch method used to determine the correct runtime type of both arguments of the addition operator.

Parameters:
other - a number.
Returns:
a ATNumeric resulting of the sum of the receiver and other.
Throws:
XTypeMismatch - if other is not an ATNumber object.

addFraction

Numeric addFraction(Fraction other)
Returns the value resulting of the sum of the receiver and a fraction passed as argument.

Note that this is a double-dispatch method used to determine the correct runtime type of both arguments of the addition operator.

Parameters:
other - a fraction.
Returns:
a Fraction resulting of the sum of the receiver and other.
Throws:
XTypeMismatch - if other is not an ATFraction object.

-

Numeric -(Numeric other)
Subtraction infix operator. Returns the value resulting of subtracting a numeric data type passed as argument from the receiver.

More specifically, this operator actually calls:

Parameters:
other - a numeric data type.
Returns:
a ATNumeric resulting of subtracting other from the receiver.

subtractNumber

Numeric subtractNumber(Number other)
Returns the value resulting of subtracting the receiver from a number passed as argument.

More specifically, this method returns a Number if both numeric data types to subtract are Number objects. Otherwise, an Fraction is returned.

Note that this is a double-dispatch method used to determine the correct runtime type of both arguments of the subtraction operator.

Parameters:
other - a number.
Returns:
a ATNumeric resulting of subtracting other from the receiver.
Throws:
XTypeMismatch - if other is not an ATNumber object.

subtractFraction

Numeric subtractFraction(Fraction other)
Returns the value resulting of the subtracting the receiver from a fraction passed as argument.

Note that this is a double-dispatch method used to determine the correct runtime type of both arguments of the subtraction operator.

Parameters:
other - a fraction.
Returns:
a Fraction resulting of subtracting other from the receiver.
Throws:
XTypeMismatch - if other is not an ATFraction object.

*

Numeric *(Numeric other)
Multiplication infix operator. Returns the value resulting of multiplying the receiver by another numeric data type passed as argument.

More specifically, this operator actually calls:

Parameters:
other - a numeric data type.
Returns:
a ATNumeric resulting of multiplying the receiver by other.

timesNumber

Numeric timesNumber(Number other)
Returns the value resulting of multiplying the receiver by a number passed as argument.

More specifically, this method returns a Number if both numeric data types to multiply are Number objects. Otherwise, an Fraction is returned.

Note that this is a double-dispatch method used to determine the correct runtime type of both arguments of the multiplication operator.

Parameters:
other - a number.
Returns:
a ATNumeric resulting of multiplying the receiver by other.
Throws:
XTypeMismatch - if other is not an ATNumber object.

timesFraction

Numeric timesFraction(Fraction other)
Returns the value resulting of multiplying the receiver by a fraction passed as argument.

Note that this is a double-dispatch method used to determine the correct runtime type of both arguments of the multiplication operator.

Parameters:
other - a fraction.
Returns:
a Fraction resulting of multiplying the receiver by other.
Throws:
XTypeMismatch - if other is not an ATFraction object.

/

Numeric /(Numeric other)
Division infix operator ("/"). Returns the value resulting of dividing the receiver by another numeric data type passed as argument.

More specifically, this operator actually calls:

Parameters:
other - a numeric data type.
Returns:
a ATNumeric resulting of dividing the receiver by other.

divideNumber

Numeric divideNumber(Number other)
Returns the value resulting of dividing a number passed as argument by the receiver.

More specifically, this method returns a Number if both numeric data types to multiply are Number objects. Otherwise, an Fraction is returned.

Note that this is a double-dispatch method used to determine the correct runtime type of both arguments of the division operator.

Parameters:
other - a number.
Returns:
a ATNumeric resulting of dividing a given number by the receiver.
Throws:
XTypeMismatch - if other is not an ATNumber object.
XIllegalArgument - if the receiver is 0.

divideFraction

Numeric divideFraction(Fraction other)
Returns the value resulting of dividing a number passed as argument by the receiver.

Note that this is a double-dispatch method used to determine the correct runtime type of both arguments of the division operator.

Parameters:
other - a fraction.
Returns:
a Fraction resulting of dividing a given number by the receiver.
Throws:
XTypeMismatch - if other is not an ATFraction object.
XIllegalArgument - if the receiver is 0.

<=>

Numeric <=>(Numeric other)
Generalized equality infix operator. Returns:

This method actually calls:

Parameters:
other - a numeric data type.
Returns:
a ATNumber resulting of evaluating the generalized equality between the receiver and other.

gequalsNumber

Numeric gequalsNumber(Number other)
Returns the value of evaluating the generalized equality between the numeric data type and a number.

The generalized equality returns:

Note that this is a double-dispatch method used to determine the correct runtime type of both arguments of the generalized equality operator.

Parameters:
other - a number.
Returns:
a Number resulting of applying the generalized equality between the receiver and other.
Throws:
XTypeMismatch - if other is not an ATNumber object.

gequalsFraction

Numeric gequalsFraction(Fraction other)
Returns the value of evaluating the generalized equality between the numeric data type and a fraction.

The generalized equality returns:

Note that this is a double-dispatch method used to determine the correct runtime type of both arguments of the generalized equality operator.

Parameters:
other - a number.
Returns:
a Number resulting of applying the generalized equality between the receiver and other.
Throws:
XTypeMismatch - if other is not an ATFraction object.

<

Boolean <(Numeric other)
Returns true if the receiver is smaller than the numeric data type passed as argument.

Parameters:
other - a numeric data type.
Returns:
a Boolean resulting of evaluating (receiver <=> other) == -1
Throws:
XTypeMismatch - if other is not an ATNumeric object.

>

Boolean >(Numeric other)
Returns true if the receiver is greater than the numeric data type passed as argument.

Parameters:
other - a numeric data type.
Returns:
a Boolean resulting of evaluating (receiver <=> other) == 1
Throws:
XTypeMismatch - if other is not an ATNumeric object.

<=

Boolean <=(Numeric other)
Returns true if the receiver is smaller than or equal to the numeric data type passed as argument.

Parameters:
other - a numeric data type.
Returns:
a Boolean resulting of evaluating (receiver <=> other) != 1
Throws:
XTypeMismatch - if other is not an ATNumeric object.

>=

Boolean >=(Numeric other)
Returns true if the receiver is greater than or equal to the numeric data type passed as argument.

Parameters:
other - a numeric data type.
Returns:
a Boolean resulting of evaluating (receiver <=> other) != -1
Throws:
XTypeMismatch - if other is not an ATNumeric object.

=

Boolean =(Numeric other)
Returns true if the receiver is equal to the numeric data type passed as argument.

Parameters:
other - a numeric data type.
Returns:
a Boolean resulting of evaluating (receiver <=> other) == 0
Throws:
XTypeMismatch - if other is not an ATNumeric object.

!=

Boolean !=(Object other)
Returns true if the receiver is different than the numeric data type passed as argument.

Parameters:
other - an object which compared to this one only if it is a numeric data type.
Returns:
a Boolean resulting of evaluating (receiver <=> other) != 0
Throws:
XTypeMismatch - if other is not an ATNumeric object.

toText

Text toText()
Converts the numeric value into a text string.

Returns:
a text (an AmbientTalk string) encoding a decimal representation of the numeric value.