You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by br...@apache.org on 2005/08/22 14:54:46 UTC
svn commit: r234481 - in /jakarta/commons/proper/math/branches/MATH_1_1:
src/java/org/apache/commons/math/util/MathUtils.java
src/test/org/apache/commons/math/util/MathUtilsTest.java xdocs/changes.xml
Author: brentworden
Date: Mon Aug 22 05:54:42 2005
New Revision: 234481
URL: http://svn.apache.org/viewcvs?rev=234481&view=rev
Log:
PR: 36300
Fixed division by zero error in rounding methods.
Modified:
jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/util/MathUtils.java
jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/util/MathUtilsTest.java
jakarta/commons/proper/math/branches/MATH_1_1/xdocs/changes.xml
Modified: jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/util/MathUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/util/MathUtils.java?rev=234481&r1=234480&r2=234481&view=diff
==============================================================================
--- jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/util/MathUtils.java (original)
+++ jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/util/MathUtils.java Mon Aug 22 05:54:42 2005
@@ -499,7 +499,7 @@
* @since 1.1
*/
public static double round(double x, int scale, int roundingMethod) {
- double sign = sign(x);
+ double sign = indicator(x);
double factor = Math.pow(10.0, scale) * sign;
return roundUnscaled(x * factor, sign, roundingMethod) / factor;
}
@@ -530,7 +530,7 @@
* @since 1.1
*/
public static float round(float x, int scale, int roundingMethod) {
- float sign = sign(x);
+ float sign = indicator(x);
float factor = (float)Math.pow(10.0f, scale) * sign;
return (float)roundUnscaled(x * factor, sign, roundingMethod) / factor;
}
Modified: jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/util/MathUtilsTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/util/MathUtilsTest.java?rev=234481&r1=234480&r2=234481&view=diff
==============================================================================
--- jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/util/MathUtilsTest.java (original)
+++ jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/util/MathUtilsTest.java Mon Aug 22 05:54:42 2005
@@ -17,6 +17,8 @@
import java.math.BigDecimal;
+import org.apache.commons.math.TestUtils;
+
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -556,6 +558,12 @@
} catch (IllegalArgumentException ex) {
// success
}
+
+ // special values
+ TestUtils.assertEquals(Float.NaN, MathUtils.round(Float.NaN, 2), 0.0f);
+ assertEquals(0.0f, MathUtils.round(0.0f, 2), 0.0f);
+ assertEquals(Float.POSITIVE_INFINITY, MathUtils.round(Float.POSITIVE_INFINITY, 2), 0.0f);
+ assertEquals(Float.NEGATIVE_INFINITY, MathUtils.round(Float.NEGATIVE_INFINITY, 2), 0.0f);
}
public void testRoundDouble() {
@@ -646,5 +654,11 @@
} catch (IllegalArgumentException ex) {
// success
}
+
+ // special values
+ TestUtils.assertEquals(Double.NaN, MathUtils.round(Double.NaN, 2), 0.0);
+ assertEquals(0.0, MathUtils.round(0.0, 2), 0.0);
+ assertEquals(Double.POSITIVE_INFINITY, MathUtils.round(Double.POSITIVE_INFINITY, 2), 0.0);
+ assertEquals(Double.NEGATIVE_INFINITY, MathUtils.round(Double.NEGATIVE_INFINITY, 2), 0.0);
}
}
Modified: jakarta/commons/proper/math/branches/MATH_1_1/xdocs/changes.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/math/branches/MATH_1_1/xdocs/changes.xml?rev=234481&r1=234480&r2=234481&view=diff
==============================================================================
--- jakarta/commons/proper/math/branches/MATH_1_1/xdocs/changes.xml (original)
+++ jakarta/commons/proper/math/branches/MATH_1_1/xdocs/changes.xml Mon Aug 22 05:54:42 2005
@@ -45,7 +45,10 @@
and numerical utilities, and a PRNG pluggability framework making it
possible to replace the JDK-supplied random number generator in
commons-math (and elsewhere) with alternative PRNG implementations.">
- <action dev="brentworden" type="update" issue="36215" due-to="Mike Hu">
+ <action dev="brentworden" type="fix" issue="36300" due-to="Nikhil Gupte">
+ Fixed division by zero error in rounding methods.
+ </action>
+ <action dev="brentworden" type="fix" issue="36215" due-to="Mike Hu">
Added upper tail cumulative probability method to HypergeometricDistributionImpl.
</action>
<action dev="brentworden" type="fix" issue="36205" due-to="Xiaogang Zhang">
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org