You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2012/07/31 16:58:02 UTC
svn commit: r1367593 - in /commons/proper/math/trunk/src: changes/changes.xml
main/java/org/apache/commons/math3/fraction/Fraction.java
test/java/org/apache/commons/math3/fraction/FractionTest.java
Author: erans
Date: Tue Jul 31 14:58:01 2012
New Revision: 1367593
URL: http://svn.apache.org/viewvc?rev=1367593&view=rev
Log:
MATH-835
Avoid overflow.
Modified:
commons/proper/math/trunk/src/changes/changes.xml
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fraction/Fraction.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/fraction/FractionTest.java
Modified: commons/proper/math/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/changes/changes.xml?rev=1367593&r1=1367592&r2=1367593&view=diff
==============================================================================
--- commons/proper/math/trunk/src/changes/changes.xml (original)
+++ commons/proper/math/trunk/src/changes/changes.xml Tue Jul 31 14:58:01 2012
@@ -52,6 +52,9 @@ If the output is not quite correct, chec
<body>
<release version="3.1" date="TBD" description="
">
+ <action dev="erans" type="fix" issue="MATH-835" due-to="Baste Nesse Buanes">
+ Fixed overflow in method "percentageValue" in class "Fraction".
+ </action>
<action dev="erans" type="fix" issue="MATH-622">
Raised (to 10) the default number of fractional digits to print out.
</action>
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fraction/Fraction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fraction/Fraction.java?rev=1367593&r1=1367592&r2=1367593&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fraction/Fraction.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fraction/Fraction.java Tue Jul 31 14:58:01 2012
@@ -594,7 +594,7 @@ public class Fraction
* @return the fraction percentage as a <tt>double</tt>.
*/
public double percentageValue() {
- return multiply(100).doubleValue();
+ return 100 * doubleValue();
}
/**
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/fraction/FractionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/fraction/FractionTest.java?rev=1367593&r1=1367592&r2=1367593&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/fraction/FractionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/fraction/FractionTest.java Tue Jul 31 14:58:01 2012
@@ -243,6 +243,17 @@ public class FractionTest {
}
@Test
+ public void testMath835() {
+ final int numer = Integer.MAX_VALUE / 99;
+ final int denom = 1;
+ final double percentage = 100 * ((double) numer) / denom;
+ final Fraction frac = new Fraction(numer, denom);
+ // With the implementation that preceded the fix suggested in MATH-835,
+ // this test was failing, due to overflow.
+ Assert.assertEquals(percentage, frac.percentageValue(), Math.ulp(percentage));
+ }
+
+ @Test
public void testReciprocal() {
Fraction f = null;