[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 1de83b9d 7/9: Refactor
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 1de83b9d 7/9: Refactor |
Date: |
Fri, 6 May 2022 19:37:36 -0400 (EDT) |
branch: master
commit 1de83b9d41a443bc142625b0f511fa9fb3469127
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Refactor
The number of places where ldbl_eps_plus_one_times() is called is lower,
but still positive.
---
gpt_server.cpp | 33 ++++++++++++++++-----------------
ihs_basicval.cpp | 9 ++++-----
mec_server.cpp | 33 ++++++++++++++++-----------------
ul_utilities.cpp | 12 ++++++++++++
ul_utilities.hpp | 9 +++++++++
5 files changed, 57 insertions(+), 39 deletions(-)
diff --git a/gpt_server.cpp b/gpt_server.cpp
index fffbca67..c19941af 100644
--- a/gpt_server.cpp
+++ b/gpt_server.cpp
@@ -36,7 +36,6 @@
#include "gpt_input.hpp"
#include "gpt_xml_document.hpp"
#include "i7702.hpp"
-#include "ieee754.hpp" // ldbl_eps_plus_one_times()
#include "ihs_irc7702a.hpp"
#include "ihs_server7702.hpp" // RunServer7702FromStruct()
#include "materially_equal.hpp" // material_difference()
@@ -53,6 +52,7 @@
#include "stratified_algorithms.hpp" // TieredGrossToNet()
#include "stratified_charges.hpp"
#include "timer.hpp"
+#include "ul_utilities.hpp" // max_modal_premium()
#include "value_cast.hpp"
#include <algorithm> // min()
@@ -137,8 +137,9 @@ gpt_state test_one_days_gpt_transactions
stratified_charges
stratified(AddDataDir(product_filenames.datum("TierFilename")));
// SOMEDAY !! Ideally these would be in the GUI (or read from product
files).
- round_to<double> const RoundNonMecPrem(2, r_downward);
+ round_to<double> const RoundNonMecPrem (2, r_downward);
round_to<double> const round_max_premium(2, r_downward);
+ round_to<double> const round_minutiae (2, r_to_nearest);
std::vector<double> TargetPremiumRates = target_premium_rates
(product_filenames
@@ -249,24 +250,22 @@ gpt_state test_one_days_gpt_transactions
// When 7Px is calculated from first principles, presumably
// the target premium should be the same as for oe_modal_table
// with a 7Px table and a DB_TgtPremMonthlyPolFee of zero.
- AnnualTargetPrem = round_max_premium
- (ldbl_eps_plus_one_times
- ( InforceTargetSpecifiedAmount
- * tabular_7Px[target_year]
- )
- );
+ AnnualTargetPrem = max_modal_premium
+ (tabular_7Px[target_year]
+ ,round_minutiae.c(InforceTargetSpecifiedAmount)
+ ,mce_annual
+ ,round_max_premium
+ ).d();
}
else if(oe_modal_table == target_premium_type)
{
- AnnualTargetPrem = round_max_premium
- (ldbl_eps_plus_one_times
- ( database.query<double>(DB_TgtPremMonthlyPolFee)
- +
- ( InforceTargetSpecifiedAmount
- * TargetPremiumRates[target_year]
- )
- )
- );
+ double const fee = database.query<double>(DB_TgtPremMonthlyPolFee);
+ AnnualTargetPrem = fee + max_modal_premium
+ (TargetPremiumRates[target_year]
+ ,round_minutiae.c(InforceTargetSpecifiedAmount)
+ ,mce_annual
+ ,round_max_premium
+ ).d();
}
else
{
diff --git a/ihs_basicval.cpp b/ihs_basicval.cpp
index 757828c7..66254b4d 100644
--- a/ihs_basicval.cpp
+++ b/ihs_basicval.cpp
@@ -37,7 +37,6 @@
#include "gpt7702.hpp"
#include "gpt_specamt.hpp"
#include "i7702.hpp"
-#include "ieee754.hpp" // ldbl_eps_plus_one_times()
#include "ihs_irc7702.hpp"
#include "ihs_irc7702a.hpp"
#include "input.hpp"
@@ -52,7 +51,7 @@
#include "rounding_rules.hpp"
#include "stl_extensions.hpp" // nonstd::power()
#include "stratified_charges.hpp"
-#include "ul_utilities.hpp" // list_bill_premium()
+#include "ul_utilities.hpp" // list_bill_premium(),
max_modal_premium()
#include <algorithm> // min()
#include <cfenv> // fesetround()
@@ -915,7 +914,7 @@ currency BasicValues::GetModalPremMaxNonMec
{
// TAXATION !! No table available if 7PP calculated from first principles.
double const rate = MortalityRates_->SevenPayRates()[0];
- return round_max_premium().c(ldbl_eps_plus_one_times(a_specamt * rate /
a_mode));
+ return max_modal_premium(rate, a_specamt, a_mode, round_max_premium());
}
/// Calculate premium using a minimum-premium ratio.
@@ -932,7 +931,7 @@ currency BasicValues::GetModalPremMinFromTable
) const
{
double const rate = MortalityRates_->MinimumPremiumRates()[0];
- return round_max_premium().c(ldbl_eps_plus_one_times(a_specamt * rate /
a_mode));
+ return max_modal_premium(rate, a_specamt, a_mode, round_max_premium());
}
/// Calculate premium using a target-premium ratio.
@@ -966,7 +965,7 @@ currency BasicValues::GetModalPremTgtFromTable
{
currency const modal_fee = TgtPremMonthlyPolFee * (12 / a_mode);
double const rate = MortalityRates_->TargetPremiumRates()[0];
- return modal_fee + round_max_premium().c(ldbl_eps_plus_one_times(a_specamt
* rate / a_mode));
+ return modal_fee + max_modal_premium(rate, a_specamt, a_mode,
round_max_premium());
}
/// Calculate premium using a tabular proxy for group insurance.
diff --git a/mec_server.cpp b/mec_server.cpp
index c59589f1..c4427816 100644
--- a/mec_server.cpp
+++ b/mec_server.cpp
@@ -34,7 +34,6 @@
#include "dbnames.hpp"
#include "et_vector.hpp"
#include "i7702.hpp"
-#include "ieee754.hpp" // ldbl_eps_plus_one_times()
#include "ihs_irc7702a.hpp"
#include "materially_equal.hpp" // material_difference()
#include "math_functions.hpp"
@@ -52,6 +51,7 @@
#include "stratified_algorithms.hpp" // TieredGrossToNet()
#include "stratified_charges.hpp"
#include "timer.hpp"
+#include "ul_utilities.hpp" // max_modal_premium()
#include "value_cast.hpp"
#include <algorithm> // min()
@@ -120,8 +120,9 @@ mec_state test_one_days_7702A_transactions
stratified_charges
stratified(AddDataDir(product_filenames.datum("TierFilename")));
// SOMEDAY !! Ideally these would be in the GUI (or read from product
files).
- round_to<double> const RoundNonMecPrem(2, r_downward);
+ round_to<double> const RoundNonMecPrem (2, r_downward);
round_to<double> const round_max_premium(2, r_downward);
+ round_to<double> const round_minutiae (2, r_to_nearest);
std::vector<double> TargetPremiumRates = target_premium_rates
(product_filenames
@@ -231,24 +232,22 @@ mec_state test_one_days_7702A_transactions
// When 7Px is calculated from first principles, presumably
// the target premium should be the same as for oe_modal_table
// with a 7Px table and a DB_TgtPremMonthlyPolFee of zero.
- AnnualTargetPrem = round_max_premium
- (ldbl_eps_plus_one_times
- ( InforceTargetSpecifiedAmount
- * tabular_7Px[target_year]
- )
- );
+ AnnualTargetPrem = max_modal_premium
+ (tabular_7Px[target_year]
+ ,round_minutiae.c(InforceTargetSpecifiedAmount)
+ ,mce_annual
+ ,round_max_premium
+ ).d();
}
else if(oe_modal_table == target_premium_type)
{
- AnnualTargetPrem = round_max_premium
- (ldbl_eps_plus_one_times
- ( database.query<double>(DB_TgtPremMonthlyPolFee)
- +
- ( InforceTargetSpecifiedAmount
- * TargetPremiumRates[target_year]
- )
- )
- );
+ double const fee = database.query<double>(DB_TgtPremMonthlyPolFee);
+ AnnualTargetPrem = fee + max_modal_premium
+ (TargetPremiumRates[target_year]
+ ,round_minutiae.c(InforceTargetSpecifiedAmount)
+ ,mce_annual
+ ,round_max_premium
+ ).d();
}
else
{
diff --git a/ul_utilities.cpp b/ul_utilities.cpp
index 17f2fa0b..2c521232 100644
--- a/ul_utilities.cpp
+++ b/ul_utilities.cpp
@@ -24,6 +24,8 @@
#include "ul_utilities.hpp"
#include "calendar_date.hpp"
+#include "ieee754.hpp" // ldbl_eps_plus_one_times()
+#include "round_to.hpp"
#include <algorithm> // generate(), min()
#include <cmath> // pow()
@@ -88,3 +90,13 @@ double list_bill_premium
std::generate(v.begin(), v.end(), [&i, v12] {return std::pow(v12, i++);});
return std::inner_product(p0.begin(), p0.end(), v.begin(), 0.0);
}
+
+currency max_modal_premium
+ (double rate
+ ,currency specamt
+ ,mcenum_mode mode
+ ,round_to<double> const& rounder
+ )
+{
+ return rounder.c(ldbl_eps_plus_one_times(specamt * rate / mode));
+}
diff --git a/ul_utilities.hpp b/ul_utilities.hpp
index 25760b71..6c748535 100644
--- a/ul_utilities.hpp
+++ b/ul_utilities.hpp
@@ -24,9 +24,11 @@
#include "config.hpp"
+#include "currency.hpp"
#include "mc_enum_type_enums.hpp" // mcenum_mode
class calendar_date;
+template<typename> class round_to;
double list_bill_premium
(double prem_ante
@@ -37,4 +39,11 @@ double list_bill_premium
,double v12
);
+currency max_modal_premium
+ (double rate
+ ,currency specamt
+ ,mcenum_mode mode
+ ,round_to<double> const& rounder
+ );
+
#endif // ul_utilities_hpp
- [lmi-commits] [lmi] master updated (13799952 -> 9e5a09bf), Greg Chicares, 2022/05/06
- [lmi-commits] [lmi] master be841c05 3/9: Refactor for clarity, Greg Chicares, 2022/05/06
- [lmi-commits] [lmi] master a24d665c 4/9: Include only appropriate headers, and say why they're included, Greg Chicares, 2022/05/06
- [lmi-commits] [lmi] master 46534540 2/9: Refactor for uniformity, Greg Chicares, 2022/05/06
- [lmi-commits] [lmi] master 9e5a09bf 9/9: Record speed measurements, Greg Chicares, 2022/05/06
- [lmi-commits] [lmi] master 78657d01 6/9: Improve physical structure, Greg Chicares, 2022/05/06
- [lmi-commits] [lmi] master 4b8bf312 1/9: Expunge workarounds for nonexistent problems, Greg Chicares, 2022/05/06
- [lmi-commits] [lmi] master 67af2e9b 5/9: Improve a debatable workaround, Greg Chicares, 2022/05/06
- [lmi-commits] [lmi] master 205497ae 8/9: Reimplement max_modal_premium(), Greg Chicares, 2022/05/06
- [lmi-commits] [lmi] master 1de83b9d 7/9: Refactor,
Greg Chicares <=