lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master fb3d854 02/11: Refactor instrumented referenc


From: Greg Chicares
Subject: [lmi-commits] [lmi] master fb3d854 02/11: Refactor instrumented reference implementation
Date: Thu, 15 Jul 2021 14:57:10 -0400 (EDT)

branch: master
commit fb3d854c628372ca644dfb19449e361bb7afc35f
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Refactor instrumented reference implementation
    
    This parallels the immediately preceding commit.
    
    Refactoring production and reference implementations separately can
    expose defects in the (identical) refactoring.
    
    ALGOL 60 did not perform short-circuit evaluation of logical {OR,AND}.
    Evaluating both conditions explicitly is thus truer to the original;
    but that doesn't matter because the affected conditions are free of
    side effects and the time to evaluate both is negligible.
---
 zero.hpp | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/zero.hpp b/zero.hpp
index 9c8b5a5..47c3b7d 100644
--- a/zero.hpp
+++ b/zero.hpp
@@ -563,7 +563,12 @@ double brent_zero
     if(tol < std::fabs(m) && 0.0 != fb)
         {
         // See if a bisection is forced.
-        if(std::fabs(e) < tol || std::fabs(fa) <= std::fabs(fb))
+        if(std::fabs(e) < tol)
+            {
+            technique = interpolate_bisection0;
+            d = e = m;
+            }
+        else if(std::fabs(fa) <= std::fabs(fb))
             {
             technique = interpolate_bisection0;
             d = e = m;
@@ -597,10 +602,9 @@ double brent_zero
                 }
             s = e;
             e = d;
-            if
-                (  2.0 * p < 3.0 * m * q - std::fabs(tol * q)
-                && p < std::fabs(0.5 * s * q)
-                )
+            bool const k0 = 2.0 * p < 3.0 * m * q - std::fabs(tol * q);
+            bool const k1 = p < std::fabs(0.5 * s * q);
+            if(k0 && k1)
                 {
                 d = p / q;
                 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]