[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;
}
- [lmi-commits] [lmi] master updated (debc275 -> a277ed6), Greg Chicares, 2021/07/15
- [lmi-commits] [lmi] master 0090739 03/11: Rename an enumeration, Greg Chicares, 2021/07/15
- [lmi-commits] [lmi] master fb3d854 02/11: Refactor instrumented reference implementation,
Greg Chicares <=
- [lmi-commits] [lmi] master 0d9b36b 05/11: Make enumerators print a useful value directly, Greg Chicares, 2021/07/15
- [lmi-commits] [lmi] master 27cdaa7 01/11: Refactor, Greg Chicares, 2021/07/15
- [lmi-commits] [lmi] master ff2f404 04/11: Use a more informative unit-test macro, Greg Chicares, 2021/07/15
- [lmi-commits] [lmi] master 0b44a84 07/11: Reenumerate root-finding activities, Greg Chicares, 2021/07/15
- [lmi-commits] [lmi] master dce3edc 08/11: Show variable shifts in optional trace, Greg Chicares, 2021/07/15
- [lmi-commits] [lmi] master 5a3bd1d 10/11: Regularize whitespace, Greg Chicares, 2021/07/15
- [lmi-commits] [lmi] master 70f1126 09/11: Find a root that coincides with an input bound, Greg Chicares, 2021/07/15
- [lmi-commits] [lmi] master b24bcce 06/11: Improve indentation, Greg Chicares, 2021/07/15
- [lmi-commits] [lmi] master a277ed6 11/11: Uniformly test two functions in parallel, Greg Chicares, 2021/07/15