commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r620373 - in /commons/proper/math/trunk/src: java/org/apache/commons/math/complex/Complex.java java/org/apache/commons/math/fraction/Fraction.java site/xdoc/changes.xml
Date Mon, 11 Feb 2008 01:18:40 GMT
Author: psteitz
Date: Sun Feb 10 17:18:39 2008
New Revision: 620373

URL: http://svn.apache.org/viewvc?rev=620373&view=rev
Log:
Made numerator and denominator final in Fraction and
deprecated protected real and imaginary parts fields in Complex,
making Fraction immutable and preparing Complex to become fully
immutable in 2.0.
JIRA: MATH-188
Reported and patched by Sebastian Bazley

Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/complex/Complex.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/Fraction.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/complex/Complex.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/complex/Complex.java?rev=620373&r1=620372&r2=620373&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/complex/Complex.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/complex/Complex.java Sun Feb
10 17:18:39 2008
@@ -56,10 +56,16 @@
     /** A complex number representing "0.0 + 0.0i" */    
     public static final Complex ZERO = new Complex(0.0, 0.0);
     
-    /** The imaginary part */
+    /** 
+     * The imaginary part 
+     * @deprecated to be made final and private in 2.0
+     */
     protected double imaginary;
     
-    /** The real part */
+    /** 
+     * The real part 
+     * @deprecated to be made final and private in 2.0
+     */
     protected double real;
     
     /**

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/Fraction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/Fraction.java?rev=620373&r1=620372&r2=620373&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/Fraction.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/Fraction.java Sun
Feb 10 17:18:39 2008
@@ -37,10 +37,10 @@
     private static final long serialVersionUID = -8958519416450949235L;
     
     /** The denominator. */
-    private int denominator;
+    private final int denominator;
     
     /** The numerator. */
-    private int numerator;
+    private final int numerator;
 
     /**
      * Create a fraction given the double value.
@@ -210,9 +210,20 @@
             num = -num;
             den = -den;
         }
+        // reduce numerator and denominator by greatest common denominator.
+        int d = MathUtils.gcd(num, den);
+        if (d > 1) {
+            num /= d;
+            den /= d;
+        }
+        
+        // move sign to numerator.
+        if (den < 0) {
+            num *= -1;
+            den *= -1;
+        }
         this.numerator = num;
         this.denominator = den;
-        reduce();
     }
     
     /**
@@ -530,24 +541,5 @@
         numerator /= gcd;
         denominator /= gcd;
         return new Fraction(numerator, denominator);
-    }
-    
-    /**
-     * Reduce this fraction to lowest terms.  This is accomplished by dividing
-     * both numerator and denominator by their greatest common divisor.
-     */
-    private void reduce() {
-        // reduce numerator and denominator by greatest common denominator.
-        int d = MathUtils.gcd(numerator, denominator);
-        if (d > 1) {
-            numerator /= d;
-            denominator /= d;
-        }
-
-        // move sign to numerator.
-        if (denominator < 0) {
-            numerator *= -1;
-            denominator *= -1;
-        }
     }
 }

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=620373&r1=620372&r2=620373&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Sun Feb 10 17:18:39 2008
@@ -172,6 +172,12 @@
         Fixed AbstractIntegerDistribution cumulativeProbablility(-,-)
         to correctly handle double arguments.
       </action>
+      <action dev="psteitz" type="update" issue="MATH-188" due-to="Sebastian Bazley">
+        Made numerator and denominator final in Fraction and
+        deprecated protected real and imaginary parts fields in Complex,
+        making Fraction immutable and preparing Complex to become fully
+        immutable in 2.0.
+      </action>
     </release>
     <release version="1.1" date="2005-12-17"  
  description="This is a maintenance release containing bug fixes and enhancements.



Mime
View raw message