Home | History | Annotate | Download | only in fraction

Lines Matching defs:FRACTION

17 package org.apache.commons.math.fraction;
40 /** A fraction representing "2 / 1". */
43 /** A fraction representing "1". */
46 /** A fraction representing "0". */
49 /** A fraction representing "-1 / 1". */
52 /** A fraction representing "4/5". */
55 /** A fraction representing "1/5". */
58 /** A fraction representing "1/2". */
61 /** A fraction representing "1/4". */
64 /** A fraction representing "1/3". */
67 /** A fraction representing "3/5". */
70 /** A fraction representing "3/4". */
73 /** A fraction representing "2/5". */
76 /** A fraction representing "2/4". */
79 /** A fraction representing "2/3". */
151 * Create a fraction given the double value.
161 * approximated, the fraction created may seem strange in some cases. For example
163 * the fraction 1/3 but the fraction 6004799503160661 / 18014398509481984
168 * @param value the double value to convert to a fraction.
208 * Create a fraction given the double value and maximum error allowed.
213 * Continued Fraction</a> equations (11) and (22)-(26)</li>
218 * the double value to convert to a fraction.
220 * maximum error allowed. The resulting fraction is within
225 * if the continued fraction failed to converge.
235 * Create a fraction given the double value and either the maximum error
257 * the double value to convert to a fraction.
259 * maximum error allowed. The resulting fraction is within
266 * if the continued fraction failed to converge.
335 * Create a fraction given the double value and maximum denominator.
340 * Continued Fraction</a> equations (11) and (22)-(26)</li>
345 * the double value to convert to a fraction.
349 * if the continued fraction failed to converge.
413 * Creates a <code>BigFraction</code> instance with the 2 parts of a fraction
425 * @return a new fraction instance, with the numerator and denominator
452 * Adds the value of this fraction to the passed {@link BigInteger},
468 * Adds the value of this fraction to the passed <tt>integer</tt>, returning
482 * Adds the value of this fraction to the passed <tt>long</tt>, returning
496 * Adds the value of this fraction to another, returning the result in
500 * @param fraction
505 public BigFraction add(final BigFraction fraction) {
506 if (fraction == null) {
507 throw new NullPointerException(LocalizedFormats.FRACTION.getSourceString());
509 if (ZERO.equals(fraction)) {
516 if (denominator.equals(fraction.denominator)) {
517 num = numerator.add(fraction.numerator);
520 num = (numerator.multiply(fraction.denominator)).add((fraction.numerator).multiply(denominator));
521 den = denominator.multiply(fraction.denominator);
529 * Gets the fraction as a <code>BigDecimal</code>. This calculates the
530 * fraction as the numerator divided by denominator.
533 * @return the fraction as a <code>BigDecimal</code>.
545 * Gets the fraction as a <code>BigDecimal</code> following the passed
546 * rounding mode. This calculates the fraction as the numerator divided by
552 * @return the fraction as a <code>BigDecimal</code>.
564 * Gets the fraction as a <code>BigDecimal</code> following the passed scale
565 * and rounding mode. This calculates the fraction as the numerator divided
574 * @return the fraction as a <code>BigDecimal</code>.
600 * Divide the value of this fraction by the passed <code>BigInteger</code>,
610 * if the fraction to divide by is zero.
621 * Divide the value of this fraction by the passed <tt>int</tt>, ie
629 * if the fraction to divide by is zero.
637 * Divide the value of this fraction by the passed <tt>long</tt>, ie
645 * if the fraction to divide by is zero.
653 * Divide the value of this fraction by another, returning the result in
657 * @param fraction Fraction to divide by, must not be {@code null}.
659 * @throws NullPointerException if the {@code fraction} is {@code null}.
660 * @throws ArithmeticException if the fraction to divide by is zero.
662 public BigFraction divide(final BigFraction fraction) {
663 if (fraction == null) {
664 throw new NullPointerException(LocalizedFormats.FRACTION.getSourceString());
666 if (BigInteger.ZERO.equals(fraction.numerator)) {
670 return multiply(fraction.reciprocal());
675 * Gets the fraction as a <tt>double</tt>. This calculates the fraction as
679 * @return the fraction as a <tt>double</tt>
695 * fraction to test for equality to this fraction, can be
699 * equal to this fraction instance.
719 * Gets the fraction as a <tt>float</tt>. This calculates the fraction as
723 * @return the fraction as a <tt>float</tt>.
799 * Gets a hashCode for the fraction.
812 * Gets the fraction as an <tt>int</tt>. This returns the whole number part
813 * of the fraction.
816 * @return the whole number fraction part.
826 * Gets the fraction as a <tt>long</tt>. This returns the whole number part
827 * of the fraction.
830 * @return the whole number fraction part.
840 * Multiplies the value of this fraction by the passed
857 * Multiply the value of this fraction by the passed <tt>int</tt>, returning
871 * Multiply the value of this fraction by the passed <tt>long</tt>,
885 * Multiplies the value of this fraction by another, returning the result in
889 * @param fraction Fraction to multiply by, must not be {@code null}.
891 * @throws NullPointerException if {@code fraction} is {@code null}.
893 public BigFraction multiply(final BigFraction fraction) {
894 if (fraction == null) {
895 throw new NullPointerException(LocalizedFormats.FRACTION.getSourceString());
898 fraction.numerator.equals(BigInteger.ZERO)) {
901 return new BigFraction(numerator.multiply(fraction.numerator),
902 denominator.multiply(fraction.denominator));
907 * Return the additive inverse of this fraction, returning the result in
911 * @return the negation of this fraction.
919 * Gets the fraction percentage as a <tt>double</tt>. This calculates the
920 * fraction as the numerator divided by denominator multiplied by 100.
923 * @return the fraction percentage as a <tt>double</tt>.
1003 * Return the multiplicative inverse of this fraction.
1006 * @return the reciprocal fraction.
1018 * the fraction can be reduced.
1073 * Subtracts the value of another fraction from the value of this one,
1077 * @param fraction {@link BigFraction} to subtract, must not be {@code null}.
1079 * @throws NullPointerException if the {@code fraction} is {@code null}.
1081 public BigFraction subtract(final BigFraction fraction) {
1082 if (fraction == null) {
1083 throw new NullPointerException(LocalizedFormats.FRACTION.getSourceString());
1085 if (ZERO.equals(fraction)) {
1091 if (denominator.equals(fraction.denominator)) {
1092 num = numerator.subtract(fraction.numerator);
1095 num = (numerator.multiply(fraction.denominator)).subtract((fraction.numerator).multiply(denominator));
1096 den = denominator.multiply(fraction.denominator);
1104 * Returns the <code>String</code> representing this fraction, ie
1108 * @return a string representation of the fraction.