lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master ad14033 6/8: Improve and test translation fro


From: Greg Chicares
Subject: [lmi-commits] [lmi] master ad14033 6/8: Improve and test translation from ALGOL 60
Date: Wed, 2 Jun 2021 15:37:07 -0400 (EDT)

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

    Improve and test translation from ALGOL 60
    
    gcc warned that some variables might have been used uninitialized;
    fixed by initializing them as in decimal_root().
---
 zero.hpp      | 4 +++-
 zero_test.cpp | 3 +++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/zero.hpp b/zero.hpp
index 46f31e3..8b69e4c 100644
--- a/zero.hpp
+++ b/zero.hpp
@@ -427,10 +427,12 @@ double brent_zero
     double fa = f(a);
     double fb = f(b);
     double fc = fb;
+    double c = b;
+    double d = b - a;
+    double e = d;
 
     for(;;)
         {
-        double c, d, e;
         if((0.0 < fb) == (0.0 < fc))
             {
             c = a;
diff --git a/zero_test.cpp b/zero_test.cpp
index 76eb79e..23f1797 100644
--- a/zero_test.cpp
+++ b/zero_test.cpp
@@ -193,6 +193,9 @@ int test_main(int, char*[])
     LMI_TEST(root_is_valid == r.second);
     LMI_TEST(std::fabs(r.first) <= epsilon);
 
+    double d = brent_zero(-1.0, 4.0, 1.0e-20, e_19);
+    LMI_TEST(std::fabs(d) <= epsilon);
+
     test_zero(-1.0, 4.0, -100, e_19, std::exp(1.0));
     test_zero(-1.0, 4.0,    0, e_19, std::exp(1.0));
     test_zero(-1.0, 4.0,  100, e_19, std::exp(1.0));



reply via email to

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