Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Interface nl.coffee.math.RationalNumber

Subinterfaces:
IntegerNumber
Implementing Classes:
AbstractRationalNumber

public abstract interface RationalNumber
extends RealNumber
An immutable rational number. This interface provides the base for all rational numbers. It extends the RealNumber interface by offering narrowed numeric computations for rational numbers.

All rational values can be written as a fraction x/y, where both x and y are integer numbers.

RationalNumber derivates must obey these rules:

Some RationalNumber numeric computations are narrowed compared to their more general RealNumber equivalents. For instance, adding two rational numbers will result in a rational number. The computations concerned are:

Since:
JUMP_1.0
Version:
1.1 199809.24
Author:
Ernst de Haan

Method Summary
RationalNumber add(RationalNumber n)
          Computes this+n, where n is a rational number.
int compareTo(RationalNumber n)
           
RationalNumber divide(RationalNumber n)
          Computes this/n, where n is a rational number.
IntegerNumber getDenominator()
          Returns the denominator of this fraction.
IntegerNumber getNumerator()
          Returns the numerator of this fraction.
RationalNumber multiply(RationalNumber n)
          Computes this*n, where n is a rational number.
RationalNumber pow(IntegerNumber n)
          Computes this**n, where n is an integer number.
RationalNumber subtract(RationalNumber n)
          Computes this-n, where n is a rational number.
 

Method Detail

compareTo

public int compareTo(RationalNumber n)
             throws java.lang.IllegalArgumentException

add

public RationalNumber add(RationalNumber n)
                                 throws java.lang.IllegalArgumentException
Computes this+n, where n is a rational number.
Parameters:
n - the number to add to this.
Returns:
the sum of this and n.
Throws:
java.lang.IllegalArgumentException - if n == null.

subtract

public RationalNumber subtract(RationalNumber n)
                                      throws java.lang.IllegalArgumentException
Computes this-n, where n is a rational number.
Parameters:
n - the number to subtract from this.
Returns:
this minus n.
Throws:
java.lang.IllegalArgumentException - if n == null.

multiply

public RationalNumber multiply(RationalNumber n)
                                      throws java.lang.IllegalArgumentException
Computes this*n, where n is a rational number.
Parameters:
n - the number to multiply this by.
Returns:
the product of this and n.
Throws:
java.lang.IllegalArgumentException - if n == null.

divide

public RationalNumber divide(RationalNumber n)
                                    throws java.lang.IllegalArgumentException,
                                           java.lang.ArithmeticException
Computes this/n, where n is a rational number.
Parameters:
n - the number to divide this by.
Returns:
this divided by n.
Throws:
java.lang.IllegalArgumentException - if n == null.
java.lang.ArithmeticException - if the value of n is zero.

pow

public RationalNumber pow(IntegerNumber n)
Computes this**n, where n is an integer number.
Parameters:
n - the exponent.
Returns:
this raised to the power of n.
Throws:
java.lang.IllegalArgumentException - if n == null.

getNumerator

public IntegerNumber getNumerator()
Returns the numerator of this fraction. This numerator may be negative.
Returns:
the numerator.

getDenominator

public IntegerNumber getDenominator()
Returns the denominator of this fraction. The denonimator will allways be a positive integer number.
Returns:
the denominator.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD