commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r1088473 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/util/MathUtils.java site/xdoc/changes.xml test/java/org/apache/commons/math/util/MathUtilsTest.java
Date Mon, 04 Apr 2011 04:51:37 GMT
Author: psteitz
Date: Mon Apr  4 04:51:37 2011
New Revision: 1088473

URL: http://svn.apache.org/viewvc?rev=1088473&view=rev
Log:
Changed MathUtils.round(double,int,int) to propagate rather than
wrap runtime exceptions.  Instead of MathRuntimeException, this method
now throws IllegalArgumentException or ArithmeticException under
the conditions specified in the javadoc.
JIRA: MATH-555



Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java?rev=1088473&r1=1088472&r2=1088473&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java Mon
Apr  4 04:51:37 2011
@@ -33,7 +33,6 @@ import org.apache.commons.math.exception
 import org.apache.commons.math.exception.NotPositiveException;
 import org.apache.commons.math.exception.MathArithmeticException;
 import org.apache.commons.math.exception.MathIllegalArgumentException;
-import org.apache.commons.math.exception.MathRuntimeException;
 import org.apache.commons.math.exception.NumberIsTooLargeException;
 import org.apache.commons.math.exception.NotFiniteNumberException;
 
@@ -1333,15 +1332,22 @@ public final class MathUtils {
     }
 
     /**
-     * Round the given value to the specified number of decimal places. The
+     * <p>Round the given value to the specified number of decimal places. The
      * value is rounded using the given method which is any method defined in
-     * {@link BigDecimal}.
+     * {@link BigDecimal}.</p>
+     *
+     * <p>If {@code x} is infinite or NaN, then the value of {@code x} is
+     * returned unchanged, regardless of the other parameters.</p>
      *
      * @param x the value to round.
      * @param scale the number of digits to the right of the decimal point.
      * @param roundingMethod the rounding method as defined in
      *        {@link BigDecimal}.
      * @return the rounded value.
+     * @throws ArithmeticException if roundingMethod==ROUND_UNNECESSARY and the
+     * specified scaling operation would require rounding.
+     * @throws IllegalArgumentException if roundingMethod does not represent a
+     * valid rounding mode.
      * @since 1.1
      */
     public static double round(double x, int scale, int roundingMethod) {
@@ -1356,8 +1362,6 @@ public final class MathUtils {
             } else {
                 return Double.NaN;
             }
-        } catch (RuntimeException ex) {
-            throw new MathRuntimeException(ex);
         }
     }
 

Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=1088473&r1=1088472&r2=1088473&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Mon Apr  4 04:51:37 2011
@@ -52,6 +52,12 @@ The <action> type attribute can be add,u
     If the output is not quite correct, check for invisible trailing spaces!
      -->
     <release version="3.0" date="TBD" description="TBD">
+      <action dev="psteitz" type="update" issue="MATH-555">
+        Changed MathUtils.round(double,int,int) to propagate rather than
+        wrap runtime exceptions.  Instead of MathRuntimeException, this method
+        now throws IllegalArgumentException or ArithmeticException under
+        the conditions specified in the javadoc.
+      </action>
       <action dev="luc" type="fix" issue="MATH-554" >
         Reduced cancellation errors in Vector3D.crossProduct
       </action>

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java?rev=1088473&r1=1088472&r2=1088473&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java
Mon Apr  4 04:51:37 2011
@@ -1136,8 +1136,8 @@ public final class MathUtilsTest {
         try {
             MathUtils.round(1.234, 2, BigDecimal.ROUND_UNNECESSARY);
             Assert.fail();
-        } catch (MathRuntimeException ex) { // XXX Loosing semantics?
-            // success
+        } catch (ArithmeticException ex) { 
+            // expected
         }
 
         Assert.assertEquals(1.24, MathUtils.round(x, 2, BigDecimal.ROUND_UP), 0.0);
@@ -1150,8 +1150,8 @@ public final class MathUtilsTest {
         try {
             MathUtils.round(1.234, 2, 1923);
             Assert.fail();
-        } catch (MathRuntimeException ex) { // XXX Loosing semantics?
-            // success
+        } catch (IllegalArgumentException ex) {
+            // expected
         }
 
         // MATH-151



Mime
View raw message