org.znerd.math
Class BasicRationalNumber

java.lang.Object
  |
  +--java.lang.Number
        |
        +--org.znerd.math.RealNumber
              |
              +--org.znerd.math.RationalNumber
                    |
                    +--org.znerd.math.BasicRationalNumber

public class BasicRationalNumber
extends RationalNumber

Basic implementation of a rational number, i.e. a fraction.

This implementation simply encapsulates a numerator and a denominator field. Both are IntegerNumber objects.

Version:
$Revision: 1.2 $ $Date: 2002/06/13 11:55:01 $
Author:
Ernst de Haan (znerd@FreeBSD.org)
See Also:
Serialized Form

Field Summary
static BasicRationalNumber MINUS_ONE_HALF
          Cached instance that represents the number minus one half, -1/2.
static BasicRationalNumber ONE_HALF
          Cached instance that represents the number one half, 1/2.
 
Fields inherited from class org.znerd.math.RealNumber
MAXIMUM_RADIX
 
Constructor Summary
protected BasicRationalNumber(IntegerNumber numerator, IntegerNumber denominator)
          Constructs a new BasicRationalNumber from a numerator and a denominator.
 
Method Summary
static BasicRationalNumber createInstance(IntegerNumber numerator, IntegerNumber denominator)
          Returns an instance of a BasicRationalNumber with the given numerator and denominator.
 
Methods inherited from class org.znerd.math.RationalNumber
add, add, compareTo, compareToImpl, compareToImpl, compareToImpl2, divide, divide, doubleValue, getDenominator, getNumerator, invert, multiply, multiply, negate, pow, pow, subtract, subtract, toBigDecimal, toBigDecimal, trunc
 
Methods inherited from class org.znerd.math.RealNumber
abs, byteValue, compareTo, compareTo, equals, fitsByte, fitsDouble, fitsFloat, fitsInt, fitsLong, fitsShort, floatValue, getSign, intValue, longValue, shortValue, toBigInteger, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ONE_HALF

public static final BasicRationalNumber ONE_HALF
Cached instance that represents the number one half, 1/2.

MINUS_ONE_HALF

public static final BasicRationalNumber MINUS_ONE_HALF
Cached instance that represents the number minus one half, -1/2.
Constructor Detail

BasicRationalNumber

protected BasicRationalNumber(IntegerNumber numerator,
                              IntegerNumber denominator)
                       throws IllegalArgumentException,
                              ArithmeticException
Constructs a new BasicRationalNumber from a numerator and a denominator.
Parameters:
numerator - the numerator for the fraction.
denominator - the denominator for the fraction.
Throws:
IllegalArgumentException - if one of the following applies:
  1. numerator == null
  2. denominator == null
ArithmeticException - if the value of denominator is zero.
Method Detail

createInstance

public static BasicRationalNumber createInstance(IntegerNumber numerator,
                                                 IntegerNumber denominator)
                                          throws IllegalArgumentException,
                                                 ArithmeticException
Returns an instance of a BasicRationalNumber with the given numerator and denominator.
Parameters:
numerator - the numerator for the fraction.
denominator - the denominator for the fraction.
Returns:
the (possibly newly constructed) instance.
Throws:
IllegalArgumentException - if one of the following applies:
  1. numerator == null
  2. denominator == null
ArithmeticException - if the value of denominator is zero.


See http://jump-math.sourceforge.net/.