You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2021/12/16 17:10:40 UTC

[commons-numbers] branch master updated (20f1db2 -> 765afd0)

This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git.


    from 20f1db2  Avoid underflow computing the initial value
     new abba5da  Remove dependency on Precision
     new 765afd0  Remove redundant variable assignment

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 commons-numbers-rootfinder/pom.xml                   |  7 -------
 .../commons/numbers/rootfinder/BrentSolver.java      | 20 ++++++++++++++------
 2 files changed, 14 insertions(+), 13 deletions(-)

[commons-numbers] 01/02: Remove dependency on Precision

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git

commit abba5dabdd6d800f915a4147af7987ecb9b2d20d
Author: aherbert <ah...@apache.org>
AuthorDate: Thu Dec 16 16:32:51 2021 +0000

    Remove dependency on Precision
    
    Since this was used to compare to zero the method can be more simply
    implemented:
    
    Precision.equals(b, 0) == Math.abs(b) <= Double.MIN_VALUE
---
 commons-numbers-rootfinder/pom.xml                          |  7 -------
 .../org/apache/commons/numbers/rootfinder/BrentSolver.java  | 13 +++++++++++--
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/commons-numbers-rootfinder/pom.xml b/commons-numbers-rootfinder/pom.xml
index 43ebe4f..f797818 100644
--- a/commons-numbers-rootfinder/pom.xml
+++ b/commons-numbers-rootfinder/pom.xml
@@ -40,11 +40,4 @@
     <numbers.parent.dir>${basedir}/..</numbers.parent.dir>
   </properties>
 
-  <dependencies>
-    <dependency>
-      <groupId>org.apache.commons</groupId>
-      <artifactId>commons-numbers-core</artifactId>
-    </dependency>
-  </dependencies>
-
 </project>
diff --git a/commons-numbers-rootfinder/src/main/java/org/apache/commons/numbers/rootfinder/BrentSolver.java b/commons-numbers-rootfinder/src/main/java/org/apache/commons/numbers/rootfinder/BrentSolver.java
index ad58019..ad80fa5 100644
--- a/commons-numbers-rootfinder/src/main/java/org/apache/commons/numbers/rootfinder/BrentSolver.java
+++ b/commons-numbers-rootfinder/src/main/java/org/apache/commons/numbers/rootfinder/BrentSolver.java
@@ -17,7 +17,6 @@
 package org.apache.commons.numbers.rootfinder;
 
 import java.util.function.DoubleUnaryOperator;
-import org.apache.commons.numbers.core.Precision;
 
 /**
  * This class implements the <a href="http://mathworld.wolfram.com/BrentsMethod.html">
@@ -185,7 +184,7 @@ public class BrentSolver {
             final double m = 0.5 * (c - b);
 
             if (Math.abs(m) <= tol ||
-                Precision.equals(fb, 0))  {
+                equalsZero(fb))  {
                 return b;
             }
             if (Math.abs(e) < tol ||
@@ -249,4 +248,14 @@ public class BrentSolver {
             }
         }
     }
+
+    /**
+     * Return true if the value is within 1 ULP of zero.
+     *
+     * @param value Value
+     * @return true if zero within a 1 ULP tolerance
+     */
+    private static boolean equalsZero(double value) {
+        return Math.abs(value) <= Double.MIN_VALUE;
+    }
 }

[commons-numbers] 02/02: Remove redundant variable assignment

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git

commit 765afd0beccaa420db537ce1c0bf668c8fb913fc
Author: aherbert <ah...@apache.org>
AuthorDate: Thu Dec 16 16:34:00 2021 +0000

    Remove redundant variable assignment
    
    Use e directly and update to d in the condition that accepts the
    interpolation. The condition that rejects interpolation updates e
    anyway.
---
 .../java/org/apache/commons/numbers/rootfinder/BrentSolver.java    | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/commons-numbers-rootfinder/src/main/java/org/apache/commons/numbers/rootfinder/BrentSolver.java b/commons-numbers-rootfinder/src/main/java/org/apache/commons/numbers/rootfinder/BrentSolver.java
index ad80fa5..13a5bbc 100644
--- a/commons-numbers-rootfinder/src/main/java/org/apache/commons/numbers/rootfinder/BrentSolver.java
+++ b/commons-numbers-rootfinder/src/main/java/org/apache/commons/numbers/rootfinder/BrentSolver.java
@@ -193,7 +193,7 @@ public class BrentSolver {
                 d = m;
                 e = d;
             } else {
-                double s = fb / fa;
+                final double s = fb / fa;
                 double p;
                 double q;
                 // The equality test (a == c) is intentional,
@@ -215,16 +215,15 @@ public class BrentSolver {
                 } else {
                     p = -p;
                 }
-                s = e;
-                e = d;
                 if (p >= 1.5 * m * q - Math.abs(tol * q) ||
-                    p >= Math.abs(0.5 * s * q)) {
+                    p >= Math.abs(0.5 * e * q)) {
                     // Inverse quadratic interpolation gives a value
                     // in the wrong direction, or progress is slow.
                     // Fall back to bisection.
                     d = m;
                     e = d;
                 } else {
+                    e = d;
                     d = p / q;
                 }
             }