lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] valyuta/002 9dc1602 10/21: Remove double relops


From: Greg Chicares
Subject: [lmi-commits] [lmi] valyuta/002 9dc1602 10/21: Remove double relops
Date: Fri, 18 Sep 2020 21:53:48 -0400 (EDT)

branch: valyuta/002
commit 9dc1602db72d4ec09cd313d67828b285150c56a7
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Remove double relops
    
    Because doing this to a currency value:
      bourn_cast<double>(m_) / cents_per_dollar
    and comparing the result to 0.0 is less elegant than comparing m_ to 0.
    
    It may seem silly to assert that payments cannot exceed some "bignum",
    but that assertion actually has fired during development of class
    currency. A value of 2^double_mantissa_bits_including_implied_bit is
    about as good as any.
---
 accountvalue.cpp | 14 +++++++-------
 currency.hpp     | 17 -----------------
 gpt_specamt.cpp  |  2 +-
 ihs_acctval.cpp  |  3 ++-
 ihs_avmly.cpp    |  7 ++++---
 ihs_avsolve.cpp  |  2 +-
 ihs_basicval.cpp |  6 +++---
 solve.cpp        |  2 +-
 8 files changed, 19 insertions(+), 34 deletions(-)

diff --git a/accountvalue.cpp b/accountvalue.cpp
index 31ae361..9c6c86c 100644
--- a/accountvalue.cpp
+++ b/accountvalue.cpp
@@ -523,7 +523,7 @@ void AccountValue::TxOptionChange()
 
     // Nothing to do unless AV is positive.
     currency AV = AVUnloaned + AVRegLn + AVPrfLn;
-    if(AV <= 0.0)
+    if(AV <= currency())
         {
         return;
         }
@@ -727,7 +727,7 @@ void AccountValue::TxLoanRepay()
         }
 
     // Nothing to do if no loan repayment requested.
-    if(0.0 <= RequestedLoan)
+    if(currency() <= RequestedLoan)
         {
         return;
         }
@@ -832,14 +832,14 @@ void AccountValue::TxCreditInt()
 {
     // Accrue interest on unloaned and loaned account value separately,
     //   but do not charge interest on negative account value.
-    if(0.0 < AVUnloaned)
+    if(currency() < AVUnloaned)
         {
         // IHS !! Each interest increment is rounded separately in lmi.
         currency z = round_interest_credit().c(AVUnloaned * 
YearsGenAcctIntRate);
         AVUnloaned += z;
         }
     // Loaned account value cannot be negative.
-    LMI_ASSERT(0.0 <= AVRegLn + AVPrfLn);
+    LMI_ASSERT(currency() <= AVRegLn + AVPrfLn);
 }
 
 /// Accrue loan interest, and calculate interest credit on loaned AV.
@@ -847,7 +847,7 @@ void AccountValue::TxCreditInt()
 void AccountValue::TxLoanInt()
 {
     // Nothing to do if there's no loan outstanding.
-    if(0.0 == RegLnBal && 0.0 == PrfLnBal)
+    if(currency() == RegLnBal && currency() == PrfLnBal)
         {
         return;
         }
@@ -970,7 +970,7 @@ void AccountValue::TxTakeLoan()
         }
 
     // Nothing to do if no loan requested.
-    if(RequestedLoan <= 0.0)
+    if(RequestedLoan <= currency())
         {
         return;
         }
@@ -1024,7 +1024,7 @@ void AccountValue::TxTestLapse()
     // Otherwise if AV is negative or if overloaned, then lapse the policy.
     else if
         (
-            (AVUnloaned + AVRegLn + AVPrfLn < 0.0)
+            (AVUnloaned + AVRegLn + AVPrfLn < currency())
         ||  (MaxLoan < RegLnBal + PrfLnBal)
         )
         {
diff --git a/currency.hpp b/currency.hpp
index 2e3d967..80b5171 100644
--- a/currency.hpp
+++ b/currency.hpp
@@ -160,23 +160,6 @@ inline bool operator> (currency const& lhs, currency 
const& rhs){return  operato
 inline bool operator<=(currency const& lhs, currency const& rhs){return 
!operator> (lhs,rhs);}
 inline bool operator>=(currency const& lhs, currency const& rhs){return 
!operator< (lhs,rhs);}
 
-// double--avoid these:
-
-inline bool operator==(currency const& lhs, double   const& rhs){return 
lhs.d() == rhs;}
-inline bool operator< (currency const& lhs, double   const& rhs){return 
lhs.d() <  rhs;}
-inline bool operator==(double   const& lhs, currency const& rhs){return lhs == 
rhs.d();}
-inline bool operator< (double   const& lhs, currency const& rhs){return lhs <  
rhs.d();}
-
-inline bool operator!=(currency const& lhs, double   const& rhs){return 
!operator==(lhs,rhs);}
-inline bool operator> (currency const& lhs, double   const& rhs){return  
operator< (rhs,lhs);}
-inline bool operator<=(currency const& lhs, double   const& rhs){return 
!operator> (lhs,rhs);}
-inline bool operator>=(currency const& lhs, double   const& rhs){return 
!operator< (lhs,rhs);}
-
-inline bool operator!=(double   const& lhs, currency const& rhs){return 
!operator==(lhs,rhs);}
-inline bool operator> (double   const& lhs, currency const& rhs){return  
operator< (rhs,lhs);}
-inline bool operator<=(double   const& lhs, currency const& rhs){return 
!operator> (lhs,rhs);}
-inline bool operator>=(double   const& lhs, currency const& rhs){return 
!operator< (lhs,rhs);}
-
 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);}
