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/06/22 13:28:19 UTC

[commons-numbers] branch master updated (b1daf7b -> 7b36cbf)

This is an automated email from the ASF dual-hosted git repository.

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


    from b1daf7b  Merge branch 'NUMBERS-100__heinrich'
     new 5c9d177  NUMBERS-116: Remove addAndCheck methods
     new 7fd2bfe  NUMBERS-116: Remove subAndCheck methods
     new 1512d65  NUMBERS-116: Remove mulAndCheck methods
     new 7b36cbf  Merge branch 'NUMBERS-116__heinrich'

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../numbers/combinatorics/BinomialCoefficient.java |   2 +-
 .../combinatorics/BinomialCoefficientTest.java     |   2 +-
 .../commons/numbers/core/ArithmeticUtils.java      | 174 +--------------------
 .../commons/numbers/core/ArithmeticUtilsTest.java  | 150 ------------------
 .../apache/commons/numbers/fraction/Fraction.java  |  12 +-
 5 files changed, 14 insertions(+), 326 deletions(-)


[commons-numbers] 04/04: Merge branch 'NUMBERS-116__heinrich'

Posted by er...@apache.org.
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 7b36cbf23bf5c9cfa9ad29832ae57b99093a55ac
Merge: b1daf7b 1512d65
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
AuthorDate: Sat Jun 22 15:16:10 2019 +0200

    Merge branch 'NUMBERS-116__heinrich'
    
    Closes #52.

 .../numbers/combinatorics/BinomialCoefficient.java |   2 +-
 .../combinatorics/BinomialCoefficientTest.java     |   2 +-
 .../commons/numbers/core/ArithmeticUtils.java      | 174 +--------------------
 .../commons/numbers/core/ArithmeticUtilsTest.java  | 150 ------------------
 .../apache/commons/numbers/fraction/Fraction.java  |  12 +-
 5 files changed, 14 insertions(+), 326 deletions(-)


[commons-numbers] 02/04: NUMBERS-116: Remove subAndCheck methods

Posted by er...@apache.org.
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 7fd2bfe11f396bb761b20e2153b46c5cc189d521
Author: Schamschi <he...@gmx.at>
AuthorDate: Sun Jun 16 00:04:21 2019 +0200

    NUMBERS-116: Remove subAndCheck methods
---
 .../commons/numbers/core/ArithmeticUtils.java      | 61 ----------------------
 .../commons/numbers/core/ArithmeticUtilsTest.java  | 55 -------------------
 .../apache/commons/numbers/fraction/Fraction.java  |  2 +-
 3 files changed, 1 insertion(+), 117 deletions(-)

