| java.lang.Object java.lang.Number org.apache.commons.math.fraction.Fraction
Fraction | public class Fraction extends Number implements Comparable(Code) | | Representation of a rational number.
since: 1.1 version: $Revision: 348519 $ $Date: 2005-11-23 12:12:18 -0700 (Wed, 23 Nov 2005) $ |
Field Summary | |
final public static Fraction | ONE A fraction representing "1 / 1". | final public static Fraction | ZERO A fraction representing "0 / 1". |
Constructor Summary | |
public | Fraction(double value) Create a fraction given the double value. | public | Fraction(double value, double epsilon, int maxIterations) Create a fraction given the double value.
References:
Parameters: value - the double value to convert to a fraction. Parameters: epsilon - maximum error allowed. | public | Fraction(int num, int den) Create a fraction given the numerator and denominator. |
ONE | final public static Fraction ONE(Code) | | A fraction representing "1 / 1".
|
ZERO | final public static Fraction ZERO(Code) | | A fraction representing "0 / 1".
|
Fraction | public Fraction(double value) throws ConvergenceException(Code) | | Create a fraction given the double value.
Parameters: value - the double value to convert to a fraction. throws: ConvergenceException - if the continued fraction failed toconverge. |
Fraction | public Fraction(double value, double epsilon, int maxIterations) throws ConvergenceException(Code) | | Create a fraction given the double value.
References:
Parameters: value - the double value to convert to a fraction. Parameters: epsilon - maximum error allowed. The resulting fraction is withinepsilon of value , in absolute terms. Parameters: maxIterations - maximum number of convergents throws: ConvergenceException - if the continued fraction failed toconverge. |
Fraction | public Fraction(int num, int den)(Code) | | Create a fraction given the numerator and denominator. The fraction is
reduced to lowest terms.
Parameters: num - the numerator. Parameters: den - the denominator. throws: ArithmeticException - if the denomiator is zero |
abs | public Fraction abs()(Code) | | Returns the absolute value of this fraction.
the absolute value. |
add | public Fraction add(Fraction fraction)(Code) | | Adds the value of this fraction to another, returning the result in reduced form.
The algorithm follows Knuth, 4.5.1.
Parameters: fraction - the fraction to add, must not be null a Fraction instance with the resulting values throws: IllegalArgumentException - if the fraction is null throws: ArithmeticException - if the resulting numerator or denominator exceedsInteger.MAX_VALUE |
compareTo | public int compareTo(Object object)(Code) | | Compares this object to another based on size.
Parameters: object - the object to compare to -1 if this is less than object, +1 if this is greaterthan object, 0 if they are equal. |
divide | public Fraction divide(Fraction fraction)(Code) | | Divide the value of this fraction by another.
Parameters: fraction - the fraction to divide by, must not be null a Fraction instance with the resulting values throws: IllegalArgumentException - if the fraction is null throws: ArithmeticException - if the fraction to divide by is zero throws: ArithmeticException - if the resulting numerator or denominator exceedsInteger.MAX_VALUE |
doubleValue | public double doubleValue()(Code) | | Gets the fraction as a double. This calculates the fraction as
the numerator divided by denominator.
the fraction as a double |
equals | public boolean equals(Object other)(Code) | | Test for the equality of two fractions. If the lowest term
numerator and denominators are the same for both fractions, the two
fractions are considered to be equal.
Parameters: other - fraction to test for equality to this fraction true if two fractions are equal, false if object isnull, not an instance of Fraction, or not equalto this fraction instance. |
floatValue | public float floatValue()(Code) | | Gets the fraction as a float. This calculates the fraction as
the numerator divided by denominator.
the fraction as a float |
getDenominator | public int getDenominator()(Code) | | Access the denominator.
the denominator. |
getNumerator | public int getNumerator()(Code) | | Access the numerator.
the numerator. |
getReducedFraction | public static Fraction getReducedFraction(int numerator, int denominator)(Code) | | Creates a Fraction instance with the 2 parts
of a fraction Y/Z.
Any negative signs are resolved to be on the numerator.
Parameters: numerator - the numerator, for example the three in 'three sevenths' Parameters: denominator - the denominator, for example the seven in 'three sevenths' a new fraction instance, with the numerator and denominator reduced throws: ArithmeticException - if the denominator is zero |
hashCode | public int hashCode()(Code) | | Gets a hashCode for the fraction.
a hash code value for this object |
intValue | public int intValue()(Code) | | Gets the fraction as an int. This returns the whole number part
of the fraction.
the whole number fraction part |
longValue | public long longValue()(Code) | | Gets the fraction as a long. This returns the whole number part
of the fraction.
the whole number fraction part |
multiply | public Fraction multiply(Fraction fraction)(Code) | | Multiplies the value of this fraction by another, returning the
result in reduced form.
Parameters: fraction - the fraction to multiply by, must not be null a Fraction instance with the resulting values throws: IllegalArgumentException - if the fraction is null throws: ArithmeticException - if the resulting numerator or denominator exceedsInteger.MAX_VALUE |
negate | public Fraction negate()(Code) | | Return the additive inverse of this fraction.
the negation of this fraction. |
reciprocal | public Fraction reciprocal()(Code) | | Return the multiplicative inverse of this fraction.
the reciprocal fraction |
subtract | public Fraction subtract(Fraction fraction)(Code) | | Subtracts the value of another fraction from the value of this one,
returning the result in reduced form.
Parameters: fraction - the fraction to subtract, must not be null a Fraction instance with the resulting values throws: IllegalArgumentException - if the fraction is null throws: ArithmeticException - if the resulting numerator or denominatorcannot be represented in an int . |
|
|