lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master 447a92d 1/2: Refactor to make it easier to us


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 447a92d 1/2: Refactor to make it easier to use nextafter()
Date: Wed, 6 Jun 2018 10:26:30 -0400 (EDT)

branch: master
commit 447a92d139be7a8419d6bc8e9d37d8a737cf91a1
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Refactor to make it easier to use nextafter()
    
    Routed certain 1+epsilon multiplications through a common subroutine.
    This doesn't address the issue described here:
      https://github.com/vadz/lmi/issues/22
    but does facilitate addressing it later. This commit does let the
    '-Wno-float-conversion' exceptions for these files be removed.
---
 gpt_server.cpp   | 25 ++++++++++++-------------
 ieee754.hpp      |  6 +++---
 ihs_basicval.cpp | 22 +++++++++++-----------
 mec_server.cpp   | 25 ++++++++++++-------------
 4 files changed, 38 insertions(+), 40 deletions(-)

diff --git a/gpt_server.cpp b/gpt_server.cpp
index 5145fd3..1f050df 100644
--- a/gpt_server.cpp
+++ b/gpt_server.cpp
@@ -36,6 +36,7 @@
 #include "et_vector.hpp"
 #include "gpt_input.hpp"
 #include "gpt_xml_document.hpp"
+#include "ieee754.hpp"                  // ldbl_eps_plus_one_times()
 #include "ihs_irc7702a.hpp"
 #include "ihs_server7702.hpp"           // RunServer7702FromStruct()
 #include "materially_equal.hpp"         // material_difference()
@@ -58,7 +59,6 @@
 
 #include <algorithm>                    // min()
 #include <iostream>
-#include <limits>
 #include <string>
 #include <vector>
 
@@ -273,11 +273,6 @@ gpt_state test_one_days_gpt_transactions
     z.UpdateBOY7702A(InforceYear);
     z.UpdateBOM7702A(InforceMonth);
 
-    // See the implementation of class BasicValues.
-    long double const epsilon_plus_one =
-        1.0L + std::numeric_limits<long double>::epsilon()
-        ;
-
     double AnnualTargetPrem = 1000000000.0; // No higher premium is 
anticipated.
     int const target_year =
           database.Query(DB_TgtPremFixedAtIssue)
@@ -294,18 +289,22 @@ gpt_state test_one_days_gpt_transactions
         // 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
-            (   InforceTargetSpecifiedAmount
-            *   epsilon_plus_one
-            *   tabular_7Px[target_year]
+            (ldbl_eps_plus_one_times
+                ( InforceTargetSpecifiedAmount
+                * tabular_7Px[target_year]
+                )
             );
         }
     else if(oe_modal_table == target_premium_type)
         {
         AnnualTargetPrem = round_max_premium
-            (   database.Query(DB_TgtPremMonthlyPolFee)
-            +       InforceTargetSpecifiedAmount
-                *   epsilon_plus_one
-                *   TargetPremiumRates[target_year]
+            (ldbl_eps_plus_one_times
+                (   database.Query(DB_TgtPremMonthlyPolFee)
+                +
+                    ( InforceTargetSpecifiedAmount
+                    * TargetPremiumRates[target_year]
+                    )
+                )
             );
         }
     else
diff --git a/ieee754.hpp b/ieee754.hpp
index f450793..a894f87 100644
--- a/ieee754.hpp
+++ b/ieee754.hpp
@@ -122,10 +122,10 @@ inline bool is_infinite(T t)
 /// circumstances avoids this embarrassment while introducing an error
 /// that shouldn't matter.
 
-inline long double ldbl_eps_plus_one()
+inline double ldbl_eps_plus_one_times(double z)
 {
-    static long double const z = 1.0L + std::numeric_limits<long 
double>::epsilon();
-    return z;
+    static long double const y = 1.0L + std::numeric_limits<long 
double>::epsilon();
+    return static_cast<double>(y * z);
 }
 
 #endif // ieee754_hpp
diff --git a/ihs_basicval.cpp b/ihs_basicval.cpp
index 4f8bb28..27a685f 100644
--- a/ihs_basicval.cpp
+++ b/ihs_basicval.cpp
@@ -36,7 +36,7 @@
 #include "fund_data.hpp"
 #include "global_settings.hpp"
 #include "gpt_specamt.hpp"
-#include "ieee754.hpp"                  // ldbl_eps_plus_one()
+#include "ieee754.hpp"                  // ldbl_eps_plus_one_times()
 #include "ihs_irc7702.hpp"
 #include "ihs_irc7702a.hpp"
 #include "input.hpp"
@@ -919,7 +919,7 @@ double BasicValues::GetModalPremMaxNonMec
 {
     // TAXATION !! No table available if 7PP calculated from first principles.
     double temp = MortalityRates_->SevenPayRates()[0];
-    return round_max_premium()(temp * ldbl_eps_plus_one() * a_specamt / 
a_mode);
+    return round_max_premium()(ldbl_eps_plus_one_times(temp * a_specamt / 
a_mode));
 }
 
 /// Calculate premium using a target-premium ratio.
@@ -953,13 +953,13 @@ double BasicValues::GetModalPremTgtFromTable
     ) const
 {
     return round_max_premium()
-        (
-            (   TgtPremMonthlyPolFee * 12
-            +       a_specamt
-                *   ldbl_eps_plus_one()
-                *   MortalityRates_->TargetPremiumRates()[0]
+        (ldbl_eps_plus_one_times
+            (
+                ( TgtPremMonthlyPolFee * 12
+                + (a_specamt * MortalityRates_->TargetPremiumRates()[0])
+                )
+            /   a_mode
             )
-        /   a_mode
         );
 }
 
@@ -976,7 +976,7 @@ double BasicValues::GetModalPremCorridor
     ) const
 {
     double temp = GetCorridorFactor()[0];
-    return round_max_premium()((ldbl_eps_plus_one() * a_specamt / temp) / 
a_mode);
+    return round_max_premium()(ldbl_eps_plus_one_times((a_specamt / temp) / 
a_mode));
 }
 
 //============================================================================
@@ -1002,7 +1002,7 @@ double BasicValues::GetModalPremGLP
 // term rider, dumpin
 
     z /= a_mode;
-    return round_max_premium()(ldbl_eps_plus_one() * z);
+    return round_max_premium()(ldbl_eps_plus_one_times(z));
 }
 
 //============================================================================
