lmi-commits
[Top][All Lists]
Advanced

[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};



reply via email to

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