Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 13850 invoked from network); 30 Jul 2005 07:25:55 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 30 Jul 2005 07:25:55 -0000 Received: (qmail 68047 invoked by uid 500); 30 Jul 2005 07:25:52 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 68017 invoked by uid 500); 30 Jul 2005 07:25:52 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 68004 invoked by uid 500); 30 Jul 2005 07:25:51 -0000 Received: (qmail 68001 invoked by uid 99); 30 Jul 2005 07:25:51 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Sat, 30 Jul 2005 00:25:40 -0700 Received: (qmail 13801 invoked by uid 65534); 30 Jul 2005 07:25:38 -0000 Message-ID: <20050730072538.13800.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commons-cvs@jakarta.apache.org From: psteitz@apache.org X-Mailer: svnmailer-1.0.2 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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