org.jscience.mathematics.algebraic.numbers
Class Rational

java.lang.Object
  extended by java.lang.Number
      extended by org.jscience.mathematics.algebraic.numbers.ComparableNumber
          extended by org.jscience.mathematics.algebraic.numbers.Rational
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable, Field.Member, Ring.Member, AbelianGroup.Member, Member

public final class Rational
extends ComparableNumber
implements java.lang.Cloneable, java.io.Serializable, Field.Member

DOCUMENT ME!

See Also:
Serialized Form

Field Summary
static long MAX_VALUE
          DOCUMENT ME!
static long MIN_VALUE
          DOCUMENT ME!
static long NEGATIVE_INFINITY
          DOCUMENT ME!
static Rational ONE
          DOCUMENT ME!
static long POSITIVE_INFINITY
          DOCUMENT ME!
static java.lang.Class TYPE
          DOCUMENT ME!
static Rational ZERO
          DOCUMENT ME!
 
Constructor Summary
Rational(double x)
          Find the numerator and the denominator using the Euclidean algorithm.
Rational(int num)
          Constructs a Rational number.
Rational(Integer num)
          Constructs a Rational number.
Rational(long l)
          Creates a new Rational object.
Rational(Long num)
          Constructs a Rational number.
Rational(long l, long l1)
          Creates a new Rational object.
Rational(Rational rational)
          Creates a new Rational object.
 
Method Summary
 Rational abs()
          Returns the abs of this number.
 AbelianGroup.Member add(AbelianGroup.Member n)
          Returns the addition of this number and another.
 Rational add(Rational rational)
          DOCUMENT ME!
 long ceil()
          DOCUMENT ME!
 java.lang.Object clone()
          DOCUMENT ME!
 int compareTo(java.lang.Object obj)
          Compares two comparable numbers.
 int compareTo(Rational obj)
          Compares two Rational numbers.
 Field.Member divide(Field.Member n)
          Returns the division of this number and another.
 Rational divide(Rational rational)
          DOCUMENT ME!
 double doubleValue()
          DOCUMENT ME!
 boolean equals(java.lang.Object obj)
          Compares two rational numbers for equality.
 float floatValue()
          DOCUMENT ME!
 long floor()
          DOCUMENT ME!
 Rational fractionalPart()
          DOCUMENT ME!
 long getDenominator()
          DOCUMENT ME!
 ComparableNumber getDistance(ComparableNumber n)
          DOCUMENT ME!
 ComparableNumber getNaN()
          DOCUMENT ME!
 ComparableNumber getNegativeInfinity()
          DOCUMENT ME!
 long getNumerator()
          DOCUMENT ME!
 ComparableNumber getPositiveInfinity()
          DOCUMENT ME!
 int hashCode()
          Returns a hash code for this Rational object.
 int intValue()
          DOCUMENT ME!
 Field.Member inverse()
          Returns the inverse of this number.
 boolean isDefined()
          DOCUMENT ME!
 boolean isInfinite()
          Returns true if this number is infinite.
 boolean isInteger()
          DOCUMENT ME!
 boolean isNaN()
          Returns true if this number is NaN.
 boolean isNegativeInfinity()
          DOCUMENT ME!
 boolean isPositiveInfinity()
          DOCUMENT ME!
 boolean isQuasiNaN()
          Returns true if this number is defined as the quotient of two infinites
 boolean isQuasiZero()
          Returns true if this number is quasi zero, which means the number may be different from Rational.ZERO although probably still leading to division by zero results if inverted
 long longValue()
          DOCUMENT ME!
 Rational max(Rational val)
          Returns the max of this number and another, according to compareTo rules.
 Rational min(Rational val)
          Returns the min of this number and another, according to compareTo rules.
 Rational mod(long l)
          DOCUMENT ME!
 Rational mod(Rational rational)
          DOCUMENT ME!
 Rational multiply(Rational rational)
          DOCUMENT ME!
 Ring.Member multiply(Ring.Member n)
          Returns the multiplication of this number and another.
 AbelianGroup.Member negate()
          Returns the negative of this number.
 int signum()
          Returns the sign of this number.
 AbelianGroup.Member subtract(AbelianGroup.Member n)
          Returns the subtraction of this number and another.
 Rational subtract(Rational rational)
          DOCUMENT ME!
 java.lang.String toString()
          DOCUMENT ME!
 double value()
          DOCUMENT ME!
 
