[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 8861874 2/2: Refactor for clarity
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 8861874 2/2: Refactor for clarity |
Date: |
Mon, 13 Mar 2017 19:12:39 -0400 (EDT) |
branch: master
commit 8861874c0d5d7d9cfe359cdb04dc42911a9c5b8f
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Refactor for clarity
See:
http://lists.nongnu.org/archive/html/lmi/2017-03/msg00086.html
---
ledger.cpp | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/ledger.cpp b/ledger.cpp
index dd2dd82..9a4a6c2 100644
--- a/ledger.cpp
+++ b/ledger.cpp
@@ -148,8 +148,14 @@ void Ledger::SetRunBases(int length)
}
}
+/// Set inforce lives to zero after lapse.
+///
+/// Accomplish this by (1) shortening the inforce-lives vector to the
+/// chosen lapse year, increased by one because values are always
+/// illustrated to the end of that year--iff that is shorter--and then
+/// (2) restoring it to its original length.
+///
/// Pick the highest lapse year of any basis (i.e. any LedgerVariant).
-/// Set inforce lives to zero at the end of that year and thereafter.
/// This is extremely likely to mean the lapse year on the current
/// basis; but if it's the lapse year on some other basis, we don't
/// want to truncate values on that other basis, even if it means
@@ -157,19 +163,21 @@ void Ledger::SetRunBases(int length)
/// current values.
///
/// SOMEDAY !! Reconsider whether the values this function sets to
-/// zero should already have been zero.
+/// zero should somehow be set to zero upstream.
void Ledger::ZeroInforceAfterLapse()
{
ledger_map_t const& l_map_rep = ledger_map_->held();
- auto original_length = ledger_invariant_->InforceLives.size();
- using T = decltype(original_length);
- T lapse_year = T(0);
+
+ double lapse_year = 0.0;
for(auto const& i : l_map_rep)
{
- lapse_year = std::max(lapse_year, static_cast<T>(i.second.LapseYear));
+ lapse_year = std::max(lapse_year, i.second.LapseYear);
}
- T unlapsed_length = 1 + lapse_year;
+
+ auto original_length = ledger_invariant_->InforceLives.size();
+ using T = decltype(original_length);
+ T unlapsed_length = static_cast<T>(1 + lapse_year);
if(unlapsed_length < original_length)
{
ledger_invariant_->InforceLives.resize(unlapsed_length);