diff --git a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java
index 84f44aa..3df1cb4 100644
--- a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java
+++ b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java
@@ -30,8 +30,6 @@ public final class ArithmeticUtils {
     private static final String OVERFLOW_GCD_MESSAGE_2_POWER_31 = "overflow: gcd({0}, {1}) is 2^31";
     /** Overflow gcd exception message for 2^63. */
     private static final String OVERFLOW_GCD_MESSAGE_2_POWER_63 = "overflow: gcd({0}, {1}) is 2^63";
-    /** Overflow subtraction exception message. */
-    private static final String OVERFLOW_IN_SUBTRACTION_MESSAGE = "overflow in subtraction: {0} + {1}";
 
     /** Negative exponent exception message part 1 */
     private static final String NEGATIVE_EXPONENT_1 = "negative exponent ({";
@@ -404,47 +402,6 @@ public final class ArithmeticUtils {
     }
 
     /**
-     * Subtract two integers, checking for overflow.
-     *
-     * @param x Minuend.
-     * @param y Subtrahend.
-     * @return the difference {@code x - y}.
-     * @throws ArithmeticException if the result can not be represented
-     * as an {@code int}.
-     */
-    public static int subAndCheck(int x, int y) {
-        long s = (long)x - (long)y;
-        if (s < Integer.MIN_VALUE || s > Integer.MAX_VALUE) {
-            throw new NumbersArithmeticException("overflow in subtraction: {0} - {1}", x, y);
-        }
-        return (int)s;
-    }
-
-    /**
-     * Subtract two long integers, checking for overflow.
-     *
-     * @param a Value.
-     * @param b Value.
-     * @return the difference {@code a - b}.
-     * @throws ArithmeticException if the result can not be represented as a
-     * {@code long}.
-     */
-    public static long subAndCheck(long a, long b) {
-        long ret;
-        if (b == Long.MIN_VALUE) {
-            if (a < 0) {
-                ret = a - b;
-            } else {
-                throw new NumbersArithmeticException(OVERFLOW_IN_SUBTRACTION_MESSAGE, a, -b);
-            }
-        } else {
-            // use additive inverse
-            ret = addAndCheck(a, -b, OVERFLOW_IN_SUBTRACTION_MESSAGE);
-        }
-        return ret;
-    }
-
-    /**
      * Raise an int to an int power.
      *
      * @param k Number to raise.
@@ -582,24 +539,6 @@ public final class ArithmeticUtils {
     }
 
     /**
-     * Add two long integers, checking for overflow.
-     *
-     * @param a Addend.
-     * @param b Addend.
-     * @param message Pattern to use for any thrown exception.
-     * @return the sum {@code a + b}.
-     * @throws ArithmeticException if the result cannot be represented
-     * as a {@code long}.
-     */
-     private static long addAndCheck(long a, long b, String message) {
-         final long result = a + b;
-         if (!((a ^ b) < 0 || (a ^ result) >= 0)) {
-             throw new NumbersArithmeticException(message, a, b);
-         }
-         return result;
-    }
-
-    /**
      * Returns true if the argument is a power of two.
      *
      * @param n the number to test
diff --git a/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/ArithmeticUtilsTest.java b/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/ArithmeticUtilsTest.java
index edee964..3a3b45b 100644
--- a/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/ArithmeticUtilsTest.java
+++ b/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/ArithmeticUtilsTest.java
@@ -293,52 +293,6 @@ public class ArithmeticUtilsTest {
     }
 
     @Test
-    public void testSubAndCheck() {
-        int big = Integer.MAX_VALUE;
-        int bigNeg = Integer.MIN_VALUE;
-        Assertions.assertEquals(big, ArithmeticUtils.subAndCheck(big, 0));
-        Assertions.assertEquals(bigNeg + 1, ArithmeticUtils.subAndCheck(bigNeg, -1));
-        Assertions.assertEquals(-1, ArithmeticUtils.subAndCheck(bigNeg, -big));
-        try {
-            ArithmeticUtils.subAndCheck(big, -1);
-            Assertions.fail("Expecting ArithmeticException");
-        } catch (ArithmeticException ex) {
-        }
-        try {
-            ArithmeticUtils.subAndCheck(bigNeg, 1);
-            Assertions.fail("Expecting ArithmeticException");
-        } catch (ArithmeticException ex) {
-        }
-    }
-
-    @Test
-    public void testSubAndCheckErrorMessage() {
-        int big = Integer.MAX_VALUE;
-        try {
-            ArithmeticUtils.subAndCheck(big, -1);
-            Assertions.fail("Expecting ArithmeticException");
-        } catch (ArithmeticException ex) {
-            Assertions.assertTrue(ex.getMessage().length() > 1);
-        }
-    }
-
-    @Test
-    public void testSubAndCheckLong() {
-        long max = Long.MAX_VALUE;
-        long min = Long.MIN_VALUE;
-        Assertions.assertEquals(max, ArithmeticUtils.subAndCheck(max, 0));
-        Assertions.assertEquals(min, ArithmeticUtils.subAndCheck(min, 0));
-        Assertions.assertEquals(-max, ArithmeticUtils.subAndCheck(0, max));
-        Assertions.assertEquals(min + 1, ArithmeticUtils.subAndCheck(min, -1));
-        // min == -1-max
-        Assertions.assertEquals(-1, ArithmeticUtils.subAndCheck(-max - 1, -max));
-        Assertions.assertEquals(max, ArithmeticUtils.subAndCheck(-1, -1 - max));
-        testSubAndCheckLongFailure(0L, min);
-        testSubAndCheckLongFailure(max, -1L);
-        testSubAndCheckLongFailure(min, 1L);
-    }
-
-    @Test
     public void testPow() {
 
         Assertions.assertEquals(1801088541, ArithmeticUtils.pow(21, 7));
@@ -534,15 +488,6 @@ public class ArithmeticUtilsTest {
         }
     }
 
-    private void testSubAndCheckLongFailure(long a, long b) {
-        try {
-            ArithmeticUtils.subAndCheck(a, b);
-            Assertions.fail("Expecting ArithmeticException");
-        } catch (ArithmeticException ex) {
-            // success
-        }
-    }
-
     /**
      * Testing helper method.
      * @return an array of int numbers containing corner cases:<ul>
diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java
index 41132e0..5fd740e 100644
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java
+++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java
@@ -474,7 +474,7 @@ public class Fraction
         int d1 = ArithmeticUtils.gcd(denominator, fraction.denominator);
         int uvp = ArithmeticUtils.mulAndCheck(numerator, fraction.denominator / d1);
         int upv = ArithmeticUtils.mulAndCheck(fraction.numerator, denominator / d1);
-        int t = isAdd ? Math.addExact(uvp, upv) : ArithmeticUtils.subAndCheck(uvp, upv);
+        int t = isAdd ? Math.addExact(uvp, upv) : Math.subtractExact(uvp, upv);
         int tmodd1 = t % d1;
         int d2 = (tmodd1==0)?d1:ArithmeticUtils.gcd(tmodd1, d1);
         // result is (t/d2) / (u'/d1)(v'/d2)


[commons-numbers] 03/04: NUMBERS-116: Remove mulAndCheck methods

Posted by er...@apache.org.
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 1512d65dfa987b34e31582ba4b6ce52cdbcc3b7a
Author: Schamschi <he...@gmx.at>
AuthorDate: Sun Jun 16 11:36:17 2019 +0200

    NUMBERS-116: Remove mulAndCheck methods
---
 .../numbers/combinatorics/BinomialCoefficient.java |  2 +-
 .../commons/numbers/core/ArithmeticUtils.java      | 82 ++--------------------
 .../commons/numbers/core/ArithmeticUtilsTest.java  | 48 -------------
 .../apache/commons/numbers/fraction/Fraction.java  | 10 +--
 4 files changed, 12 insertions(+), 130 deletions(-)

diff --git a/commons-numbers-combinatorics/src/main/java/org/apache/commons/numbers/combinatorics/BinomialCoefficient.java b/commons-numbers-combinatorics/src/main/java/org/apache/commons/numbers/combinatorics/BinomialCoefficient.java
index 8c34df1..0f4929f 100644
--- a/commons-numbers-combinatorics/src/main/java/org/apache/commons/numbers/combinatorics/BinomialCoefficient.java
+++ b/commons-numbers-combinatorics/src/main/java/org/apache/commons/numbers/combinatorics/BinomialCoefficient.java
@@ -96,7 +96,7 @@ public class BinomialCoefficient {
             int i = n - k + 1;
             for (int j = 1; j <= k; j++) {
                 final long d = ArithmeticUtils.gcd(i, j);
-                result = ArithmeticUtils.mulAndCheck(result / (j / d), i / d);
+                result = Math.multiplyExact(result / (j / d), i / d);
                 ++i;
             }
         }
diff --git a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java
index 3df1cb4..8895328 100644
--- a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java
+++ b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java
@@ -290,7 +290,7 @@ public final class ArithmeticUtils {
         if (a == 0 || b == 0){
             return 0;
         }
-        int lcm = Math.abs(ArithmeticUtils.mulAndCheck(a / gcd(a, b), b));
+        int lcm = Math.abs(Math.multiplyExact(a / gcd(a, b), b));
         if (lcm == Integer.MIN_VALUE) {
             throw new NumbersArithmeticException("overflow: lcm({0}, {1}) is 2^31",
                                               a, b);
@@ -323,7 +323,7 @@ public final class ArithmeticUtils {
         if (a == 0 || b == 0){
             return 0;
         }
-        long lcm = Math.abs(ArithmeticUtils.mulAndCheck(a / gcd(a, b), b));
+        long lcm = Math.abs(Math.multiplyExact(a / gcd(a, b), b));
         if (lcm == Long.MIN_VALUE){
             throw new NumbersArithmeticException("overflow: lcm({0}, {1}) is 2^63",
                                               a, b);
@@ -332,76 +332,6 @@ public final class ArithmeticUtils {
     }
 
     /**
-     * Multiply two integers, checking for overflow.
-     *
-     * @param x Factor.
-     * @param y Factor.
-     * @return the product {@code x * y}.
-     * @throws ArithmeticException if the result can not be
-     * represented as an {@code int}.
-     */
-    public static int mulAndCheck(int x, int y) {
-        long m = ((long)x) * ((long)y);
-        if (m < Integer.MIN_VALUE || m > Integer.MAX_VALUE) {
-            throw new NumbersArithmeticException();
-        }
-        return (int)m;
-    }
-
-    /**
-     * Multiply two long integers, checking for overflow.
-     *
-     * @param a Factor.
-     * @param b Factor.
-     * @return the product {@code a * b}.
-     * @throws ArithmeticException if the result can not be represented
-     * as a {@code long}.
-     */
-    public static long mulAndCheck(long a, long b) {
-        long ret;
-        if (a > b) {
-            // use symmetry to reduce boundary cases
-            ret = mulAndCheck(b, a);
-        } else {
-            if (a < 0) {
-                if (b < 0) {
-                    // check for positive overflow with negative a, negative b
-                    if (a >= Long.MAX_VALUE / b) {
-                        ret = a * b;
-                    } else {
-                        throw new NumbersArithmeticException();
-                    }
-                } else if (b > 0) {
-                    // check for negative overflow with negative a, positive b
-                    if (Long.MIN_VALUE / b <= a) {
-                        ret = a * b;
-                    } else {
-                        throw new NumbersArithmeticException();
-
-                    }
-                } else {
-                    // assert b == 0
-                    ret = 0;
-                }
-            } else if (a > 0) {
-                // assert a > 0
-                // assert b > 0
-
-                // check for positive overflow with positive a, positive b
-                if (a <= Long.MAX_VALUE / b) {
-                    ret = a * b;
-                } else {
-                    throw new NumbersArithmeticException();
-                }
-            } else {
-                // assert a == 0
-                ret = 0;
-            }
-        }
-        return ret;
-    }
-
-    /**
      * Raise an int to an int power.
      *
      * @param k Number to raise.
@@ -421,7 +351,7 @@ public final class ArithmeticUtils {
         int k2p    = k;
         while (true) {
             if ((exp & 0x1) != 0) {
-                result = mulAndCheck(result, k2p);
+                result = Math.multiplyExact(result, k2p);
             }
 
             exp >>= 1;
@@ -429,7 +359,7 @@ public final class ArithmeticUtils {
                 break;
             }
 
-            k2p = mulAndCheck(k2p, k2p);
+            k2p = Math.multiplyExact(k2p, k2p);
         }
 
         return result;
@@ -455,7 +385,7 @@ public final class ArithmeticUtils {
         long k2p    = k;
         while (true) {
             if ((exp & 0x1) != 0) {
-                result = mulAndCheck(result, k2p);
+                result = Math.multiplyExact(result, k2p);
             }
 
             exp >>= 1;
@@ -463,7 +393,7 @@ public final class ArithmeticUtils {
                 break;
             }
 
-            k2p = mulAndCheck(k2p, k2p);
+            k2p = Math.multiplyExact(k2p, k2p);
         }
 
         return result;
diff --git a/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/ArithmeticUtilsTest.java b/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/ArithmeticUtilsTest.java
index 3a3b45b..fe0ce08 100644
--- a/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/ArithmeticUtilsTest.java
+++ b/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/ArithmeticUtilsTest.java
@@ -254,45 +254,6 @@ public class ArithmeticUtilsTest {
     }
 
     @Test
-    public void testMulAndCheck() {
-        int big = Integer.MAX_VALUE;
-        int bigNeg = Integer.MIN_VALUE;
-        Assertions.assertEquals(big, ArithmeticUtils.mulAndCheck(big, 1));
-        try {
-            ArithmeticUtils.mulAndCheck(big, 2);
-            Assertions.fail("Expecting ArithmeticException");
-        } catch (ArithmeticException ex) {
-        }
-        try {
-            ArithmeticUtils.mulAndCheck(bigNeg, 2);
-            Assertions.fail("Expecting ArithmeticException");
-        } catch (ArithmeticException ex) {
-        }
-    }
-
-    @Test
-    public void testMulAndCheckLong() {
-        long max = Long.MAX_VALUE;
-        long min = Long.MIN_VALUE;
-        Assertions.assertEquals(max, ArithmeticUtils.mulAndCheck(max, 1L));
-        Assertions.assertEquals(min, ArithmeticUtils.mulAndCheck(min, 1L));
-        Assertions.assertEquals(0L, ArithmeticUtils.mulAndCheck(max, 0L));
-        Assertions.assertEquals(0L, ArithmeticUtils.mulAndCheck(min, 0L));
-        Assertions.assertEquals(max, ArithmeticUtils.mulAndCheck(1L, max));
-        Assertions.assertEquals(min, ArithmeticUtils.mulAndCheck(1L, min));
-        Assertions.assertEquals(0L, ArithmeticUtils.mulAndCheck(0L, max));
-        Assertions.assertEquals(0L, ArithmeticUtils.mulAndCheck(0L, min));
-        Assertions.assertEquals(1L, ArithmeticUtils.mulAndCheck(-1L, -1L));
-        Assertions.assertEquals(min, ArithmeticUtils.mulAndCheck(min / 2, 2));
-        testMulAndCheckLongFailure(max, 2L);
-        testMulAndCheckLongFailure(2L, max);
-        testMulAndCheckLongFailure(min, 2L);
-        testMulAndCheckLongFailure(2L, min);
-        testMulAndCheckLongFailure(min, -1L);
-        testMulAndCheckLongFailure(-1L, min);
-    }
-
-    @Test
     public void testPow() {
 
         Assertions.assertEquals(1801088541, ArithmeticUtils.pow(21, 7));
@@ -479,15 +440,6 @@ public class ArithmeticUtilsTest {
         }
     }
 
-    private void testMulAndCheckLongFailure(long a, long b) {
-        try {
-            ArithmeticUtils.mulAndCheck(a, b);
-            Assertions.fail("Expecting ArithmeticException");
-        } catch (ArithmeticException ex) {
-            // success
-        }
-    }
-
     /**
      * Testing helper method.
      * @return an array of int numbers containing corner cases:<ul>
diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java
index 5fd740e..f741c52 100644
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java
+++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java
@@ -472,14 +472,14 @@ public class Fraction
         }
         // t = u(v'/gcd) +/- v(u'/gcd)
         int d1 = ArithmeticUtils.gcd(denominator, fraction.denominator);
-        int uvp = ArithmeticUtils.mulAndCheck(numerator, fraction.denominator / d1);
-        int upv = ArithmeticUtils.mulAndCheck(fraction.numerator, denominator / d1);
+        int uvp = Math.multiplyExact(numerator, fraction.denominator / d1);
+        int upv = Math.multiplyExact(fraction.numerator, denominator / d1);
         int t = isAdd ? Math.addExact(uvp, upv) : Math.subtractExact(uvp, upv);
         int tmodd1 = t % d1;
         int d2 = (tmodd1==0)?d1:ArithmeticUtils.gcd(tmodd1, d1);
         // result is (t/d2) / (u'/d1)(v'/d2)
         int w = t / d2;
-        return new Fraction (w, ArithmeticUtils.mulAndCheck(denominator/d1,
+        return new Fraction (w, Math.multiplyExact(denominator/d1,
                         fraction.denominator/d2));
     }
 
@@ -505,8 +505,8 @@ public class Fraction
         int d1 = ArithmeticUtils.gcd(numerator, fraction.denominator);
         int d2 = ArithmeticUtils.gcd(fraction.numerator, denominator);
         return getReducedFraction
-        (ArithmeticUtils.mulAndCheck(numerator/d1, fraction.numerator/d2),
-                ArithmeticUtils.mulAndCheck(denominator/d2, fraction.denominator/d1));
+        (Math.multiplyExact(numerator/d1, fraction.numerator/d2),
+                Math.multiplyExact(denominator/d2, fraction.denominator/d1));
     }
 
     /**


[commons-numbers] 01/04: NUMBERS-116: Remove addAndCheck methods

Posted by er...@apache.org.
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 5c9d177a09f16d35d8db3b39b82c4bc577f853f3
Author: Schamschi <he...@gmx.at>
AuthorDate: Sat Jun 15 23:40:02 2019 +0200

    NUMBERS-116: Remove addAndCheck methods
---
 .../combinatorics/BinomialCoefficientTest.java     |  2 +-
 .../commons/numbers/core/ArithmeticUtils.java      | 31 --------------
 .../commons/numbers/core/ArithmeticUtilsTest.java  | 47 ----------------------
 .../apache/commons/numbers/fraction/Fraction.java  |  2 +-
 4 files changed, 2 insertions(+), 80 deletions(-)

diff --git a/commons-numbers-combinatorics/src/test/java/org/apache/commons/numbers/combinatorics/BinomialCoefficientTest.java b/commons-numbers-combinatorics/src/test/java/org/apache/commons/numbers/combinatorics/BinomialCoefficientTest.java
index 9c1dde2..71d26eb 100644
--- a/commons-numbers-combinatorics/src/test/java/org/apache/commons/numbers/combinatorics/BinomialCoefficientTest.java
+++ b/commons-numbers-combinatorics/src/test/java/org/apache/commons/numbers/combinatorics/BinomialCoefficientTest.java
@@ -197,7 +197,7 @@ public class BinomialCoefficientTest {
             if (k > 100) {
                 binomialCoefficient(n - 100, k - 100);
             }
-            result = ArithmeticUtils.addAndCheck(binomialCoefficient(n - 1, k - 1),
+            result = Math.addExact(binomialCoefficient(n - 1, k - 1),
                                                  binomialCoefficient(n - 1, k));
         }
         if (result == -1) {
diff --git a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java
index 633dd3d..84f44aa 100644
--- a/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java
+++ b/commons-numbers-core/src/main/java/org/apache/commons/numbers/core/ArithmeticUtils.java
@@ -26,8 +26,6 @@ import java.text.MessageFormat;
  */
 public final class ArithmeticUtils {
 
-    /** Overflow addition exception message. */
-    private static final String OVERFLOW_IN_ADDITION_MESSAGE = "overflow in addition: {0} + {1}";
     /** Overflow gcd exception message for 2^31. */
     private static final String OVERFLOW_GCD_MESSAGE_2_POWER_31 = "overflow: gcd({0}, {1}) is 2^31";
     /** Overflow gcd exception message for 2^63. */
@@ -46,35 +44,6 @@ public final class ArithmeticUtils {
     }
 
     /**
-     * Add two integers, checking for overflow.
-     *
-     * @param x an addend
-     * @param y an addend
-     * @return the sum {@code x+y}
-     * @throws ArithmeticException if the result can not be represented
-     * as an {@code int}.
-     */
-    public static int addAndCheck(int x, int y) {
-        long s = (long)x + (long)y;
-        if (s < Integer.MIN_VALUE || s > Integer.MAX_VALUE) {
-            throw new NumbersArithmeticException(OVERFLOW_IN_ADDITION_MESSAGE, x, y);
-        }
-        return (int)s;
-    }
-
-    /**
-     * Add two long integers, checking for overflow.
-     *
-     * @param a an addend
-     * @param b an addend
-     * @return the sum {@code a+b}
-     * @throws ArithmeticException if the result can not be represented as an long
-     */
-    public static long addAndCheck(long a, long b) {
-        return addAndCheck(a, b, OVERFLOW_IN_ADDITION_MESSAGE);
-    }
-
-    /**
      * Computes the greatest common divisor of the absolute value of two
      * numbers, using a modified version of the "binary gcd" method.
      * See Knuth 4.5.2 algorithm B.
diff --git a/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/ArithmeticUtilsTest.java b/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/ArithmeticUtilsTest.java
index f23fe2d..edee964 100644
--- a/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/ArithmeticUtilsTest.java
+++ b/commons-numbers-core/src/test/java/org/apache/commons/numbers/core/ArithmeticUtilsTest.java
@@ -30,44 +30,6 @@ import org.junit.jupiter.api.Test;
 public class ArithmeticUtilsTest {
 
     @Test
-    public void testAddAndCheck() {
-        int big = Integer.MAX_VALUE;
-        int bigNeg = Integer.MIN_VALUE;
-        Assertions.assertEquals(big, ArithmeticUtils.addAndCheck(big, 0));
-        try {
-            ArithmeticUtils.addAndCheck(big, 1);
-            Assertions.fail("Expecting ArithmeticException");
-        } catch (ArithmeticException ex) {
-        }
-        try {
-            ArithmeticUtils.addAndCheck(bigNeg, -1);
-            Assertions.fail("Expecting ArithmeticException");
-        } catch (ArithmeticException ex) {
-        }
-    }
-
-    @Test
-    public void testAddAndCheckLong() {
-        long max = Long.MAX_VALUE;
-        long min = Long.MIN_VALUE;
-        Assertions.assertEquals(max, ArithmeticUtils.addAndCheck(max, 0L));
-        Assertions.assertEquals(min, ArithmeticUtils.addAndCheck(min, 0L));
-        Assertions.assertEquals(max, ArithmeticUtils.addAndCheck(0L, max));
-        Assertions.assertEquals(min, ArithmeticUtils.addAndCheck(0L, min));
-        Assertions.assertEquals(1, ArithmeticUtils.addAndCheck(-1L, 2L));
-        Assertions.assertEquals(1, ArithmeticUtils.addAndCheck(2L, -1L));
-        Assertions.assertEquals(-3, ArithmeticUtils.addAndCheck(-2L, -1L));
-        Assertions.assertEquals(min, ArithmeticUtils.addAndCheck(min + 1, -1L));
-        Assertions.assertEquals(-1, ArithmeticUtils.addAndCheck(min, max));
-        testAddAndCheckLongFailure(max, 1L);
-        testAddAndCheckLongFailure(min, -1L);
-        testAddAndCheckLongFailure(1L, max);
-        testAddAndCheckLongFailure(-1L, min);
-        testAddAndCheckLongFailure(max, max);
-        testAddAndCheckLongFailure(min, min);
-    }
-
-    @Test
     public void testGcd() {
         int a = 30;
         int b = 50;
@@ -563,15 +525,6 @@ public class ArithmeticUtilsTest {
         }
     }
 
-    private void testAddAndCheckLongFailure(long a, long b) {
-        try {
-            ArithmeticUtils.addAndCheck(a, b);
-            Assertions.fail("Expecting ArithmeticException");
-        } catch (ArithmeticException ex) {
-            // success
-        }
-    }
-
     private void testMulAndCheckLongFailure(long a, long b) {
         try {
             ArithmeticUtils.mulAndCheck(a, b);
diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java
index fad2d50..41132e0 100644
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java
+++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java
@@ -474,7 +474,7 @@ public class Fraction
         int d1 = ArithmeticUtils.gcd(denominator, fraction.denominator);
         int uvp = ArithmeticUtils.mulAndCheck(numerator, fraction.denominator / d1);
         int upv = ArithmeticUtils.mulAndCheck(fraction.numerator, denominator / d1);
-        int t = isAdd ? ArithmeticUtils.addAndCheck(uvp, upv) : ArithmeticUtils.subAndCheck(uvp, upv);
+        int t = isAdd ? Math.addExact(uvp, upv) : ArithmeticUtils.subAndCheck(uvp, upv);
         int tmodd1 = t % d1;
         int d2 = (tmodd1==0)?d1:ArithmeticUtils.gcd(tmodd1, d1);
         // result is (t/d2) / (u'/d1)(v'/d2)