commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r226479 - in /jakarta/commons/proper/math/trunk/src: java/org/apache/commons/math/util/MathUtils.java test/org/apache/commons/math/util/MathUtilsTest.java
Date Sat, 30 Jul 2005 07:25:36 GMT
Author: psteitz
Date: Sat Jul 30 00:25:26 2005
New Revision: 226479

URL: http://svn.apache.org/viewcvs?rev=226479&view=rev
Log:
Test cases and (temporary?) fix for BZ 35904.

Modified:
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/util/MathUtilsTest.java

Modified: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java?rev=226479&r1=226478&r2=226479&view=diff
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java
(original)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java
Sat Jul 30 00:25:26 2005
@@ -75,7 +75,7 @@
     public static double round(
         double x, int scale, int roundingMethod)
     {
-        return (new BigDecimal(x).setScale(scale, roundingMethod))
+        return (new BigDecimal(new Double(x).toString()).setScale(scale, roundingMethod))
             .doubleValue();
     }
     
@@ -103,7 +103,7 @@
      * @since 1.1
      */
     public static float round(float x, int scale, int roundingMethod) {
-        return (new BigDecimal(x).setScale(scale, roundingMethod)).floatValue();
+        return (new BigDecimal(new Float(x).toString()).setScale(scale, roundingMethod)).floatValue();
     }
     
     /**

Modified: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/util/MathUtilsTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/util/MathUtilsTest.java?rev=226479&r1=226478&r2=226479&view=diff
==============================================================================
--- jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/util/MathUtilsTest.java
(original)
+++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/util/MathUtilsTest.java
Sat Jul 30 00:25:26 2005
@@ -477,6 +477,16 @@
         assertEquals(1.23f, MathUtils.round(x, 2), 0.0f);
         assertEquals(1.235f, MathUtils.round(x, 3), 0.0f);
         assertEquals(1.2346f, MathUtils.round(x, 4), 0.0f);
+        
+        
+        // BZ 35904
+        assertEquals(30.1f, MathUtils.round(30.095f, 2), 0.0f);
+        assertEquals(30.1f, MathUtils.round(30.095f, 1), 0.0f);
+        assertEquals(50.09f,  MathUtils.round(50.085f, 2), 0.0f);
+        assertEquals(50.19f,  MathUtils.round(50.185f, 2), 0.0f);
+        assertEquals(50.01f,  MathUtils.round(50.005f, 2), 0.0f);
+        assertEquals(30.01f,  MathUtils.round(30.005f, 2), 0.0f);
+        assertEquals(30.65f,  MathUtils.round(30.645f, 2), 0.0f);
 
         assertEquals(1.23f, MathUtils.round(x, 2, BigDecimal.ROUND_DOWN), 0.0f);
         assertEquals(1.234f, MathUtils.round(x, 3, BigDecimal.ROUND_DOWN), 0.0f);
@@ -488,6 +498,15 @@
         assertEquals(1.23, MathUtils.round(x, 2), 0.0);
         assertEquals(1.235, MathUtils.round(x, 3), 0.0);
         assertEquals(1.2346, MathUtils.round(x, 4), 0.0);
+        
+        // BZ 35904
+        assertEquals(30.1d, MathUtils.round(30.095d, 2), 0.0d);
+        assertEquals(30.1d, MathUtils.round(30.095d, 1), 0.0d);
+        assertEquals(50.09d,  MathUtils.round(50.085d, 2), 0.0d);
+        assertEquals(50.19d,  MathUtils.round(50.185d, 2), 0.0d);
+        assertEquals(50.01d,  MathUtils.round(50.005d, 2), 0.0d);
+        assertEquals(30.01d,  MathUtils.round(30.005d, 2), 0.0d);
+        assertEquals(30.65d,  MathUtils.round(30.645d, 2), 0.0d);
 
         assertEquals(1.23, MathUtils.round(x, 2, BigDecimal.ROUND_DOWN), 0.0);
         assertEquals(1.234, MathUtils.round(x, 3, BigDecimal.ROUND_DOWN), 0.0);



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message