lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 17b7458 4/8: Eliminate the only use of a side


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 17b7458 4/8: Eliminate the only use of a side-effect guarantee
Date: Tue, 25 May 2021 20:11:00 -0400 (EDT)

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

    Eliminate the only use of a side-effect guarantee
    
    In preparation for eliminating the 'guarantee_side_effects' misfeature
    of decimal_root(), eliminated its only actual use.
    
    Improved the return value when no root is bracketed.
---
 gpt_specamt.cpp | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/gpt_specamt.cpp b/gpt_specamt.cpp
index 02b0c21..ad911f4 100644
--- a/gpt_specamt.cpp
+++ b/gpt_specamt.cpp
@@ -73,7 +73,6 @@ class FindSpecAmt
     double      const  Premium;
     double      const  NetPmtFactorTgt;
     double      const  NetPmtFactorExc;
-    currency           SpecAmt;
 
   public:
     FindSpecAmt
@@ -92,13 +91,12 @@ class FindSpecAmt
         ,Premium         {a_Premium}
         ,NetPmtFactorTgt {a_NetPmtFactorTgt}
         ,NetPmtFactorExc {a_NetPmtFactorExc}
-        ,SpecAmt         {C0}
         {
         }
     // CURRENCY !! decimal_root() expects this; but see 'ihs_avsolve.cpp'.
-    double operator()(double a_Trial)
+    double operator()(double a_Trial) const
         {
-        SpecAmt = Values_.round_min_specamt().c(a_Trial);
+        currency const SpecAmt = Values_.round_min_specamt().c(a_Trial);
         return
                 Irc7702_.CalculatePremium
                     (EIOBasis_
@@ -113,10 +111,6 @@ class FindSpecAmt
             -   Premium
             ;
         }
-    currency Get()
-        {
-        return SpecAmt;
-        }
 };
 
 /// CalculatePremium() implements an analytic solution, while 
CalculateSpecAmt()
@@ -146,7 +140,7 @@ currency gpt_specamt::CalculateSpecAmt
 
     Irc7702 const& z(safely_dereference_as<Irc7702>(a_Values.Irc7702_.get()));
 
-    FindSpecAmt fsa
+    FindSpecAmt const fsa
         (a_Values
         ,z
         ,a_EIOBasis
@@ -165,14 +159,23 @@ currency gpt_specamt::CalculateSpecAmt
     // might violate the "total" minimum for a product with a term
     // rider; that's okay when the user requests a solve, but not for
     // the strategy implemented here, which should work more robustly.
-    decimal_root
+    root_type const solution = decimal_root
         (dblize(a_Values.min_issue_spec_amt())
         ,999999999.99
         ,bias_higher
         ,z.round_min_specamt.decimals()
         ,fsa
-        ,true
         );
 
-    return fsa.Get();
+    // Because it is implausible that the upper bound is too low,
+    // failure in practice implies that the solution would be lower
+    // than the product minimum--in which case, return that minimum.
+    switch(solution.second)
+        {
+        case root_is_valid:
+            {return a_Values.round_specamt().c(solution.first);}
+        case root_not_bracketed:
+            {return a_Values.min_issue_spec_amt();}
+        }
+    throw "Unreachable--silences a compiler diagnostic.";
 }



reply via email to

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