[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
- [lmi-commits] [lmi] master updated (6620be4 -> ef8f7b4), Greg Chicares, 2021/01/29
- [lmi-commits] [lmi] master 183844a 2/6: Round only when necessary, Greg Chicares, 2021/01/29
- [lmi-commits] [lmi] master f0cdf93 3/6: Round halfway cases consistently to even, Greg Chicares, 2021/01/29
- [lmi-commits] [lmi] master 780be3c 1/6: Mark uncached product-file instances, Greg Chicares, 2021/01/29
- [lmi-commits] [lmi] master 417af8e 4/6: Simplify,
Greg Chicares <=
- [lmi-commits] [lmi] master ef8f7b4 6/6: Record speed measurements, Greg Chicares, 2021/01/29
- [lmi-commits] [lmi] master 484ed01 5/6: Refine rounding of specamt strategies, Greg Chicares, 2021/01/29