Methods inherited from class org.jscience.mathematics.algebraic.numbers.ComparableNumber
max, min
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ZERO

public static final Rational ZERO
DOCUMENT ME!


ONE

public static final Rational ONE
DOCUMENT ME!


MAX_VALUE

public static final long MAX_VALUE
DOCUMENT ME!

See Also:
Constant Field Values

MIN_VALUE

public static final long MIN_VALUE
DOCUMENT ME!

See Also:
Constant Field Values

NEGATIVE_INFINITY

public static final long NEGATIVE_INFINITY
DOCUMENT ME!

See Also:
Constant Field Values

POSITIVE_INFINITY

public static final long POSITIVE_INFINITY
DOCUMENT ME!

See Also:
Constant Field Values

TYPE

public static final java.lang.Class TYPE
DOCUMENT ME!

Constructor Detail

Rational

public Rational(double x)
Find the numerator and the denominator using the Euclidean algorithm. The resulting rational is reduced.

Parameters:
x - DOCUMENT ME!

Rational

public Rational(long l,
                long l1)
Creates a new Rational object.

Parameters:
l - DOCUMENT ME!
l1 - DOCUMENT ME!

Rational

public Rational(long l)
Creates a new Rational object.

Parameters:
l - DOCUMENT ME!

Rational

public Rational(int num)
Constructs a Rational number.

Parameters:
num - DOCUMENT ME!

Rational

public Rational(Rational rational)
Creates a new Rational object.

Parameters:
rational - DOCUMENT ME!

Rational

public Rational(Long num)
Constructs a Rational number.

Parameters:
num - DOCUMENT ME!

Rational

public Rational(Integer num)
Constructs a Rational number.

Parameters:
num - DOCUMENT ME!
Method Detail

equals

public boolean equals(java.lang.Object obj)
Compares two rational numbers for equality.

Overrides:
equals in class java.lang.Object
Parameters:
obj - a Rational number.
Returns:
DOCUMENT ME!

compareTo

public int compareTo(java.lang.Object obj)
              throws java.lang.IllegalArgumentException
Compares two comparable numbers.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
obj - a number.
Returns:
a negative value if this<obj, zero if this==obj, and a positive value if this>obj.
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

compareTo

public int compareTo(Rational obj)
              throws java.lang.IllegalArgumentException
Compares two Rational numbers.

Parameters:
obj - an Rational number.
Returns:
a negative value if this<obj, zero if this==obj, and a positive value if this>obj.
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

isInteger

public boolean isInteger()
DOCUMENT ME!

Returns:
DOCUMENT ME!

toString

public java.lang.String toString()
DOCUMENT ME!

Overrides:
toString in class java.lang.Object
Returns:
DOCUMENT ME!

value

public double value()
DOCUMENT ME!

Returns:
This is an approximated value of the Rational

doubleValue

public double doubleValue()
DOCUMENT ME!

Specified by:
doubleValue in class java.lang.Number
Returns:
DOCUMENT ME!

intValue

public int intValue()
DOCUMENT ME!

Specified by:
intValue in class java.lang.Number
Returns:
DOCUMENT ME!

floatValue

public float floatValue()
DOCUMENT ME!

Specified by:
floatValue in class java.lang.Number
Returns:
DOCUMENT ME!

longValue

public long longValue()
DOCUMENT ME!

Specified by:
longValue in class java.lang.Number
Returns:
DOCUMENT ME!

floor

public long floor()
DOCUMENT ME!

Returns:
DOCUMENT ME!

ceil

public long ceil()
DOCUMENT ME!

Returns:
DOCUMENT ME!

mod

public Rational mod(Rational rational)
DOCUMENT ME!

Parameters:
rational - DOCUMENT ME!
Returns:
DOCUMENT ME!

mod

public Rational mod(long l)
DOCUMENT ME!

Parameters:
l - DOCUMENT ME!
Returns:
DOCUMENT ME!

getNumerator

public long getNumerator()
DOCUMENT ME!

Returns:
DOCUMENT ME!

getDenominator

public long getDenominator()
DOCUMENT ME!

Returns:
DOCUMENT ME!

fractionalPart

public Rational fractionalPart()
DOCUMENT ME!

Returns:
DOCUMENT ME!

abs

public Rational abs()
Returns the abs of this number.

Returns:
DOCUMENT ME!

