[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);
}
}
}
- [lmi-commits] [lmi] master b14e318 18/22: Adjust tolerance for a particular unit-test function, (continued)
- [lmi-commits] [lmi] master b14e318 18/22: Adjust tolerance for a particular unit-test function, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 1c448d8 20/22: Augment decimal_root()'s return type, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 53c3513 21/22: Reorder unit tests, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 5cf534c 04/22: Constify, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 3865416 10/22: Rearrange certain unit tests, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 1f8316c 16/22: Test actual return value, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 3d4adb3 17/22: Clarify, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 200e756 03/22: Clarify documentation, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 1b0ed06 12/22: Change argument order, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 86661b6 22/22: Validate number of iterations, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 9027fef 13/22: Refactor,
Greg Chicares <=
- [lmi-commits] [lmi] master c1a020a 14/22: Include appropriate headers, and say why they're included, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 4d9ed2d 19/22: Abstract the Brent error limit, Greg Chicares, 2021/06/06
- [lmi-commits] [lmi] master 776f09c 15/22: Return a struct rather than a std::pair, Greg Chicares, 2021/06/06