@@ -1025,7 +1025,7 @@ double BasicValues::GetModalPremGSP
 // term rider, dumpin
 
     z /= a_mode;
-    return round_max_premium()(ldbl_eps_plus_one() * z);
+    return round_max_premium()(ldbl_eps_plus_one_times(z));
 }
 
 /// Calculate a monthly-deduction discount factor on the fly.
diff --git a/mec_server.cpp b/mec_server.cpp
index 2318d9c..261f8b3 100644
--- a/mec_server.cpp
+++ b/mec_server.cpp
@@ -34,6 +34,7 @@
 #include "database.hpp"
 #include "dbnames.hpp"
 #include "et_vector.hpp"
+#include "ieee754.hpp"                  // ldbl_eps_plus_one_times()
 #include "ihs_irc7702a.hpp"
 #include "materially_equal.hpp"         // material_difference()
 #include "math_functions.hpp"
@@ -57,7 +58,6 @@
 
 #include <algorithm>                    // min()
 #include <iostream>
-#include <limits>
 #include <string>
 #include <vector>
 
@@ -256,11 +256,6 @@ mec_state test_one_days_7702A_transactions
     z.UpdateBOY7702A(InforceYear);
     z.UpdateBOM7702A(InforceMonth);
 
-    // See the implementation of class BasicValues.
-    long double const epsilon_plus_one =
-        1.0L + std::numeric_limits<long double>::epsilon()
-        ;
-
     double AnnualTargetPrem = 1000000000.0; // No higher premium is 
anticipated.
     int const target_year =
           database.Query(DB_TgtPremFixedAtIssue)
@@ -277,18 +272,22 @@ mec_state test_one_days_7702A_transactions
         // 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
-            (   InforceTargetSpecifiedAmount
-            *   epsilon_plus_one
-            *   tabular_7Px[target_year]
+            (ldbl_eps_plus_one_times
+                ( InforceTargetSpecifiedAmount
+                * tabular_7Px[target_year]
+                )
             );
         }
     else if(oe_modal_table == target_premium_type)
         {
         AnnualTargetPrem = round_max_premium
-            (   database.Query(DB_TgtPremMonthlyPolFee)
-            +       InforceTargetSpecifiedAmount
-                *   epsilon_plus_one
-                *   TargetPremiumRates[target_year]
+            (ldbl_eps_plus_one_times
+                (   database.Query(DB_TgtPremMonthlyPolFee)
+                +
+                    ( InforceTargetSpecifiedAmount
+                    * TargetPremiumRates[target_year]
+                    )
+                )
             );
         }
     else



reply via email to

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