commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aherb...@apache.org
Subject [commons-numbers] 06/26: BigFraction: Remove pow(long/BigInteger)
Date Thu, 16 Apr 2020 12:18:21 GMT
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git

commit 51419db92c6fa1edd7b2d2cfaf26ae6bd4f45704
Author: Alex Herbert <aherbert@apache.org>
AuthorDate: Mon Apr 13 21:09:39 2020 +0100

    BigFraction: Remove pow(long/BigInteger)
    
    These are currently redundant given the maximum supported range of
    BigInteger in the reference JDK.
---
 .../commons/numbers/fraction/BigFraction.java      | 52 ++--------------------
 .../commons/numbers/fraction/BigFractionTest.java  |  2 -
 2 files changed, 4 insertions(+), 50 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 d293252..a72cdb1 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
@@ -21,7 +21,6 @@ import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.math.RoundingMode;
 import java.util.Objects;
-import org.apache.commons.numbers.core.ArithmeticUtils;
 import org.apache.commons.numbers.core.NativeOperators;
 
 /**
@@ -899,6 +898,10 @@ public final class BigFraction
             return this;
         }
 
+        // Note: Raise the BigIntegers to the power and then reduce.
+        // The supported range for BigInteger is currently
+        // +/-2^(Integer.MAX_VALUE) exclusive thus larger
+        // exponents (long, BigInteger) are currently not supported.
         if (exponent < 0) {
             return new BigFraction(denominator.pow(-exponent),
                                    numerator.pow(-exponent));
@@ -908,53 +911,6 @@ public final class BigFraction
     }
 
     /**
-     * Returns a {@code BigFraction} whose value is
-     * <code>this<sup>exponent</sup></code>, returning the result
in reduced form.
-     *
-     * @param exponent exponent to which this {@code BigFraction} is to be raised.
-     * @return <code>this<sup>exponent</sup></code>.
-     */
-    public BigFraction pow(final long exponent) {
-        if (exponent == 0) {
-            return ONE;
-        }
-        if (isZero()) {
-            return this;
-        }
-
-        if (exponent < 0) {
-            return new BigFraction(ArithmeticUtils.pow(denominator, -exponent),
-                                   ArithmeticUtils.pow(numerator,   -exponent));
-        }
-        return new BigFraction(ArithmeticUtils.pow(numerator,   exponent),
-                               ArithmeticUtils.pow(denominator, exponent));
-    }
-
-    /**
-     * Returns a {@code BigFraction} whose value is
-     * <code>this<sup>exponent</sup></code>, returning the result
in reduced form.
-     *
-     * @param exponent exponent to which this {@code BigFraction} is to be raised.
-     * @return <code>this<sup>exponent</sup></code>.
-     */
-    public BigFraction pow(final BigInteger exponent) {
-        if (exponent.signum() == 0) {
-            return ONE;
-        }
-        if (isZero()) {
-            return this;
-        }
-
-        if (exponent.signum() == -1) {
-            final BigInteger eNeg = exponent.negate();
-            return new BigFraction(ArithmeticUtils.pow(denominator, eNeg),
-                                   ArithmeticUtils.pow(numerator,   eNeg));
-        }
-        return new BigFraction(ArithmeticUtils.pow(numerator,   exponent),
-                               ArithmeticUtils.pow(denominator, exponent));
-    }
-
-    /**
      * Returns the {@code String} representing this fraction.
      * Uses:
      * <ul>
diff --git a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
index 33445a4..a1e53e0 100644
--- a/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
+++ b/commons-numbers-fraction/src/test/java/org/apache/commons/numbers/fraction/BigFractionTest.java
@@ -556,8 +556,6 @@ public class BigFractionTest {
             BigFraction f1 = BigFraction.of(testCase.firstOperandNumerator, testCase.firstOperandDenominator);
             int exponent = testCase.secondOperand;
             assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f1.pow(exponent));
-            assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f1.pow((long)
exponent));
-            assertFraction(testCase.expectedNumerator, testCase.expectedDenominator, f1.pow(BigInteger.valueOf(exponent)));
         }
 
         // Note: BigInteger magnitude is limited to 2^Integer.MAX_VALUE exclusive


Mime
View raw message