Return-Path: X-Original-To: apmail-commons-notifications-archive@minotaur.apache.org Delivered-To: apmail-commons-notifications-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 04DEA187D2 for ; Mon, 27 Jul 2015 19:40:53 +0000 (UTC) Received: (qmail 27965 invoked by uid 500); 27 Jul 2015 19:40:46 -0000 Delivered-To: apmail-commons-notifications-archive@commons.apache.org Received: (qmail 27903 invoked by uid 500); 27 Jul 2015 19:40:46 -0000 Mailing-List: contact notifications-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list notifications@commons.apache.org Received: (qmail 27868 invoked by uid 99); 27 Jul 2015 19:40:46 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Jul 2015 19:40:46 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id 5F22BAC0321 for ; Mon, 27 Jul 2015 19:40:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r959802 [2/10] - in /websites/production/commons/content/proper/commons-math/xref/org/apache/commons/math3: fraction/ geometry/euclidean/threed/ geometry/euclidean/twod/ ml/neuralnet/ ml/neuralnet/sofm/ ode/ ode/events/ special/ stat/infere... Date: Mon, 27 Jul 2015 19:40:45 -0000 To: notifications@commons.apache.org From: luc@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150727194046.5F22BAC0321@hades.apache.org> Modified: websites/production/commons/content/proper/commons-math/xref/org/apache/commons/math3/fraction/BigFraction.html ============================================================================== --- websites/production/commons/content/proper/commons-math/xref/org/apache/commons/math3/fraction/BigFraction.html (original) +++ websites/production/commons/content/proper/commons-math/xref/org/apache/commons/math3/fraction/BigFraction.html Mon Jul 27 19:40:45 2015 @@ -127,10 +127,10 @@ 119 public BigFraction(BigInteger num, BigInteger den) { 120 MathUtils.checkNotNull(num, LocalizedFormats.NUMERATOR); 121 MathUtils.checkNotNull(den, LocalizedFormats.DENOMINATOR); -122 if (BigInteger.ZERO.equals(den)) { +122 if (den.signum() == 0) { 123 throw new ZeroException(LocalizedFormats.ZERO_DENOMINATOR); 124 } -125 if (BigInteger.ZERO.equals(num)) { +125 if (num.signum() == 0) { 126 numerator = BigInteger.ZERO; 127 denominator = BigInteger.ONE; 128 } else { @@ -143,7 +143,7 @@ 135 } 136 137 // move sign to numerator -138 if (BigInteger.ZERO.compareTo(den) > 0) { +138 if (den.signum() == -1) { 139 num = num.negate(); 140 den = den.negate(); 141 } @@ -458,7 +458,7 @@ 450 * @return the absolute value as a {@link BigFraction}. 451 */ 452 public BigFraction abs() { -453 return (BigInteger.ZERO.compareTo(numerator) <= 0) ? this : negate(); +453 return (numerator.signum() == 1) ? this : negate(); 454 } 455 456 /** @@ -475,684 +475,772 @@ 467 */ 468 public BigFraction add(final BigInteger bg) throws NullArgumentException { 469 MathUtils.checkNotNull(bg); -470 return new BigFraction(numerator.add(denominator.multiply(bg)), denominator); -471 } -472 -473 /** -474 * <p> -475 * Adds the value of this fraction to the passed {@code integer}, returning -476 * the result in reduced form. -477 * </p> -478 * -479 * @param i -480 * the {@code integer} to add. -481 * @return a <code>BigFraction</code> instance with the resulting values. -482 */ -483 public BigFraction add(final int i) { -484 return add(BigInteger.valueOf(i)); -485 } -486 -487 /** -488 * <p> -489 * Adds the value of this fraction to the passed {@code long}, returning -490 * the result in reduced form. -491 * </p> -492 * -493 * @param l -494 * the {@code long} to add. -495 * @return a <code>BigFraction</code> instance with the resulting values. -496 */ -497 public BigFraction add(final long l) { -498 return add(BigInteger.valueOf(l)); -499 } -500 -501 /** -502 * <p> -503 * Adds the value of this fraction to another, returning the result in -504 * reduced form. -505 * </p> -506 * -507 * @param fraction -508 * the {@link BigFraction} to add, must not be <code>null</code>. -509 * @return a {@link BigFraction} instance with the resulting values. -510 * @throws NullArgumentException if the {@link BigFraction} is {@code null}. -511 */ -512 public BigFraction add(final BigFraction fraction) { -513 if (fraction == null) { -514 throw new NullArgumentException(LocalizedFormats.FRACTION); -515 } -516 if (ZERO.equals(fraction)) { -517 return this; -518 } -519 -520 BigInteger num = null; -521 BigInteger den = null; -522 -523 if (denominator.equals(fraction.denominator)) { -524 num = numerator.add(fraction.numerator); -525 den = denominator; -526 } else { -527 num = (numerator.multiply(fraction.denominator)).add((fraction.numerator).multiply(denominator)); -528 den = denominator.multiply(fraction.denominator); -529 } -530 return new BigFraction(num, den); +470 +471 if (numerator.signum() == 0) { +472 return new BigFraction(bg); +473 } +474 if (bg.signum() == 0) { +475 return this; +476 } +477 +478 return new BigFraction(numerator.add(denominator.multiply(bg)), denominator); +479 } +480 +481 /** +482 * <p> +483 * Adds the value of this fraction to the passed {@code integer}, returning +484 * the result in reduced form. +485 * </p> +486 * +487 * @param i +488 * the {@code integer} to add. +489 * @return a <code>BigFraction</code> instance with the resulting values. +490 */ +491 public BigFraction add(final int i) { +492 return add(BigInteger.valueOf(i)); +493 } +494 +495 /** +496 * <p> +497 * Adds the value of this fraction to the passed {@code long}, returning +498 * the result in reduced form. +499 * </p> +500 * +501 * @param l +502 * the {@code long} to add. +503 * @return a <code>BigFraction</code> instance with the resulting values. +504 */ +505 public BigFraction add(final long l) { +506 return add(BigInteger.valueOf(l)); +507 } +508 +509 /** +510 * <p> +511 * Adds the value of this fraction to another, returning the result in +512 * reduced form. +513 * </p> +514 * +515 * @param fraction +516 * the {@link BigFraction} to add, must not be <code>null</code>. +517 * @return a {@link BigFraction} instance with the resulting values. +518 * @throws NullArgumentException if the {@link BigFraction} is {@code null}. +519 */ +520 @Override +521 public BigFraction add(final BigFraction fraction) { +522 if (fraction == null) { +523 throw new NullArgumentException(LocalizedFormats.FRACTION); +524 } +525 if (fraction.numerator.signum() == 0) { +526 return this; +527 } +528 if (numerator.signum() == 0) { +529 return fraction; +530 } 531 -532 } -533 -534 /** -535 * <p> -536 * Gets the fraction as a <code>BigDecimal</code>. This calculates the -537 * fraction as the numerator divided by denominator. -538 * </p> -539 * -540 * @return the fraction as a <code>BigDecimal</code>. -541 * @throws ArithmeticException -542 * if the exact quotient does not have a terminating decimal -543 * expansion. -544 * @see BigDecimal -545 */ -546 public BigDecimal bigDecimalValue() { -547 return new BigDecimal(numerator).divide(new BigDecimal(denominator)); -548 } -549 -550 /** -551 * <p> -552 * Gets the fraction as a <code>BigDecimal</code> following the passed -553 * rounding mode. This calculates the fraction as the numerator divided by -554 * denominator. +532 BigInteger num = null; +533 BigInteger den = null; +534 +535 if (denominator.equals(fraction.denominator)) { +536 num = numerator.add(fraction.numerator); +537 den = denominator; +538 } else { +539 num = (numerator.multiply(fraction.denominator)).add((fraction.numerator).multiply(denominator)); +540 den = denominator.multiply(fraction.denominator); +541 } +542 +543 if (num.signum() == 0) { +544 return ZERO; +545 } +546 +547 return new BigFraction(num, den); +548 +549 } +550 +551 /** +552 * <p> +553 * Gets the fraction as a <code>BigDecimal</code>. This calculates the +554 * fraction as the numerator divided by denominator. 555 * </p> 556 * -557 * @param roundingMode -558 * rounding mode to apply. see {@link BigDecimal} constants. -559 * @return the fraction as a <code>BigDecimal</code>. -560 * @throws IllegalArgumentException -561 * if {@code roundingMode} does not represent a valid rounding -562 * mode. -563 * @see BigDecimal -564 */ -565 public BigDecimal bigDecimalValue(final int roundingMode) { -566 return new BigDecimal(numerator).divide(new BigDecimal(denominator), roundingMode); -567 } -568 -569 /** -570 * <p> -571 * Gets the fraction as a <code>BigDecimal</code> following the passed scale -572 * and rounding mode. This calculates the fraction as the numerator divided -573 * by denominator. -574 * </p> -575 * -576 * @param scale -577 * scale of the <code>BigDecimal</code> quotient to be returned. -578 * see {@link BigDecimal} for more information. -579 * @param roundingMode -580 * rounding mode to apply. see {@link BigDecimal} constants. -581 * @return the fraction as a <code>BigDecimal</code>. -582 * @see BigDecimal -583 */ -584 public BigDecimal bigDecimalValue(final int scale, final int roundingMode) { -585 return new BigDecimal(numerator).divide(new BigDecimal(denominator), scale, roundingMode); -586 } -587 -588 /** -589 * <p> -590 * Compares this object to another based on size. +557 * @return the fraction as a <code>BigDecimal</code>. +558 * @throws ArithmeticException +559 * if the exact quotient does not have a terminating decimal +560 * expansion. +561 * @see BigDecimal +562 */ +563 public BigDecimal bigDecimalValue() { +564 return new BigDecimal(numerator).divide(new BigDecimal(denominator)); +565 } +566 +567 /** +568 * <p> +569 * Gets the fraction as a <code>BigDecimal</code> following the passed +570 * rounding mode. This calculates the fraction as the numerator divided by +571 * denominator. +572 * </p> +573 * +574 * @param roundingMode +575 * rounding mode to apply. see {@link BigDecimal} constants. +576 * @return the fraction as a <code>BigDecimal</code>. +577 * @throws IllegalArgumentException +578 * if {@code roundingMode} does not represent a valid rounding +579 * mode. +580 * @see BigDecimal +581 */ +582 public BigDecimal bigDecimalValue(final int roundingMode) { +583 return new BigDecimal(numerator).divide(new BigDecimal(denominator), roundingMode); +584 } +585 +586 /** +587 * <p> +588 * Gets the fraction as a <code>BigDecimal</code> following the passed scale +589 * and rounding mode. This calculates the fraction as the numerator divided +590 * by denominator. 591 * </p> 592 * -593 * @param object -594 * the object to compare to, must not be <code>null</code>. -595 * @return -1 if this is less than {@code object}, +1 if this is greater -596 * than {@code object}, 0 if they are equal. -597 * @see java.lang.Comparable#compareTo(java.lang.Object) -598 */ -599 public int compareTo(final BigFraction object) { -600 BigInteger nOd = numerator.multiply(object.denominator); -601 BigInteger dOn = denominator.multiply(object.numerator); -602 return nOd.compareTo(dOn); +593 * @param scale +594 * scale of the <code>BigDecimal</code> quotient to be returned. +595 * see {@link BigDecimal} for more information. +596 * @param roundingMode +597 * rounding mode to apply. see {@link BigDecimal} constants. +598 * @return the fraction as a <code>BigDecimal</code>. +599 * @see BigDecimal +600 */ +601 public BigDecimal bigDecimalValue(final int scale, final int roundingMode) { +602 return new BigDecimal(numerator).divide(new BigDecimal(denominator), scale, roundingMode); 603 } 604 605 /** 606 * <p> -607 * Divide the value of this fraction by the passed {@code BigInteger}, -608 * ie {@code this * 1 / bg}, returning the result in reduced form. -609 * </p> -610 * -611 * @param bg the {@code BigInteger} to divide by, must not be {@code null} -612 * @return a {@link BigFraction} instance with the resulting values -613 * @throws NullArgumentException if the {@code BigInteger} is {@code null} -614 * @throws MathArithmeticException if the fraction to divide by is zero +607 * Compares this object to another based on size. +608 * </p> +609 * +610 * @param object +611 * the object to compare to, must not be <code>null</code>. +612 * @return -1 if this is less than {@code object}, +1 if this is greater +613 * than {@code object}, 0 if they are equal. +614 * @see java.lang.Comparable#compareTo(java.lang.Object) 615 */ -616 public BigFraction divide(final BigInteger bg) { -617 if (bg == null) { -618 throw new NullArgumentException(LocalizedFormats.FRACTION); -619 } -620 if (BigInteger.ZERO.equals(bg)) { -621 throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR); -622 } -623 return new BigFraction(numerator, denominator.multiply(bg)); -624 } -625 -626 /** -627 * <p> -628 * Divide the value of this fraction by the passed {@code int}, ie -629 * {@code this * 1 / i}, returning the result in reduced form. -630 * </p> -631 * -632 * @param i the {@code int} to divide by -633 * @return a {@link BigFraction} instance with the resulting values -634 * @throws MathArithmeticException if the fraction to divide by is zero -635 */ -636 public BigFraction divide(final int i) { -637 return divide(BigInteger.valueOf(i)); -638 } -639 -640 /** -641 * <p> -642 * Divide the value of this fraction by the passed {@code long}, ie -643 * {@code this * 1 / l}, returning the result in reduced form. -644 * </p> -645 * -646 * @param l the {@code long} to divide by -647 * @return a {@link BigFraction} instance with the resulting values -648 * @throws MathArithmeticException if the fraction to divide by is zero -649 */ -650 public BigFraction divide(final long l) { -651 return divide(BigInteger.valueOf(l)); -652 } -653 -654 /** -655 * <p> -656 * Divide the value of this fraction by another, returning the result in -657 * reduced form. -658 * </p> -659 * -660 * @param fraction Fraction to divide by, must not be {@code null}. -661 * @return a {@link BigFraction} instance with the resulting values. -662 * @throws NullArgumentException if the {@code fraction} is {@code null}. -663 * @throws MathArithmeticException if the fraction to divide by is zero -664 */ -665 public BigFraction divide(final BigFraction fraction) { -666 if (fraction == null) { -667 throw new NullArgumentException(LocalizedFormats.FRACTION); -668 } -669 if (BigInteger.ZERO.equals(fraction.numerator)) { -670 throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR); -671 } -672 -673 return multiply(fraction.reciprocal()); -674 } -675 -676 /** -677 * <p> -678 * Gets the fraction as a {@code double}. This calculates the fraction as -679 * the numerator divided by denominator. -680 * </p> -681 * -682 * @return the fraction as a {@code double} -683 * @see java.lang.Number#doubleValue() -684 */ -685 @Override -686 public double doubleValue() { -687 double result = numerator.doubleValue() / denominator.doubleValue(); -688 if (Double.isNaN(result)) { -689 // Numerator and/or denominator must be out of range: -690 // Calculate how far to shift them to put them in range. -691 int shift = FastMath.max(numerator.bitLength(), -692 denominator.bitLength()) - FastMath.getExponent(Double.MAX_VALUE); -693 result = numerator.shiftRight(shift).doubleValue() / -694 denominator.shiftRight(shift).doubleValue(); -695 } -696 return result; -697 } -698 -699 /** -700 * <p> -701 * Test for the equality of two fractions. If the lowest term numerator and -702 * denominators are the same for both fractions, the two fractions are -703 * considered to be equal. -704 * </p> -705 * -706 * @param other -707 * fraction to test for equality to this fraction, can be -708 * <code>null</code>. -709 * @return true if two fractions are equal, false if object is -710 * <code>null</code>, not an instance of {@link BigFraction}, or not -711 * equal to this fraction instance. -712 * @see java.lang.Object#equals(java.lang.Object) -713 */ -714 @Override -715 public boolean equals(final Object other) { -716 boolean ret = false; -717 -718 if (this == other) { -719 ret = true; -720 } else if (other instanceof BigFraction) { -721 BigFraction rhs = ((BigFraction) other).reduce(); -722 BigFraction thisOne = this.reduce(); -723 ret = thisOne.numerator.equals(rhs.numerator) && thisOne.denominator.equals(rhs.denominator); -724 } -725 -726 return ret; -727 } -728 -729 /** -730 * <p> -731 * Gets the fraction as a {@code float}. This calculates the fraction as -732 * the numerator divided by denominator. -733 * </p> -734 * -735 * @return the fraction as a {@code float}. -736 * @see java.lang.Number#floatValue() -737 */ -738 @Override -739 public float floatValue() { -740 float result = numerator.floatValue() / denominator.floatValue(); -741 if (Double.isNaN(result)) { -742 // Numerator and/or denominator must be out of range: -743 // Calculate how far to shift them to put them in range. -744 int shift = FastMath.max(numerator.bitLength(), -745 denominator.bitLength()) - FastMath.getExponent(Float.MAX_VALUE); -746 result = numerator.shiftRight(shift).floatValue() / -747 denominator.shiftRight(shift).floatValue(); -748 } -749 return result; -750 } -751 -752 /** -753 * <p> -754 * Access the denominator as a <code>BigInteger</code>. -755 * </p> -756 * -757 * @return the denominator as a <code>BigInteger</code>. -758 */ -759 public BigInteger getDenominator() { -760 return denominator; -761 } -762 -763 /** -764 * <p> -765 * Access the denominator as a {@code int}. -766 * </p> -767 * -768 * @return the denominator as a {@code int}. -769 */ -770 public int getDenominatorAsInt() { -771 return denominator.intValue(); -772 } -773 -774 /** -775 * <p> -776 * Access the denominator as a {@code long}. -777 * </p> -778 * -779 * @return the denominator as a {@code long}. -780 */ -781 public long getDenominatorAsLong() { -782 return denominator.longValue(); -783 } -784 -785 /** -786 * <p> -787 * Access the numerator as a <code>BigInteger</code>. -788 * </p> -789 * -790 * @return the numerator as a <code>BigInteger</code>. -791 */ -792 public BigInteger getNumerator() { -793 return numerator; -794 } -795 -796 /** -797 * <p> -798 * Access the numerator as a {@code int}. -799 * </p> -800 * -801 * @return the numerator as a {@code int}. -802 */ -803 public int getNumeratorAsInt() { -804 return numerator.intValue(); -805 } -806 -807 /** -808 * <p> -809 * Access the numerator as a {@code long}. -810 * </p> -811 * -812 * @return the numerator as a {@code long}. -813 */ -814 public long getNumeratorAsLong() { -815 return numerator.longValue(); -816 } -817 -818 /** -819 * <p> -820 * Gets a hashCode for the fraction. -821 * </p> -822 * -823 * @return a hash code value for this object. -824 * @see java.lang.Object#hashCode() -825 */ -826 @Override -827 public int hashCode() { -828 return 37 * (37 * 17 + numerator.hashCode()) + denominator.hashCode(); +616 @Override +617 public int compareTo(final BigFraction object) { +618 int lhsSigNum = numerator.signum(); +619 int rhsSigNum = object.numerator.signum(); +620 +621 if (lhsSigNum != rhsSigNum) { +622 return (lhsSigNum > rhsSigNum) ? 1 : -1; +623 } +624 if (lhsSigNum == 0) { +625 return 0; +626 } +627 +628 BigInteger nOd = numerator.multiply(object.denominator); +629 BigInteger dOn = denominator.multiply(object.numerator); +630 return nOd.compareTo(dOn); +631 } +632 +633 /** +634 * <p> +635 * Divide the value of this fraction by the passed {@code BigInteger}, +636 * ie {@code this * 1 / bg}, returning the result in reduced form. +637 * </p> +638 * +639 * @param bg the {@code BigInteger} to divide by, must not be {@code null} +640 * @return a {@link BigFraction} instance with the resulting values +641 * @throws NullArgumentException if the {@code BigInteger} is {@code null} +642 * @throws MathArithmeticException if the fraction to divide by is zero +643 */ +644 public BigFraction divide(final BigInteger bg) { +645 if (bg == null) { +646 throw new NullArgumentException(LocalizedFormats.FRACTION); +647 } +648 if (bg.signum() == 0) { +649 throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR); +650 } +651 if (numerator.signum() == 0) { +652 return ZERO; +653 } +654 return new BigFraction(numerator, denominator.multiply(bg)); +655 } +656 +657 /** +658 * <p> +659 * Divide the value of this fraction by the passed {@code int}, ie +660 * {@code this * 1 / i}, returning the result in reduced form. +661 * </p> +662 * +663 * @param i the {@code int} to divide by +664 * @return a {@link BigFraction} instance with the resulting values +665 * @throws MathArithmeticException if the fraction to divide by is zero +666 */ +667 public BigFraction divide(final int i) { +668 return divide(BigInteger.valueOf(i)); +669 } +670 +671 /** +672 * <p> +673 * Divide the value of this fraction by the passed {@code long}, ie +674 * {@code this * 1 / l}, returning the result in reduced form. +675 * </p> +676 * +677 * @param l the {@code long} to divide by +678 * @return a {@link BigFraction} instance with the resulting values +679 * @throws MathArithmeticException if the fraction to divide by is zero +680 */ +681 public BigFraction divide(final long l) { +682 return divide(BigInteger.valueOf(l)); +683 } +684 +685 /** +686 * <p> +687 * Divide the value of this fraction by another, returning the result in +688 * reduced form. +689 * </p> +690 * +691 * @param fraction Fraction to divide by, must not be {@code null}. +692 * @return a {@link BigFraction} instance with the resulting values. +693 * @throws NullArgumentException if the {@code fraction} is {@code null}. +694 * @throws MathArithmeticException if the fraction to divide by is zero +695 */ +696 @Override +697 public BigFraction divide(final BigFraction fraction) { +698 if (fraction == null) { +699 throw new NullArgumentException(LocalizedFormats.FRACTION); +700 } +701 if (fraction.numerator.signum() == 0) { +702 throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR); +703 } +704 if (numerator.signum() == 0) { +705 return ZERO; +706 } +707 +708 return multiply(fraction.reciprocal()); +709 } +710 +711 /** +712 * <p> +713 * Gets the fraction as a {@code double}. This calculates the fraction as +714 * the numerator divided by denominator. +715 * </p> +716 * +717 * @return the fraction as a {@code double} +718 * @see java.lang.Number#doubleValue() +719 */ +720 @Override +721 public double doubleValue() { +722 double result = numerator.doubleValue() / denominator.doubleValue(); +723 if (Double.isNaN(result)) { +724 // Numerator and/or denominator must be out of range: +725 // Calculate how far to shift them to put them in range. +726 int shift = FastMath.max(numerator.bitLength(), +727 denominator.bitLength()) - FastMath.getExponent(Double.MAX_VALUE); +728 result = numerator.shiftRight(shift).doubleValue() / +729 denominator.shiftRight(shift).doubleValue(); +730 } +731 return result; +732 } +733 +734 /** +735 * <p> +736 * Test for the equality of two fractions. If the lowest term numerator and +737 * denominators are the same for both fractions, the two fractions are +738 * considered to be equal. +739 * </p> +740 * +741 * @param other +742 * fraction to test for equality to this fraction, can be +743 * <code>null</code>. +744 * @return true if two fractions are equal, false if object is +745 * <code>null</code>, not an instance of {@link BigFraction}, or not +746 * equal to this fraction instance. +747 * @see java.lang.Object#equals(java.lang.Object) +748 */ +749 @Override +750 public boolean equals(final Object other) { +751 boolean ret = false; +752 +753 if (this == other) { +754 ret = true; +755 } else if (other instanceof BigFraction) { +756 BigFraction rhs = ((BigFraction) other).reduce(); +757 BigFraction thisOne = this.reduce(); [... 788 lines stripped ...]