| Modifier and Type | Field and Description |
|---|---|
| private static final double | DEFAULT_EPSILON
The default epsilon used for convergence. |
| private final int | denominator
The denominator. |
| public static final Fraction | FOUR_FIFTHS
A fraction representing "4/5". |
| public static final Fraction | MINUS_ONE
A fraction representing "-1 / 1". |
| private final int | numerator
The numerator. |
| public static final Fraction | ONE
A fraction representing "1". |
| public static final Fraction | ONE_FIFTH
A fraction representing "1/5". |
| public static final Fraction | ONE_HALF
A fraction representing "1/2". |
| public static final Fraction | ONE_QUARTER
A fraction representing "1/4". |
| public static final Fraction | ONE_THIRD
A fraction representing "1/3". |
| private static final long | serialVersionUID
Serializable version identifier
|
| public static final Fraction | THREE_FIFTHS
A fraction representing "3/5". |
| public static final Fraction | THREE_QUARTERS
A fraction representing "3/4". |
| public static final Fraction | TWO
A fraction representing "2 / 1". |
| public static final Fraction | TWO_FIFTHS
A fraction representing "2/5". |
| public static final Fraction | TWO_QUARTERS
A fraction representing "2/4". |
| public static final Fraction | TWO_THIRDS
A fraction representing "2/3". |
| public static final Fraction | ZERO
A fraction representing "0". |
| Access | Constructor and Description |
|---|---|
| public | Fraction(double
the double value to convert to a fraction. value)Create a fraction given the double value. |
| public | Fraction(double
the double value to convert to a fraction. value, double maximum error allowed. The resulting fraction is within
epsilon, int epsilon of value, in absolute terms.maximum number of convergents maxIterations)Create a fraction given the double value and maximum error allowed. |
| public | Fraction(double
the double value to convert to a fraction. value, int The maximum allowed value for denominator maxDenominator)Create a fraction given the double value and maximum denominator. |
| private | Fraction(double
the double value to convert to a fraction. value, double maximum error allowed. The resulting fraction is within
epsilon, int epsilon of value, in absolute terms.maximum denominator value allowed. maxDenominator, int maximum number of convergents maxIterations)Create a fraction given the double value and either the maximum error allowed or the maximum number of denominator digits. |
| public | |
| public | Fraction(int
the numerator. num, int the denominator. den)Create a fraction given the numerator and denominator. |
| Modifier and Type | Method and Description |
|---|---|
| public Fraction | |
| public Fraction | Returns: aFraction instance with the resulting valuesthe fraction to add, must not be fraction)nullImplements org. Adds the value of this fraction to another, returning the result in reduced form. |
| public Fraction | Returns: this + ithe i)integer to add.Implements org. Add an integer to the fraction. |
| private Fraction | |
| public int | Returns: -1 if this is less thanobject, +1 if this is greater
than object, 0 if they are equal.the object to compare to object)Implements java. Compares this object to another based on size. |
| public Fraction | Returns: aFraction instance with the resulting valuesthe fraction to divide by, must not be fraction)nullImplements org. Divide the value of this fraction by another. |
| public Fraction | Returns: this * ithe i)integer to divide by.Implements org. Divide the fraction by an integer. |
| public double | Returns: the fraction as adoubleImplements abstract java. Gets the fraction as a |
| public boolean | Returns: true if two fractions are equal, false if object isnull, not an instance of Fraction, or not equal
to this fraction instance.fraction to test for equality to this fraction other)Overrides java. Test for the equality of two fractions. |
| public float | Returns: the fraction as afloatImplements abstract java. Gets the fraction as a |
| public int | |
| public FractionField | getField()
Implements org. Get the |
| public int | |
| public static Fraction | Returns: a new fraction instance, with the numerator and denominator reducedthe numerator, for example the three in 'three sevenths' numerator, int the denominator, for example the seven in 'three sevenths' denominator)Creates a |
| public int | Returns: a hash code value for this objectOverrides java. Gets a hashCode for the fraction. |
| public int | Returns: the whole number fraction partImplements abstract java. Gets the fraction as an |
| public long | Returns: the whole number fraction partImplements abstract java. Gets the fraction as a |
| public Fraction | Returns: aFraction instance with the resulting valuesthe fraction to multiply by, must not be fraction)nullImplements org. Multiplies the value of this fraction by another, returning the result in reduced form. |
| public Fraction | Returns: this * ithe i)integer to multiply by.Implements org. Multiply the fraction by an integer. |
| public Fraction | Returns: the negation of this fraction.Implements org. Return the additive inverse of this fraction. |
| public double | Returns: the fraction percentage as adouble.
Gets the fraction percentage as a |
| public Fraction | Returns: the reciprocal fractionImplements org. Return the multiplicative inverse of this fraction. |
| public Fraction | Returns: aFraction instance with the resulting valuesthe fraction to subtract, must not be fraction)nullImplements org. Subtracts the value of another fraction from the value of this one, returning the result in reduced form. |
| public Fraction | Returns: this - ithe i)integer to subtract.Implements org. Subtract an integer from the fraction. |
| public String | Returns: a string representation of the fraction.Overrides java.
Returns the |
| DEFAULT_EPSILON | back to summary |
|---|---|
| private static final double DEFAULT_EPSILON The default epsilon used for convergence. | |
| denominator | back to summary |
|---|---|
| private final int denominator The denominator. | |
| FOUR_FIFTHS | back to summary |
|---|---|
| public static final Fraction FOUR_FIFTHS A fraction representing "4/5". | |
| MINUS_ONE | back to summary |
|---|---|
| public static final Fraction MINUS_ONE A fraction representing "-1 / 1". | |
| numerator | back to summary |
|---|---|
| private final int numerator The numerator. | |
| ONE | back to summary |
|---|---|
| public static final Fraction ONE A fraction representing "1". | |
| ONE_FIFTH | back to summary |
|---|---|
| public static final Fraction ONE_FIFTH A fraction representing "1/5". | |
| ONE_HALF | back to summary |
|---|---|
| public static final Fraction ONE_HALF A fraction representing "1/2". | |
| ONE_QUARTER | back to summary |
|---|---|
| public static final Fraction ONE_QUARTER A fraction representing "1/4". | |
| ONE_THIRD | back to summary |
|---|---|
| public static final Fraction ONE_THIRD A fraction representing "1/3". | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides java. Serializable version identifier | |
| THREE_FIFTHS | back to summary |
|---|---|
| public static final Fraction THREE_FIFTHS A fraction representing "3/5". | |
| THREE_QUARTERS | back to summary |
|---|---|
| public static final Fraction THREE_QUARTERS A fraction representing "3/4". | |
| TWO | back to summary |
|---|---|
| public static final Fraction TWO A fraction representing "2 / 1". | |
| TWO_FIFTHS | back to summary |
|---|---|
| public static final Fraction TWO_FIFTHS A fraction representing "2/5". | |
| TWO_QUARTERS | back to summary |
|---|---|
| public static final Fraction TWO_QUARTERS A fraction representing "2/4". | |
| TWO_THIRDS | back to summary |
|---|---|
| public static final Fraction TWO_THIRDS A fraction representing "2/3". | |
| ZERO | back to summary |
|---|---|
| public static final Fraction ZERO A fraction representing "0". | |
| Fraction | back to summary |
|---|---|
| public Fraction(double value) throws FractionConversionException Create a fraction given the double value.
| |
| Fraction | back to summary |
|---|---|
| public Fraction(double value, double epsilon, int maxIterations) throws FractionConversionException Create a fraction given the double value and maximum error allowed. References:
| |
| Fraction | back to summary |
|---|---|
| public Fraction(double value, int maxDenominator) throws FractionConversionException Create a fraction given the double value and maximum denominator. References:
| |
| Fraction | back to summary |
|---|---|
| private Fraction(double value, double epsilon, int maxDenominator, int maxIterations) throws FractionConversionException Create a fraction given the double value and either the maximum error allowed or the maximum number of denominator digits. Note This constructor is called with EITHER - a valid epsilon value and the maxDenominator set to Integer.MAX_VALUE (that way the maxDenominator has no effect). OR - a valid maxDenominator value and the epsilon value set to zero (that way epsilon only has effect if there is an exact match before the maxDenominator value is reached). It has been done this way so that the same code can be (re)used for both scenarios. However this could be confusing to users if it were part of the public API and this constructor should therefore remain PRIVATE. See JIRA issue ticket MATH-181 for more details: https://issues.apache.org/jira/browse/MATH-181
| |
| Fraction | back to summary |
|---|---|
| public Fraction(int num) Create a fraction from an int. The fraction is num / 1.
| |
| Fraction | back to summary |
|---|---|
| public Fraction(int num, int den) Create a fraction given the numerator and denominator. The fraction is reduced to lowest terms.
| |
| abs | back to summary |
|---|---|
| public Fraction abs() Returns the absolute value of this fraction.
| |
| add | back to summary |
|---|---|
| public Fraction add(Fraction fraction) Implements org. Adds the value of this fraction to another, returning the result in reduced form. The algorithm follows Knuth, 4.5.1.
| |
| add | back to summary |
|---|---|
| public Fraction add(final int i) Implements org. Add an integer to the fraction.
| |
| addSub | back to summary |
|---|---|
| private Fraction addSub(Fraction fraction, boolean isAdd) Implement add and subtract using algorithm described in Knuth 4.5.1.
| |
| compareTo | back to summary |
|---|---|
| public int compareTo(Fraction object) Implements java. Compares this object to another based on size.
| |
| divide | back to summary |
|---|---|
| public Fraction divide(Fraction fraction) Implements org. Divide the value of this fraction by another.
| |
| divide | back to summary |
|---|---|
| public Fraction divide(final int i) Implements org. Divide the fraction by an integer.
| |
| doubleValue | back to summary |
|---|---|
| public double doubleValue() Implements abstract java. Gets the fraction as a
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object other) Overrides java. 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. | |
| floatValue | back to summary |
|---|---|
| public float floatValue() Implements abstract java. Gets the fraction as a
| |
| getDenominator | back to summary |
|---|---|
| public int getDenominator() Access the denominator.
| |
| getField | back to summary |
|---|---|
| public FractionField getField() Implements org. Doc from org. Get the
| |
| getNumerator | back to summary |
|---|---|
| public int getNumerator() Access the numerator.
| |
| getReducedFraction | back to summary |
|---|---|
| public static Fraction getReducedFraction(int numerator, int denominator) Creates a Any negative signs are resolved to be on the numerator.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Gets a hashCode for the fraction.
| |
| intValue | back to summary |
|---|---|
| public int intValue() Implements abstract java. Gets the fraction as an
| |
| longValue | back to summary |
|---|---|
| public long longValue() Implements abstract java. Gets the fraction as a
| |
| multiply | back to summary |
|---|---|
| public Fraction multiply(Fraction fraction) Implements org. Multiplies the value of this fraction by another, returning the result in reduced form.
| |
| multiply | back to summary |
|---|---|
| public Fraction multiply(final int i) Implements org. Multiply the fraction by an integer.
| |
| negate | back to summary |
|---|---|
| public Fraction negate() Implements org. Return the additive inverse of this fraction.
| |
| percentageValue | back to summary |
|---|---|
| public double percentageValue()
Gets the fraction percentage as a
| |
| reciprocal | back to summary |
|---|---|
| public Fraction reciprocal() Implements org. Return the multiplicative inverse of this fraction.
| |
| subtract | back to summary |
|---|---|
| public Fraction subtract(Fraction fraction) Implements org. Subtracts the value of another fraction from the value of this one, returning the result in reduced form.
| |
| subtract | back to summary |
|---|---|
| public Fraction subtract(final int i) Implements org. Subtract an integer from the fraction.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java.
Returns the
| |