[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 060aecf 6/9: Rearrange for comprehensibility
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 060aecf 6/9: Rearrange for comprehensibility |
Date: |
Sat, 17 Feb 2018 11:13:05 -0500 (EST) |
branch: master
commit 060aecfda311e9ee3607ee8fb63383595fae94d0
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Rearrange for comprehensibility
http://wiki.c2.com/?SimplyUnderstoodCode
"Arrange the important parts of the code so it fits on one page."
---
ledger_invariant.cpp | 48 +++++++++++++++++++++++++-----------------------
1 file changed, 25 insertions(+), 23 deletions(-)
diff --git a/ledger_invariant.cpp b/ledger_invariant.cpp
index f43db91..dfb4231 100644
--- a/ledger_invariant.cpp
+++ b/ledger_invariant.cpp
@@ -1262,6 +1262,18 @@ LedgerInvariant& LedgerInvariant::PlusEq(LedgerInvariant
const& a_Addend)
/// Perform costly IRR calculations on demand only.
///
+/// IRRs on zero-sepacct-interest bases cannot be calculated for
+/// ledger types that do not generate values on those bases (any
+/// attempt to access such values as irr() arguments would throw).
+/// Here, such impossible calculations are avoided by explicit
+/// logic (they might be avoided implicitly if IRRs were set in
+/// class LedgerVariant instead). In that logic, it is plausibly
+/// assumed that
+/// mce_run_gen_curr_sep_zero
+/// mce_run_gen_guar_sep_zero
+/// are always used in pairs, so that either may be tested as a
+/// proxy for the other.
+///
/// TODO ?? It is extraordinary that this "invariant" class uses and
/// even sets some data that vary by basis and therefore seem to
/// belong in the complementary "variant" class instead.
@@ -1270,6 +1282,15 @@ void LedgerInvariant::CalculateIrrs(Ledger const&
LedgerValues)
{
irr_initialized_ = false;
+ bool const zero_sepacct_interest_bases_undefined =
+ (0 == std::count
+ (LedgerValues.GetRunBases().begin()
+ ,LedgerValues.GetRunBases().end()
+ ,mce_run_gen_curr_sep_zero
+ )
+ );
+ // PDF !! Initialize the '0'-suffixed IRRs regardless.
+
// Terse aliases for invariants.
int const m = LedgerValues.GetMaxLength();
int const n = irr_precision_;
@@ -1282,27 +1303,8 @@ void LedgerInvariant::CalculateIrrs(Ledger const&
LedgerValues)
irr(Outlay, Curr_.CSVNet, IrrCsvCurrInput, Curr_.LapseYear, m, n);
irr(Outlay, Curr_.EOYDeathBft, IrrDbCurrInput, Curr_.LapseYear, m, n);
- // IRRs on zero-sepacct-interest bases cannot be calculated for
- // ledger types that do not generate values on those bases (any
- // attempt to access such values as irr() arguments would throw).
- // Here, such impossible calculations are avoided by explicit
- // logic (they might be avoided implicitly if IRRs were set in
- // class LedgerVariant instead). In that logic, it is plausibly
- // assumed that
- // mce_run_gen_curr_sep_zero
- // mce_run_gen_guar_sep_zero
- // are always used in pairs, so that either may be tested as a
- // proxy for the other.
- bool const zero_sepacct_interest_bases_undefined =
- (0 == std::count
- (LedgerValues.GetRunBases().begin()
- ,LedgerValues.GetRunBases().end()
- ,mce_run_gen_curr_sep_zero
- )
- );
if(zero_sepacct_interest_bases_undefined)
{
- // PDF !! Initialize the '0'-suffixed IRRs here.
irr_initialized_ = true;
return;
}
@@ -1310,10 +1312,10 @@ void LedgerInvariant::CalculateIrrs(Ledger const&
LedgerValues)
LedgerVariant const& Curr0 = LedgerValues.GetCurrZero();
LedgerVariant const& Guar0 = LedgerValues.GetGuarZero();
- irr(Outlay, Guar0.CSVNet, IrrCsvGuar0, Guar0.LapseYear, m, n);
- irr(Outlay, Guar0.EOYDeathBft, IrrDbGuar0, Guar0.LapseYear, m, n);
- irr(Outlay, Curr0.CSVNet, IrrCsvCurr0, Curr0.LapseYear, m, n);
- irr(Outlay, Curr0.EOYDeathBft, IrrDbCurr0, Curr0.LapseYear, m, n);
+ irr(Outlay, Guar0.CSVNet, IrrCsvGuar0, Guar0.LapseYear, m, n);
+ irr(Outlay, Guar0.EOYDeathBft, IrrDbGuar0, Guar0.LapseYear, m, n);
+ irr(Outlay, Curr0.CSVNet, IrrCsvCurr0, Curr0.LapseYear, m, n);
+ irr(Outlay, Curr0.EOYDeathBft, IrrDbCurr0, Curr0.LapseYear, m, n);
irr_initialized_ = true;
}
- [lmi-commits] [lmi] master updated (422cd51 -> 5e372c6), Greg Chicares, 2018/02/17
- [lmi-commits] [lmi] master 36d5a6b 1/9: Remove unnecessary static_cast, Greg Chicares, 2018/02/17
- [lmi-commits] [lmi] master 513e891 4/9: Improve documentation, Greg Chicares, 2018/02/17
- [lmi-commits] [lmi] master ca32be5 3/9: Find a root of the zero polynomial, Greg Chicares, 2018/02/17
- [lmi-commits] [lmi] master 3781a93 5/9: Refactor for rearrangeability, Greg Chicares, 2018/02/17
- [lmi-commits] [lmi] master 0ae54b4 2/9: Refactor for terseness, Greg Chicares, 2018/02/17
- [lmi-commits] [lmi] master b710396 8/9: Don't assume--assert, Greg Chicares, 2018/02/17
- [lmi-commits] [lmi] master 3f1dd88 7/9: Consolidate and improve documentation, Greg Chicares, 2018/02/17
- [lmi-commits] [lmi] master 060aecf 6/9: Rearrange for comprehensibility,
Greg Chicares <=
- [lmi-commits] [lmi] master 5e372c6 9/9: Perform ledger IRR initialization in one place only, Greg Chicares, 2018/02/17