commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From celes...@apache.org
Subject svn commit: r1294027 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math3/fraction/BigFraction.java test/java/org/apache/commons/math3/fraction/BigFractionTest.java
Date Mon, 27 Feb 2012 04:38:45 GMT
Author: celestin
Date: Mon Feb 27 04:38:45 2012
New Revision: 1294027

URL: http://svn.apache.org/viewvc?rev=1294027&view=rev
Log:
BigFraction.divide(BigFraction) now throws MathArithmeticException (see MATH-755).

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fraction/BigFraction.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/fraction/BigFractionTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fraction/BigFraction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fraction/BigFraction.java?rev=1294027&r1=1294026&r2=1294027&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fraction/BigFraction.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fraction/BigFraction.java
Mon Feb 27 04:38:45 2012
@@ -21,13 +21,14 @@ import java.math.BigDecimal;
 import java.math.BigInteger;
 
 import org.apache.commons.math3.FieldElement;
+import org.apache.commons.math3.exception.MathArithmeticException;
 import org.apache.commons.math3.exception.MathIllegalArgumentException;
 import org.apache.commons.math3.exception.NullArgumentException;
 import org.apache.commons.math3.exception.ZeroException;
 import org.apache.commons.math3.exception.util.LocalizedFormats;
+import org.apache.commons.math3.util.ArithmeticUtils;
 import org.apache.commons.math3.util.FastMath;
 import org.apache.commons.math3.util.MathUtils;
-import org.apache.commons.math3.util.ArithmeticUtils;
 
 /**
  * Representation of a rational number without any overflow. This class is
@@ -598,36 +599,34 @@ public class BigFraction
 
     /**
      * <p>
-     * Divide the value of this fraction by the passed <code>BigInteger</code>,
-     * ie "this * 1 / bg", returning the result in reduced form.
+     * Divide the value of this fraction by the passed {@code BigInteger},
+     * ie {@code this * 1 / bg}, returning the result in reduced form.
      * </p>
      *
-     * @param bg
-     *            the <code>BigInteger</code> to divide by, must not be
-     *            <code>null</code>.
-     * @return a {@link BigFraction} instance with the resulting values.
-     * @throws NullArgumentException if the {@code BigInteger} is {@code null}.
-     * @throws ZeroException
-     *             if the fraction to divide by is zero.
+     * @param bg the {@code BigInteger} to divide by, must not be {@code null}
+     * @return a {@link BigFraction} instance with the resulting values
+     * @throws NullArgumentException if the {@code BigInteger} is {@code null}
+     * @throws MathArithmeticException if the fraction to divide by is zero
      */
     public BigFraction divide(final BigInteger bg) {
+        if (bg == null) {
+            throw new NullArgumentException(LocalizedFormats.FRACTION);
+        }
         if (BigInteger.ZERO.equals(bg)) {
-            throw new ZeroException(LocalizedFormats.ZERO_DENOMINATOR);
+            throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR);
         }
         return new BigFraction(numerator, denominator.multiply(bg));
     }
 
     /**
      * <p>
-     * Divide the value of this fraction by the passed <tt>int</tt>, ie
-     * "this * 1 / i", returning the result in reduced form.
+     * Divide the value of this fraction by the passed {@code int}, ie
+     * {@code this * 1 / i}, returning the result in reduced form.
      * </p>
      *
-     * @param i
-     *            the <tt>int</tt> to divide by.
-     * @return a {@link BigFraction} instance with the resulting values.
-     * @throws ArithmeticException
-     *             if the fraction to divide by is zero.
+     * @param i the {@code int} to divide by
+     * @return a {@link BigFraction} instance with the resulting values
+     * @throws MathArithmeticException if the fraction to divide by is zero
      */
     public BigFraction divide(final int i) {
         return divide(BigInteger.valueOf(i));
@@ -635,15 +634,13 @@ public class BigFraction
 
     /**
      * <p>
-     * Divide the value of this fraction by the passed <tt>long</tt>, ie
-     * "this * 1 / l", returning the result in reduced form.
+     * Divide the value of this fraction by the passed {@code long}, ie
+     * {@code this * 1 / l}, returning the result in reduced form.
      * </p>
      *
-     * @param l
-     *            the <tt>long</tt> to divide by.
-     * @return a {@link BigFraction} instance with the resulting values.
-     * @throws ArithmeticException
-     *             if the fraction to divide by is zero.
+     * @param l the {@code long} to divide by
+     * @return a {@link BigFraction} instance with the resulting values
+     * @throws MathArithmeticException if the fraction to divide by is zero
      */
     public BigFraction divide(final long l) {
         return divide(BigInteger.valueOf(l));
@@ -658,14 +655,14 @@ public class BigFraction
      * @param fraction Fraction to divide by, must not be {@code null}.
      * @return a {@link BigFraction} instance with the resulting values.
      * @throws NullArgumentException if the {@code fraction} is {@code null}.
-     * @throws ZeroException if the fraction to divide by is zero.
+     * @throws MathArithmeticException if the fraction to divide by is zero
      */
     public BigFraction divide(final BigFraction fraction) {
         if (fraction == null) {
             throw new NullArgumentException(LocalizedFormats.FRACTION);
         }
         if (BigInteger.ZERO.equals(fraction.numerator)) {
-            throw new ZeroException(LocalizedFormats.ZERO_DENOMINATOR);
+            throw new MathArithmeticException(LocalizedFormats.ZERO_DENOMINATOR);
         }
 
         return multiply(fraction.reciprocal());

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/fraction/BigFractionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/fraction/BigFractionTest.java?rev=1294027&r1=1294026&r2=1294027&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/fraction/BigFractionTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/fraction/BigFractionTest.java
Mon Feb 27 04:38:45 2012
@@ -21,6 +21,7 @@ import java.math.BigInteger;
 
 import org.apache.commons.math3.TestUtils;
 import org.apache.commons.math3.exception.ConvergenceException;
+import org.apache.commons.math3.exception.MathArithmeticException;
 import org.apache.commons.math3.exception.NullArgumentException;
 import org.apache.commons.math3.exception.ZeroException;
 import org.apache.commons.math3.util.FastMath;
@@ -423,8 +424,8 @@ public class BigFractionTest {
         BigFraction f2 = BigFraction.ZERO;
         try {
             f1.divide(f2);
-            Assert.fail("expecting ArithmeticException");
-        } catch (ZeroException ex) {
+            Assert.fail("expecting MathArithmeticException");
+        } catch (MathArithmeticException ex) {
         }
 
         f1 = new BigFraction(0, 5);



Mime
View raw message