You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2019/07/01 17:24:56 UTC
[commons-numbers] 02/07: NUMBERS-125: Delete BigFraction.reduce()
This is an automated email from the ASF dual-hosted git repository.
erans pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git
commit fbe05a1b79fb9b872666678d8d455cd1be7a0232
Author: Schamschi <he...@gmx.at>
AuthorDate: Mon Jul 1 13:29:57 2019 +0200
NUMBERS-125: Delete BigFraction.reduce()
---
.../commons/numbers/fraction/BigFraction.java | 27 ++++------------------
1 file changed, 4 insertions(+), 23 deletions(-)
diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
index 11c6a7b..3971525 100644
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
+++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/BigFraction.java
@@ -42,10 +42,10 @@ public class BigFraction extends Number implements Comparable<BigFraction>, Seri
/** Parameter name for BigIntegers (to satisfy checkstyle). */
private static final String PARAM_NAME_BG = "bg";
- /** The numerator. */
+ /** The numerator of this fraction reduced to lowest terms. Possibly negative*/
private final BigInteger numerator;
- /** The denominator. */
+ /** The denominator of this fraction reduced to lowest terms. Always positive*/
private final BigInteger denominator;
/**
@@ -706,9 +706,8 @@ public class BigFraction extends Number implements Comparable<BigFraction>, Seri
if (this == other) {
ret = true;
} else if (other instanceof BigFraction) {
- BigFraction rhs = ((BigFraction) other).reduce();
- BigFraction thisOne = this.reduce();
- ret = thisOne.numerator.equals(rhs.numerator) && thisOne.denominator.equals(rhs.denominator);
+ BigFraction rhs = (BigFraction) other;
+ ret = numerator.equals(rhs.numerator) && denominator.equals(rhs.denominator);
}
return ret;
@@ -1038,24 +1037,6 @@ public class BigFraction extends Number implements Comparable<BigFraction>, Seri
/**
* <p>
- * Reduce this <code>BigFraction</code> to its lowest terms.
- * </p>
- *
- * @return the reduced <code>BigFraction</code>. It doesn't change anything if
- * the fraction can be reduced.
- */
- public BigFraction reduce() {
- final BigInteger gcd = numerator.gcd(denominator);
-
- if (BigInteger.ONE.compareTo(gcd) < 0) {
- return new BigFraction(numerator.divide(gcd), denominator.divide(gcd));
- } else {
- return this;
- }
- }
-
- /**
- * <p>
* Subtracts the value of an {@link BigInteger} from the value of this
* {@code BigFraction}, returning the result in reduced form.
* </p>