diff --git a/gpt_specamt.cpp b/gpt_specamt.cpp
index e2b67fe..bcf0ba1 100644
--- a/gpt_specamt.cpp
+++ b/gpt_specamt.cpp
@@ -139,7 +139,7 @@ currency gpt_specamt::CalculateSpecAmt
     ,double             a_NetPmtFactorExc
     )
 {
-    LMI_ASSERT(0.0 != a_Premium);
+    LMI_ASSERT(currency() != a_Premium);
     LMI_ASSERT(0.0 != a_NetPmtFactorTgt);
     LMI_ASSERT(0.0 != a_NetPmtFactorExc);
 
diff --git a/ihs_acctval.cpp b/ihs_acctval.cpp
index 7316828..8029e6d 100644
--- a/ihs_acctval.cpp
+++ b/ihs_acctval.cpp
@@ -222,7 +222,8 @@ void AccountValue::SetGuarPrem()
         {
         GuarPremium = SolveGuarPremium();
         }
-    LMI_ASSERT(GuarPremium < 1.0e100);
+    // bignum: the largest integer convertible to and from double.
+    LMI_ASSERT(GuarPremium < currency(1LL << 53, true));
     ledger_->SetGuarPremium(GuarPremium.d());
 }
 
diff --git a/ihs_avmly.cpp b/ihs_avmly.cpp
index a56705b..461c842 100644
--- a/ihs_avmly.cpp
+++ b/ihs_avmly.cpp
@@ -1267,7 +1267,8 @@ void AccountValue::TxAscertainDesiredPayment()
             ;
 //  LMI_ASSERT(materially_equal(GrossPmts[Month], EeGrossPmts[Month] + 
ErGrossPmts[Month]));
     LMI_ASSERT(GrossPmts[Month] == EeGrossPmts[Month] + ErGrossPmts[Month]);
-    LMI_ASSERT(GrossPmts[Month] < 1.0e100);
+    // bignum: the largest integer convertible to and from double.
+    LMI_ASSERT(GrossPmts[Month] < currency(1LL << 53, true));
 
     if(0 == Year && 0 == Month)
         {
@@ -1586,8 +1587,8 @@ void AccountValue::TxLoanRepay()
     ActualLoan = currency() - std::min(currency() - RequestedLoan, RegLnBal + 
PrfLnBal); // unary operator-()
 
     process_distribution(ActualLoan);
-    LMI_ASSERT(0.0 == progressively_reduce(AVRegLn , AVPrfLn , currency() - 
ActualLoan)); // unary operator-()
-    LMI_ASSERT(0.0 == progressively_reduce(RegLnBal, PrfLnBal, currency() - 
ActualLoan)); // unary operator-()
+    LMI_ASSERT(currency() == progressively_reduce(AVRegLn , AVPrfLn , 
currency() - ActualLoan)); // unary operator-()
+    LMI_ASSERT(currency() == progressively_reduce(RegLnBal, PrfLnBal, 
currency() - ActualLoan)); // unary operator-()
 
 // This seems wrong. If we're changing something that's invariant among
 // bases, why do we change it for each basis?
diff --git a/ihs_avsolve.cpp b/ihs_avsolve.cpp
index 0c94b71..f95cd71 100644
--- a/ihs_avsolve.cpp
+++ b/ihs_avsolve.cpp
@@ -223,7 +223,7 @@ currency AccountValue::SolveTest(currency a_CandidateValue)
             - VariantValues().AcctVal    [SolveTargetDuration_ - 1]
             );
         }
-    if(worst_negative < 0.0)
+    if(worst_negative < currency())
         {
         value = std::min(value, worst_negative);
         }
diff --git a/ihs_basicval.cpp b/ihs_basicval.cpp
index 2b79304..71c9623 100644
--- a/ihs_basicval.cpp
+++ b/ihs_basicval.cpp
@@ -637,7 +637,7 @@ void BasicValues::SetPermanentInvariants()
     database().query_into(DB_TgtPremFixedAtIssue  , TgtPremFixedAtIssue);
     TgtPremMonthlyPolFee = 
currency(database().query<int>(DB_TgtPremMonthlyPolFee));
     // Assertion: see comments on GetModalPremTgtFromTable().
-    LMI_ASSERT(0.0 == TgtPremMonthlyPolFee || oe_modal_table == TgtPremType);
+    LMI_ASSERT(currency() == TgtPremMonthlyPolFee || oe_modal_table == 
TgtPremType);
     database().query_into(DB_CurrCoiTable0Limit   , CurrCoiTable0Limit);
     database().query_into(DB_CurrCoiTable1Limit   , CurrCoiTable1Limit);
 // NO!
@@ -1621,11 +1621,11 @@ std::vector<double> const& 
BasicValues::GetBandedCoiRates
 {
     if(UseUnusualCOIBanding && mce_gen_guar != rate_basis)
         {
-        if(CurrCoiTable0Limit <= a_specamt && a_specamt < CurrCoiTable1Limit)
+        if(CurrCoiTable0Limit <= a_specamt.d() && a_specamt.d() < 
CurrCoiTable1Limit)
             {
             return MortalityRates_->MonthlyCoiRatesBand1(rate_basis);
             }
-        else if(CurrCoiTable1Limit <= a_specamt)
+        else if(CurrCoiTable1Limit <= a_specamt.d())
             {
             return MortalityRates_->MonthlyCoiRatesBand2(rate_basis);
             }
diff --git a/solve.cpp b/solve.cpp
index 875024b..31ecefc 100644
--- a/solve.cpp
+++ b/solve.cpp
@@ -94,7 +94,7 @@ currency SolveTest()
         }
 
     currency z = currency(ConstThat->VariantValues().CSVNet[ThatSolveTgtYear - 
1]);
-    if(Negative < 0.0)
+    if(Negative < currency())
         z = std::min(z, Negative);
     // IHS !! If SolveTgtYr within no-lapse period...see lmi.
 



reply via email to

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