[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master bbf2517 10/23: Use signum() where a signum fu
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master bbf2517 10/23: Use signum() where a signum function is wanted |
Date: |
Tue, 27 Jul 2021 21:59:52 -0400 (EDT) |
branch: master
commit bbf251793cf72761ad04904d5a7f51ccdb0a36a8
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Use signum() where a signum function is wanted
These conditions are not the same:
- (0.0 < fa) == (0.0 < fb)) // dubious
+ signum(fa) == signum(fb)) // clear
for {fa=-1, fb=0} or {fa=0,fb=-1}, but those cases don't matter for
lmi_root(), which returns immediately when either fa or fb is zero.
No such condition is imposed in the original ALGOL, which only comments:
"The procedure assumes that f(a) and f(b) have different signs"
or in the reference implementations. The replaced code was an artifact
of translation and does not reflect on Brent's work; the replacement
follows a literal reading of his comment.
---
zero.hpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/zero.hpp b/zero.hpp
index 1efb47f..bbe3e9c 100644
--- a/zero.hpp
+++ b/zero.hpp
@@ -469,7 +469,8 @@ root_type lmi_root
}
// f(a) and f(b) must have different signs; neither may be a NaN.
- if(std::isnan(fa) || std::isnan(fb) || (0.0 < fa) == (0.0 < fb))
+ // Cases where either is zero were already handled above.
+ if(std::isnan(fa) || std::isnan(fb) || signum(fa) == signum(fb))
{
recapitulate();
return {0.0, root_not_bracketed, n_iter, n_eval};
- [lmi-commits] [lmi] master cecc91f 21/23: Avoid a unit-test false negative, (continued)
- [lmi-commits] [lmi] master cecc91f 21/23: Avoid a unit-test false negative, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master 4b26bf8 01/23: Add a parenthetical comment to a unit test, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master 86ae65d 18/23: Revert "Demonstration, for immediate reversion", Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master e59df26 14/23: Refactor, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master 8f2f355 19/23: Augment unit tests; record some observations, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master a259cb6 05/23: Calculate maximum possible number of iterations, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master d0a65c2 04/23: Demonstrate that Brent's δ can be almost arbitrarily small, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master 548f9ab 06/23: Document known shortcomings of a unit-testing helper, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master 19a4a3a 03/23: For now at least, trace solves in regression test, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master 04c58eb 09/23: Count iterations and evaluations separately, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master bbf2517 10/23: Use signum() where a signum function is wanted,
Greg Chicares <=
- [lmi-commits] [lmi] master e08be34 12/23: Improve a unit test, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master 02dde17 13/23: Avoid catastrophic cancellation, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master d2dcbf8 15/23: Reduce complexity, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master e93ca8f 17/23: Demonstration, for immediate reversion, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master 4500338 22/23: Simplify, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master 2ad4944 20/23: Record some more observations--no files changed, Greg Chicares, 2021/07/27
- [lmi-commits] [lmi] master 028b454 23/23: Find any root with only 64 function evaluations, Greg Chicares, 2021/07/27