commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r617826 - in /commons/proper/math/trunk/src/java/org/apache/commons/math: analysis/BrentSolver.java analysis/MullerSolver.java util/MathUtils.java
Date Sat, 02 Feb 2008 16:39:19 GMT
Author: luc
Date: Sat Feb  2 08:39:18 2008
New Revision: 617826

URL: http://svn.apache.org/viewvc?rev=617826&view=rev
Log:
added comments in the code to explain use of real number equality tests
JIRA: MATH-183

Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/BrentSolver.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/MullerSolver.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/BrentSolver.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/BrentSolver.java?rev=617826&r1=617825&r2=617826&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/BrentSolver.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/BrentSolver.java Sat
Feb  2 08:39:18 2008
@@ -202,6 +202,9 @@
                 double r3 = y1 / y0;
                 double p;
                 double p1;
+                // the equality test (x0 == x2) is intentional,
+                // it is part of the original Brent's method,
+                // it should NOT be replaced by proximity test
                 if (x0 == x2) {
                     // Linear interpolation.
                     p = dx * r3;

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/MullerSolver.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/MullerSolver.java?rev=617826&r1=617825&r2=617826&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/MullerSolver.java
(original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/MullerSolver.java
Sat Feb  2 08:39:18 2008
@@ -153,6 +153,8 @@
 
             // Bisect if convergence is too slow. Bisection would waste
             // our calculation of x, hopefully it won't happen often.
+            // the real number equality test x == x1 is intentional and
+            // completes the proximity tests above it
             boolean bisect = (x < x1 && (x1 - x0) > 0.95 * (x2 - x0)) ||
                              (x > x1 && (x2 - x1) > 0.95 * (x2 - x0)) ||
                              (x == x1);
@@ -244,7 +246,8 @@
             }
             if (denominator != 0) {
                 x = x2 - 2.0 * C * (x2 - x1) / denominator;
-                // perturb x if it coincides with x1 or x2
+                // perturb x if it exactly coincides with x1 or x2
+                // the equality tests here are intentional
                 while (x == x1 || x == x2) {
                     x += absoluteAccuracy;
                 }

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java?rev=617826&r1=617825&r2=617826&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java Sat Feb
 2 08:39:18 2008
@@ -784,6 +784,7 @@
             } else if (fraction < 0.5) {
                 unscaled = Math.floor(unscaled);
             } else {
+                // The following equality test is intentional and needed for rounding purposes
                 if (Math.floor(unscaled) / 2.0 == Math.floor(Math
                     .floor(unscaled) / 2.0)) { // even
                     unscaled = Math.floor(unscaled);



Mime
View raw message