lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] valyuta/002 39d842f 57/65: Simplify: catastrophic ca


From: Greg Chicares
Subject: [lmi-commits] [lmi] valyuta/002 39d842f 57/65: Simplify: catastrophic cancellation less worrisome with integer math
Date: Wed, 16 Sep 2020 16:55:22 -0400 (EDT)

branch: valyuta/002
commit 39d842f5d0aad807f6b1b89c469b206ae57ff136
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Simplify: catastrophic cancellation less worrisome with integer math
---
 ihs_avmly.cpp | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/ihs_avmly.cpp b/ihs_avmly.cpp
index c4e08d5..c00d3cd 100644
--- a/ihs_avmly.cpp
+++ b/ihs_avmly.cpp
@@ -2212,7 +2212,7 @@ void AccountValue::TxCreditInt()
 {
     ApplyDynamicMandE(AssetsPostBom);
 
-    double notional_sep_acct_charge = 0.0;
+    currency notional_sep_acct_charge {};
 
     // SOMEDAY !! This should be done in the interest-rate class.
     double gross_sep_acct_rate = i_upper_12_over_12_from_i<double>()
@@ -2227,21 +2227,9 @@ void AccountValue::TxCreditInt()
     if(currency() < AVSepAcct)
         {
         SepAcctIntCred = InterestCredited(AVSepAcct, YearsSepAcctIntRate);
-        double gross   = InterestCredited(AVSepAcct, gross_sep_acct_rate).d();
-        notional_sep_acct_charge = (gross - SepAcctIntCred).d();
-        // Guard against catastrophic cancellation. Testing the
-        // absolute values of the addends for material equality is not
-        // sufficient, because the interest increment has already been
-        // rounded.
-        double result = (AVSepAcct + SepAcctIntCred).d();
-        if(result < 0.0 && 0.0 <= AVSepAcct)
-            {
-            AVSepAcct = currency();
-            }
-        else
-            {
-            AVSepAcct = currency(result);
-            }
+        currency gross = InterestCredited(AVSepAcct, gross_sep_acct_rate);
+        notional_sep_acct_charge = gross - SepAcctIntCred;
+        AVSepAcct += SepAcctIntCred;
         }
     else
         {



reply via email to

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