lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 2384269 1/6: Allow currency/currency --> doub


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 2384269 1/6: Allow currency/currency --> double
Date: Sun, 31 Jan 2021 17:27:27 -0500 (EST)

branch: master
commit 2384269186368fae5302d79a4734c15c5d1f2323
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Allow currency/currency --> double
    
    This is preferable to converting one operand explicitly to double
    (and the other implicitly) because dividing two values:
      c0.m_ / c1.m_
    is simpler than scaling them both first:
      (c0.m_ / cents_per_dollar) / (c1.m_ / cents_per_dollar)
    and (depending on compiler optimization) faster or as fast.
---
 currency.hpp  |  2 ++
 ihs_avmly.cpp | 18 +++++++-----------
 2 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/currency.hpp b/currency.hpp
index e3d45df..11009fa 100644
--- a/currency.hpp
+++ b/currency.hpp
@@ -125,6 +125,8 @@ inline double operator*(double lhs, currency rhs)
     {return lhs * rhs.d();}
 inline double operator/(currency lhs, double rhs)
     {return lhs.d() / rhs;}
+inline double operator/(currency lhs, currency rhs)
+    {return lhs.cents() / rhs.cents();}
 
 inline std::ostream& operator<<(std::ostream& os, currency z)
     {return os << z.d();}
diff --git a/ihs_avmly.cpp b/ihs_avmly.cpp
index 8cae629..b8713ae 100644
--- a/ihs_avmly.cpp
+++ b/ihs_avmly.cpp
@@ -291,8 +291,7 @@ void AccountValue::process_payment(currency payment)
     double er_proportion = 0.0;
     if(C0 != gross_non_1035_pmts)
         {
-        // CURRENCY !! more efficient: currency / currency --> double
-        er_proportion = ErGrossPmts[Month] / dblize(gross_non_1035_pmts);
+        er_proportion = ErGrossPmts[Month] / gross_non_1035_pmts;
         }
 
     // This is a net premium that's multiplied by a gross-premium
@@ -443,12 +442,11 @@ void AccountValue::DecrementAVProportionally(currency 
decrement)
 
     double general_account_proportion  = 0.0;
     double separate_account_proportion = 0.0;
-    // CURRENCY !! more efficient: currency / currency --> double
-    double general_account_nonnegative_assets  = dblize(std::max(C0, 
AVGenAcct));
-    double separate_account_nonnegative_assets = dblize(std::max(C0, 
AVSepAcct));
+    currency general_account_nonnegative_assets  = std::max(C0, AVGenAcct);
+    currency separate_account_nonnegative_assets = std::max(C0, AVSepAcct);
     if
-        (  0.0 == general_account_nonnegative_assets
-        && 0.0 == separate_account_nonnegative_assets
+        (  C0 == general_account_nonnegative_assets
+        && C0 == separate_account_nonnegative_assets
         )
         {
         general_account_proportion  = GenAcctPaymentAllocation;
@@ -743,8 +741,7 @@ void AccountValue::ChangeSpecAmtBy(currency delta)
                 break;
             case mce_adjust_both:
                 {
-                // CURRENCY !! more efficient: currency / currency --> double
-                term_proportion = TermSpecAmt / dblize(old_total_specamt);
+                term_proportion = TermSpecAmt / old_total_specamt;
                 }
                 break;
             case mce_adjust_base:
@@ -2548,8 +2545,7 @@ void AccountValue::TxTakeWD()
     // charge. This would become more complicated if we maintained
     // distinct surrender-charge layers.
 
-    // CURRENCY !! more efficient: currency / currency --> double
-    double surrchg_proportion = SurrChg_[Year] / dblize(csv);
+    double surrchg_proportion = SurrChg_[Year] / csv;
     currency non_free_wd = GrossWD;
     if(0.0 != FreeWDProportion[Year])
         {



reply via email to

[Prev in Thread] Current Thread [Next in Thread]