org.retro.neural
Class Rational

java.lang.Object
  extended byorg.retro.neural.FieldElement
      extended byorg.retro.neural.Rational
All Implemented Interfaces:
java.lang.Comparable

public class Rational
extends FieldElement


Field Summary
protected  java.math.BigInteger denominator
           
protected  java.math.BigInteger numerator
           
 
Constructor Summary
Rational(java.math.BigInteger value)
          This creates a Rational with denominator 1
Rational(java.math.BigInteger numerator, java.math.BigInteger denominator)
          This creates a Rational.
Rational(double value)
          This creates a Rational out of a double.
Rational(long numerator, long denominator)
          This constructor takes two longs as numerator and denominator.
 
Method Summary
 Rational abs()
          Returns the absolute value of this Rational number.
 FieldElement add(FieldElement val)
          Returns the result of this Rational added to another one.
protected  void cancel()
          Completely cancels this Rational.
 int compareTo(java.lang.Object o)
          Implements Comparable.compareTo(Object).
 double doubleValue()
          Returns the value of this Rational as a double.
 boolean equals(FieldElement val)
          Tests two Rationals for equality.
 java.math.BigInteger getDenominator()
          Returns the denominator of this Rational.
 java.math.BigInteger getNumerator()
          Returns the numerator of this Rational.
 FieldElement instance(double dval)
          Returns an instance of this FieldElement to be used in computing mean and other values.
 FieldElement invert()
          Returns the inverted Rational to this rational.
 FieldElement multiply(FieldElement val)
          Returns the result of this Rational multiplied with another one.
 FieldElement negate()
          Calculates the inverse element of addition for this FieldElement.
 FieldElement one()
          Returns the one element for this field.
 FieldElement subtract(FieldElement val)
          Returns the result of this Rational minus another one.
 java.lang.String toString()
          Returns a String representation of this Rational.
 FieldElement zero()
          Returns the zero element for this field.
 
Methods inherited from class org.retro.neural.FieldElement
divide, ge, gt, isOne, isZero, le, lt
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

numerator

protected java.math.BigInteger numerator

denominator

protected java.math.BigInteger denominator
Constructor Detail

Rational

public Rational(long numerator,
                long denominator)
This constructor takes two longs as numerator and denominator.

Parameters:
numerator -
denominator -

Rational

public Rational(java.math.BigInteger value)
This creates a Rational with denominator 1

Parameters:
value - numerator

Rational

public Rational(java.math.BigInteger numerator,
                java.math.BigInteger denominator)
This creates a Rational.

Parameters:
numerator -
denominator -

Rational

public Rational(double value)
This creates a Rational out of a double. So for example 1.2 will become 6/5 and Math.PI will become 3141592653589793/1000000000000000.

Parameters:
value -
Method Detail

toString

public java.lang.String toString()
Returns a String representation of this Rational.


cancel

protected void cancel()
Completely cancels this Rational.


add

public FieldElement add(FieldElement val)
Returns the result of this Rational added to another one.

Specified by:
add in class FieldElement
Parameters:
val -
Returns:
sum

subtract

public FieldElement subtract(FieldElement val)
Returns the result of this Rational minus another one.

Overrides:
subtract in class FieldElement
Parameters:
val -
Returns:
difference

multiply

public FieldElement multiply(FieldElement val)
Returns the result of this Rational multiplied with another one.

Specified by:
multiply in class FieldElement
Parameters:
val -
Returns:
product

negate

public FieldElement negate()
Description copied from class: FieldElement
Calculates the inverse element of addition for this FieldElement.

Specified by:
negate in class FieldElement
Returns:
negated

invert

public FieldElement invert()
                    throws InvalidOperationException
Returns the inverted Rational to this rational. So for example 6/5 will return 5/6.

Specified by:
invert in class FieldElement
Returns:
inverted
Throws:
InvalidOperationException

getNumerator

public java.math.BigInteger getNumerator()
Returns the numerator of this Rational.

Returns:
numerator

getDenominator

public java.math.BigInteger getDenominator()
Returns the denominator of this Rational.

Returns:
denominator

doubleValue

public double doubleValue()
Returns the value of this Rational as a double.

Returns:
numerator.doubleValue() / denominator.doubleValue();

equals

public boolean equals(FieldElement val)
Tests two Rationals for equality.

Overrides:
equals in class FieldElement
Parameters:
val -
Returns:
Equal or not.

zero

public FieldElement zero()
Returns the zero element for this field.

Specified by:
zero in class FieldElement
Returns:
zero

one

public FieldElement one()
Returns the one element for this field.

Specified by:
one in class FieldElement
Returns:
one

compareTo

public int compareTo(java.lang.Object o)
Implements Comparable.compareTo(Object).

Specified by:
compareTo in interface java.lang.Comparable
Specified by:
compareTo in class FieldElement
Parameters:
o - the object
Returns:
{-,+,0} as this object is less than, equal to, or greater than the specified object.

abs

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

Returns:
absolute value

instance

public FieldElement instance(double dval)
Returns an instance of this FieldElement to be used in computing mean and other values.

Specified by:
instance in class FieldElement
Parameters:
dval - the value to use
Returns:
instance