signum

public int signum()
Returns the sign of this number.

Returns:
DOCUMENT ME!

min

public Rational min(Rational val)
Returns the min of this number and another, according to compareTo rules.

Parameters:
val - DOCUMENT ME!
Returns:
DOCUMENT ME!

max

public Rational max(Rational val)
Returns the max of this number and another, according to compareTo rules.

Parameters:
val - DOCUMENT ME!
Returns:
DOCUMENT ME!

hashCode

public int hashCode()
Returns a hash code for this Rational object.

Overrides:
hashCode in class java.lang.Object
Returns:
DOCUMENT ME!

isNaN

public boolean isNaN()
Returns true if this number is NaN.

Specified by:
isNaN in class ComparableNumber
Returns:
DOCUMENT ME!

isDefined

public boolean isDefined()
DOCUMENT ME!

Returns:
DOCUMENT ME!

isInfinite

public boolean isInfinite()
Returns true if this number is infinite.

Specified by:
isInfinite in class ComparableNumber
Returns:
DOCUMENT ME!

isNegativeInfinity

public boolean isNegativeInfinity()
DOCUMENT ME!

Specified by:
isNegativeInfinity in class ComparableNumber
Returns:
DOCUMENT ME!

isPositiveInfinity

public boolean isPositiveInfinity()
DOCUMENT ME!

Specified by:
isPositiveInfinity in class ComparableNumber
Returns:
DOCUMENT ME!

getNaN

public ComparableNumber getNaN()
DOCUMENT ME!

Specified by:
getNaN in class ComparableNumber
Returns:
DOCUMENT ME!

getNegativeInfinity

public ComparableNumber getNegativeInfinity()
DOCUMENT ME!

Specified by:
getNegativeInfinity in class ComparableNumber
Returns:
DOCUMENT ME!

getPositiveInfinity

public ComparableNumber getPositiveInfinity()
DOCUMENT ME!

Specified by:
getPositiveInfinity in class ComparableNumber
Returns:
DOCUMENT ME!

isQuasiZero

public boolean isQuasiZero()
Returns true if this number is quasi zero, which means the number may be different from Rational.ZERO although probably still leading to division by zero results if inverted

Returns:
DOCUMENT ME!

isQuasiNaN

public boolean isQuasiNaN()
Returns true if this number is defined as the quotient of two infinites

Returns:
DOCUMENT ME!

getDistance

public ComparableNumber getDistance(ComparableNumber n)
DOCUMENT ME!

Specified by:
getDistance in class ComparableNumber
Parameters:
n - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

negate

public AbelianGroup.Member negate()
Returns the negative of this number.

Specified by:
negate in interface AbelianGroup.Member
Returns:
DOCUMENT ME!

inverse

public Field.Member inverse()
Returns the inverse of this number.

Specified by:
inverse in interface Field.Member
Returns:
DOCUMENT ME!

add

public AbelianGroup.Member add(AbelianGroup.Member n)
Returns the addition of this number and another.

Specified by:
add in interface AbelianGroup.Member
Parameters:
n - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

add

public Rational add(Rational rational)
DOCUMENT ME!

Parameters:
rational - DOCUMENT ME!
Returns:
DOCUMENT ME!

subtract

public AbelianGroup.Member subtract(AbelianGroup.Member n)
Returns the subtraction of this number and another.

Specified by:
subtract in interface AbelianGroup.Member
Parameters:
n - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

subtract

public Rational subtract(Rational rational)
DOCUMENT ME!

Parameters:
rational - DOCUMENT ME!
Returns:
DOCUMENT ME!

multiply

public Ring.Member multiply(Ring.Member n)
Returns the multiplication of this number and another.

Specified by:
multiply in interface Ring.Member
Parameters:
n - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

multiply

public Rational multiply(Rational rational)
DOCUMENT ME!

Parameters:
rational - DOCUMENT ME!
Returns:
DOCUMENT ME!

divide

public Field.Member divide(Field.Member n)
Returns the division of this number and another.

Specified by:
divide in interface Field.Member
Parameters:
n - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

divide

public Rational divide(Rational rational)
DOCUMENT ME!

Parameters:
rational - DOCUMENT ME!
Returns:
DOCUMENT ME!

clone

public java.lang.Object clone()
DOCUMENT ME!

Overrides:
clone in class java.lang.Object
Returns:
DOCUMENT ME!