[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] valyuta/002 215244a 13/21: Avoid implicit mixed-mode
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] valyuta/002 215244a 13/21: Avoid implicit mixed-mode calculations more avidly |
Date: |
Fri, 18 Sep 2020 21:53:48 -0400 (EDT) |
branch: valyuta/002
commit 215244ac5c85021655cabba66e3bb1967671a20e
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Avoid implicit mixed-mode calculations more avidly
Explicit is better than implicit. And it makes mistakes like this easier
to identify and remove [YearsTotalGptForceout is of currency type]:
- ,currency() - YearsTotalGptForceout.d()
+ ,currency() - YearsTotalGptForceout
---
accountvalue.cpp | 2 +-
currency.hpp | 7 +------
ihs_acctval.cpp | 2 +-
ihs_avmly.cpp | 35 ++++++++++++++++++-----------------
ihs_basicval.cpp | 2 +-
5 files changed, 22 insertions(+), 26 deletions(-)
diff --git a/accountvalue.cpp b/accountvalue.cpp
index 9c6c86c..5723536 100644
--- a/accountvalue.cpp
+++ b/accountvalue.cpp
@@ -790,7 +790,7 @@ void AccountValue::TxSetCoiCharge()
TxSetDeathBft();
// Negative AV doesn't increase NAAR.
- NAAR = (deathbft * mlyguarv - (AVUnloaned + AVRegLn + AVPrfLn)).d();
+ NAAR = deathbft * mlyguarv - (AVUnloaned + AVRegLn + AVPrfLn).d();
NAAR = round_naar()(NAAR);
CoiCharge = round_coi_charge().c(NAAR * YearsCoiRate0);
diff --git a/currency.hpp b/currency.hpp
index 75836cc..55ba053 100644
--- a/currency.hpp
+++ b/currency.hpp
@@ -150,12 +150,7 @@ inline bool operator>=(currency const& lhs, currency
const& rhs){return !operato
inline currency operator+(currency lhs, currency rhs) {return lhs += rhs;}
inline currency operator-(currency lhs, currency rhs) {return lhs -= rhs;}
-inline currency operator+(currency lhs, double rhs) {return lhs +=
currency(rhs);}
-inline currency operator+(double lhs, currency rhs) {return currency(lhs) +=
rhs;}
-inline currency operator-(currency lhs, double rhs) {return lhs -=
currency(rhs);}
-inline currency operator-(double lhs, currency rhs) {return currency(lhs) -=
rhs;}
-//inline currency operator*(currency lhs, double rhs) {return lhs *=
currency(rhs);}
-////inline double operator*(currency lhs, double rhs) {return lhs *=
currency(rhs);}
+
// Don't actually want any member operator*() for double:
inline double operator*(currency lhs, double rhs) {return lhs.d() * rhs;}
inline double operator*(double lhs, currency rhs) {return lhs * rhs.d();}
diff --git a/ihs_acctval.cpp b/ihs_acctval.cpp
index 8029e6d..2534c73 100644
--- a/ihs_acctval.cpp
+++ b/ihs_acctval.cpp
@@ -1317,7 +1317,7 @@ void AccountValue::FinalizeYear()
VariantValues().NetPmt[Year] = std::accumulate
(NetPmts.begin()
,NetPmts.end()
- ,currency() - YearsTotalGptForceout.d() // unary operator-()
+ ,currency() - YearsTotalGptForceout // unary operator-()
).d();
if(mce_run_gen_curr_sep_full == RunBasis_)
diff --git a/ihs_avmly.cpp b/ihs_avmly.cpp
index 461c842..2e606d4 100644
--- a/ihs_avmly.cpp
+++ b/ihs_avmly.cpp
@@ -1744,8 +1744,8 @@ void AccountValue::TxSetDeathBft()
, (
YearsCorridorFactor
* ( Dcv
- - std::min(currency(), SurrChg())
- + GetRefundableSalesLoad()
+ - std::min(currency(), SurrChg()).d()
+ + GetRefundableSalesLoad().d()
// + std::max(0.0, ExpRatReserve) // This would be added if
it existed.
)
)
@@ -1875,11 +1875,11 @@ void AccountValue::TxSetCoiCharge()
)
);
double retention_rate = round_coi_rate()(coi_rate * CoiRetentionRate);
- retention_charge = round_coi_charge()(NAAR * retention_rate);
+ retention_charge = NAAR * retention_rate;
}
CoiCharge = round_coi_charge().c(NAAR * ActualCoiRate);
- NetCoiCharge = CoiCharge - retention_charge;
+ NetCoiCharge = CoiCharge - round_coi_charge().c(retention_charge);
YearsTotalCoiCharge += CoiCharge;
// DCV need not be rounded.
@@ -1963,11 +1963,11 @@ void AccountValue::TxSetRiderDed()
YearsWpRate
* (
DcvCoiCharge
- + MonthsPolicyFees
- + SpecAmtLoad
- + AdbCharge
- + SpouseRiderCharge
- + ChildRiderCharge
+ + MonthsPolicyFees.d()
+ + SpecAmtLoad.d()
+ + AdbCharge.d()
+ + SpouseRiderCharge.d()
+ + ChildRiderCharge.d()
+ DcvTermCharge
);
}
@@ -2379,19 +2379,20 @@ currency AccountValue::anticipated_deduction
void AccountValue::SetMaxWD()
{
- MaxWD =
+ double max_wd =
AVGenAcct * MaxWdGenAcctValMult
+ AVSepAcct * MaxWdSepAcctValMult
- + (AVRegLn + AVPrfLn)
- - (RegLnBal + PrfLnBal)
- - anticipated_deduction(MaxWDDed_)
- - std::max(currency(), SurrChg())
+ + (AVRegLn + AVPrfLn).d()
+ - (RegLnBal + PrfLnBal).d()
+ - anticipated_deduction(MaxWDDed_).d()
+ - std::max(0.0, SurrChg().d())
;
- if(MaxWD < MinWD)
+ if(max_wd < MinWD.d())
{
- MaxWD = currency();
+ max_wd = 0.0;
}
- MaxWD = std::max(currency(), MaxWD);
+ max_wd = std::max(0.0, max_wd);
+ MaxWD = round_withdrawal().c(max_wd);
}
/// Take a withdrawal.
diff --git a/ihs_basicval.cpp b/ihs_basicval.cpp
index 71c9623..8bb7f42 100644
--- a/ihs_basicval.cpp
+++ b/ihs_basicval.cpp
@@ -1494,7 +1494,7 @@ currency BasicValues::GetModalSpecAmtTgt(currency
annualized_pmt) const
case oe_modal_table:
return round_min_specamt().c
(
- (annualized_pmt - TgtPremMonthlyPolFee * 12.0)
+ (annualized_pmt - TgtPremMonthlyPolFee * 12)
/ MortalityRates_->TargetPremiumRates()[0]
);
}
- [lmi-commits] [lmi] valyuta/002 da89fe3 04/21: Revert "Make it faster", (continued)
- [lmi-commits] [lmi] valyuta/002 da89fe3 04/21: Revert "Make it faster", Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 4b313b0 07/21: Discard some commented-out code, Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 e474aa4 09/21: Remove int relops, Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 d1c1af3 01/21: Revert "Trivially avoid spurious regression errors", Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 693dac0 02/21: Revert "Make it even faster", Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 24abb3f 03/21: Revert "Make it more faster", Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 95f34c4 06/21: Get rid of unneeded scalar doubleize(), Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 9dc1602 10/21: Remove double relops, Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 b803441 12/21: Improve documentation, Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 06046b6 05/21: Revert "Make it float", Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 215244a 13/21: Avoid implicit mixed-mode calculations more avidly,
Greg Chicares <=
- [lmi-commits] [lmi] valyuta/002 63419d4 14/21: Improve documentation, Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 d8e2470 15/21: Refactor for clarity, Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 b07371e 17/21: Avoid implicit conversions yet more avidly, Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 331e748 18/21: Unbreak a unit test, Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 02d03f2 08/21: Discard more commented-out code, Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 3266cfe 11/21: Establish a separate test/ directory for this branch, Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 0e9baa5 16/21: Use currency where currency is wanted, Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 97e9057 21/21: Fix a unit test, Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 8785c00 19/21: Implement negation operator, Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 97eb31d 20/21: Use negation operator, Greg Chicares, 2020/09/18