lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 9027fef 13/22: Refactor


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 9027fef 13/22: Refactor
Date: Sun, 6 Jun 2021 21:38:01 -0400 (EDT)

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

    Refactor
    
    Incrementing a local variable in three locations is better than passing
    it by reference to a separate function that increments it in one place.
    More crucially, this change ensures that 'n_iter' records the correct
    number of iterations even if a trace is not being printed: that's useful
    for measuring worst-case behavior and validating an implementation of
    Brent's method against his guarantees.
---
 zero.hpp | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/zero.hpp b/zero.hpp
index b358279..b99ebbb 100644
--- a/zero.hpp
+++ b/zero.hpp
@@ -60,7 +60,7 @@ namespace detail
 {
 inline void expatiate
     (std::ostream           & os_trace
-    ,int                    & n_iter
+    ,int                      n_iter
     ,interpolation_technique  technique
     ,double                   x
     ,double                   fx
@@ -69,7 +69,7 @@ inline void expatiate
     if(os_trace.good())
         {
         os_trace
-            << "iteration " << n_iter++
+            << "iteration " << n_iter
             << " "          << "IBLQb"[technique]
             << " iterand "  << x
             << " value "    << fx
@@ -279,14 +279,14 @@ root_type decimal_root
         }
 
     double fa = static_cast<double>(f(a));
-    detail::expatiate(os_trace, n_iter, technique, a, fa);
+    detail::expatiate(os_trace, n_iter++, technique, a, fa);
     if(0.0 == fa) // Note 0.
         {
         return std::make_pair(a, root_is_valid);
         }
 
     double fb = static_cast<double>(f(b));
-    detail::expatiate(os_trace, n_iter, technique, b, fb);
+    detail::expatiate(os_trace, n_iter++, technique, b, fb);
     if(0.0 == fb) // Note 0 [bis].
         {
         return std::make_pair(b, root_is_valid);
@@ -410,7 +410,7 @@ root_type decimal_root
         else
             {
             fb = static_cast<double>(f(b));
-            detail::expatiate(os_trace, n_iter, technique, b, fb);
+            detail::expatiate(os_trace, n_iter++, technique, b, fb);
             }
         }
 }



reply via email to

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