lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 99aebcc 07/22: Treat decimal_root return valu


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 99aebcc 07/22: Treat decimal_root return value more flexibly
Date: Sun, 6 Jun 2021 21:38:00 -0400 (EDT)

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

    Treat decimal_root return value more flexibly
    
    At present, enum root_validity has only two values:
        {root_is_valid
        ,root_not_bracketed
        };
    but it is desirable to add a third, indicating a different mode of
    failure, as all successes are similar but failures can have different
    causes. Thus, that enumeration wants to be handled in a 'switch'.
    
    Where failure is considered impossible, assert success, instead of
    asserting the absence of some type of failure: then the assertion
    makes a 'switch' unnecessary.
---
 calendar_date.cpp |  2 +-
 financial.hpp     |  9 ++++++---
 ihs_avsolve.cpp   | 19 +++++++++++++------
 solve.cpp         | 13 ++++++++++---
 4 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/calendar_date.cpp b/calendar_date.cpp
index 05d5de3..85f51d9 100644
--- a/calendar_date.cpp
+++ b/calendar_date.cpp
@@ -751,7 +751,7 @@ class birthdate_limit
             ,0
             ,*this
             );
-        LMI_ASSERT(root_not_bracketed != z.second);
+        LMI_ASSERT(root_is_valid == z.second);
         int j = bourn_cast<int>(z.first);
         j = std::min(j, as_of_date_.julian_day_number());
         j = std::max(j, a_priori_minimum_);
diff --git a/financial.hpp b/financial.hpp
index edfef5f..5e9d60a 100644
--- a/financial.hpp
+++ b/financial.hpp
@@ -122,12 +122,15 @@ class irr_helper
             ,decimals_
             ,*this
             );
-        if(root_not_bracketed == z.second)
+        switch(z.second)
             {
+            case root_is_valid:
+                {return z.first;}
             // Return -100% if NPVs of a priori bounds have same sign.
-            z.first = -1.0L;
+            case root_not_bracketed:
+                {return -1.0L;}
             }
-        return z.first;
+        throw "Unreachable--silences a compiler diagnostic.";
         }
 
   private:
diff --git a/ihs_avsolve.cpp b/ihs_avsolve.cpp
index 05332b4..1ee549e 100644
--- a/ihs_avsolve.cpp
+++ b/ihs_avsolve.cpp
@@ -468,15 +468,22 @@ currency AccountValue::Solve
     // now, and actual values are freshly generated downstream.
     (this->*solve_set_fn)(solution_cents);
 
-    if(root_not_bracketed == solution.second)
+    switch(solution.second)
         {
-        LMI_ASSERT(0.0 == solution.first);
-        // Don't want this firing continually in census runs.
-        if(!SolvingForGuarPremium)
+        case root_is_valid:
+            {} // Do nothing.
+            break;
+        case root_not_bracketed:
             {
-            warning() << "Solution not found: using zero instead." << 
LMI_FLUSH;
-            // TODO ?? What can we do when no solution exists for guar prem?
+            LMI_ASSERT(0.0 == solution.first);
+            // Don't want this firing continually in census runs.
+            if(!SolvingForGuarPremium)
+                {
+                warning() << "Solution not found: using zero instead." << 
LMI_FLUSH;
+                // TODO ?? What can we do when no solution exists for guar 
prem?
+                }
             }
+            break;
         }
     return solution_cents;
 }
diff --git a/solve.cpp b/solve.cpp
index 7dfb3c9..ff665bb 100644
--- a/solve.cpp
+++ b/solve.cpp
@@ -347,10 +347,17 @@ currency AccountValue::Solve()
     // now, and actual values are freshly generated downstream.
     SolveFn(dblize(solution_cents));
 
-    if(root_not_bracketed == solution.second)
+    switch(solution.second)
         {
-        LMI_ASSERT(0.0 == solution.first);
-        warning() << "solution not found. Using zero instead." << LMI_FLUSH;
+        case root_is_valid:
+            {} // Do nothing.
+            break;
+        case root_not_bracketed:
+            {
+            LMI_ASSERT(0.0 == solution.first);
+            warning() << "solution not found. Using zero instead." << 
LMI_FLUSH;
+            }
+            break;
         }
     return solution_cents;
 }



reply via email to

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