commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r1203516 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/fraction/ site/xdoc/ test/java/org/apache/commons/math/fraction/
Date Fri, 18 Nov 2011 07:42:13 GMT
Author: luc
Date: Fri Nov 18 07:42:12 2011
New Revision: 1203516

URL: http://svn.apache.org/viewvc?rev=1203516&view=rev
Log:
Fixed BigFraction percentage method which did not work at all.

JIRA: MATH-709

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/BigFraction.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/Fraction.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/fraction/BigFractionTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/fraction/FractionTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/BigFraction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/BigFraction.java?rev=1203516&r1=1203515&r2=1203516&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/BigFraction.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/BigFraction.java
Fri Nov 18 07:42:12 2011
@@ -85,7 +85,7 @@ public class BigFraction
     private static final long serialVersionUID = -5630213147331578515L;
 
     /** <code>BigInteger</code> representation of 100. */
-    private static final BigInteger ONE_HUNDRED_DOUBLE = BigInteger.valueOf(100);
+    private static final BigInteger ONE_HUNDRED = BigInteger.valueOf(100);
 
     /** The numerator. */
     private final BigInteger numerator;
@@ -923,7 +923,7 @@ public class BigFraction
      * @return the fraction percentage as a <tt>double</tt>.
      */
     public double percentageValue() {
-        return (numerator.divide(denominator)).multiply(ONE_HUNDRED_DOUBLE).doubleValue();
+        return multiply(ONE_HUNDRED).doubleValue();
     }
 
     /**

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/Fraction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/Fraction.java?rev=1203516&r1=1203515&r2=1203516&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/Fraction.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/fraction/Fraction.java
Fri Nov 18 07:42:12 2011
@@ -586,6 +586,18 @@ public class Fraction
     }
 
     /**
+     * <p>
+     * Gets the fraction percentage as a <tt>double</tt>. This calculates the
+     * fraction as the numerator divided by denominator multiplied by 100.
+     * </p>
+     *
+     * @return the fraction percentage as a <tt>double</tt>.
+     */
+    public double percentageValue() {
+        return multiply(100).doubleValue();
+    }
+
+    /**
      * <p>Creates a {@code Fraction} instance with the 2 parts
      * of a fraction Y/Z.</p>
      *

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=1203516&r1=1203515&r2=1203516&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Fri Nov 18 07:42:12 2011
@@ -52,6 +52,9 @@ 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="luc" type="fix" issue="MATH-709">
+        Fixed BigFraction percentage method which did not work at all.
+      </action>
       <action dev="erans" type="update" issue="MATH-697">
         Added interface and abstract class for supporting optimizers classes
         that can take simple constraints into account.

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/fraction/BigFractionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/fraction/BigFractionTest.java?rev=1203516&r1=1203515&r2=1203516&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/fraction/BigFractionTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/fraction/BigFractionTest.java
Fri Nov 18 07:42:12 2011
@@ -558,6 +558,11 @@ public class BigFractionTest {
     }
 
     @Test
+    public void testPercentage() {
+        Assert.assertEquals(50.0, new BigFraction(1, 2).percentageValue(), 1.0e-15);
+    }
+
+    @Test
     public void testPow() {
         Assert.assertEquals(new BigFraction(8192, 1594323), new BigFraction(2, 3).pow(13));
         Assert.assertEquals(new BigFraction(8192, 1594323), new BigFraction(2, 3).pow(13l));

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/fraction/FractionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/fraction/FractionTest.java?rev=1203516&r1=1203515&r2=1203516&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/fraction/FractionTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/fraction/FractionTest.java
Fri Nov 18 07:42:12 2011
@@ -238,6 +238,11 @@ public class FractionTest {
     }
 
     @Test
+    public void testPercentage() {
+        Assert.assertEquals(50.0, new Fraction(1, 2).percentageValue(), 1.0e-15);
+    }
+
+    @Test
     public void testReciprocal() {
         Fraction f = null;
 



Mime
View raw message