lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 417af8e 4/6: Simplify


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 417af8e 4/6: Simplify
Date: Fri, 29 Jan 2021 15:44:16 -0500 (EST)

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

    Simplify
    
    Catastrophic cancellation cannot occur with plausible currency amounts,
    and that's an important benefit of switching to the currency class.
    
    The logic was this:
        if(C0 < AVSepAcct)
            currency result = AVSepAcct + SepAcctIntCred;
            if(result < C0 && C0 <= AVSepAcct)
                AVSepAcct = C0;
            else
                AVSepAcct = result;
    If AVSepAcct is positive, it's nonnegative, so that simplifies to:
        if(C0 < AVSepAcct)
            currency result = AVSepAcct + SepAcctIntCred;
            if(result < C0)
                AVSepAcct = C0;
            else
                AVSepAcct = result;
    which now clearly means:
            AVSepAcct = AVSepAcct + SepAcctIntCred;
            if(result < C0)
                AVSepAcct = C0;
    and thus:
            AVSepAcct = std::max(C0, AVSepAcct + SepAcctIntCred);
---
 ihs_avmly.cpp | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/ihs_avmly.cpp b/ihs_avmly.cpp
index 540f348..8cae629 100644
--- a/ihs_avmly.cpp
+++ b/ihs_avmly.cpp
@@ -2195,16 +2195,9 @@ void AccountValue::TxCreditInt()
         currency gross = InterestCredited(AVSepAcct, YearsSepAcctGrossRate);
         notional_sep_acct_charge = gross - SepAcctIntCred;
 #if defined USE_CURRENCY_CLASS
-        currency result = AVSepAcct + SepAcctIntCred;
-        // CURRENCY !! rethink this weird logic
-        if(result < C0 && C0 <= AVSepAcct)
-            {
-            AVSepAcct = C0;
-            }
-        else
-            {
-            AVSepAcct = result;
-            }
+        // CURRENCY !! Further simplify the local logic after
+        // expunging macro USE_CURRENCY_CLASS.
+        AVSepAcct = std::max(C0, AVSepAcct + SepAcctIntCred);
 #else  // !defined USE_CURRENCY_CLASS
         // Guard against catastrophic cancellation. Testing the
         // absolute values of the addends for material equality is not



reply via email to

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