lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] master e5b0ac2 2/2: Use new PETE Max() and Min()


From: Greg Chicares
Subject: [lmi-commits] [lmi] master e5b0ac2 2/2: Use new PETE Max() and Min()
Date: Fri, 26 Feb 2021 15:46:41 -0500 (EST)

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

    Use new PETE Max() and Min()
    
    This:
      Max(0.0, Min(X, Y))
    is much easier to understand than this:
      apply_binary(greater_of, 0.0, apply_binary(lesser_of<double>(), X, Y))
    
    Expunged now-unneeded greater_of and lesser_of function objects.
---
 dbvalue.cpp                    |  5 ++---
 expression_template_0_test.cpp | 11 +----------
 i7702.cpp                      | 12 ++++--------
 ihs_mortal.cpp                 |  5 ++---
 math_functions.hpp             | 24 ------------------------
 math_functions_test.cpp        |  3 ---
 6 files changed, 9 insertions(+), 51 deletions(-)

diff --git a/dbvalue.cpp b/dbvalue.cpp
index dd8117c..22127dc 100644
--- a/dbvalue.cpp
+++ b/dbvalue.cpp
@@ -29,7 +29,6 @@
 #include "dbnames.hpp"
 #include "et_vector.hpp"
 #include "handle_exceptions.hpp"        // report_exception()
-#include "math_functions.hpp"           // lesser_of()
 #include "print_matrix.hpp"
 #include "value_cast.hpp"
 #include "xml_serialize.hpp"
@@ -219,8 +218,8 @@ void database_entity::reshape(std::vector<int> const& 
new_dims)
         LMI_ASSERT(0 == z);
 
         // limit dst and source indexes to those that actually vary
-        assign(dst_idx, apply_binary(lesser_of<int>(), working_idx, 
dst_max_idx));
-        assign(src_idx, apply_binary(lesser_of<int>(), working_idx, 
src_max_idx));
+        assign(dst_idx, Min(working_idx, dst_max_idx));
+        assign(src_idx, Min(working_idx, src_max_idx));
         new_object[dst_idx] = operator[](src_idx);
         }
 
diff --git a/expression_template_0_test.cpp b/expression_template_0_test.cpp
index c40c182..7150961 100644
--- a/expression_template_0_test.cpp
+++ b/expression_template_0_test.cpp
@@ -76,15 +76,6 @@
 
 namespace
 {
-template<typename T>
-struct greater_of
-{
-    T operator()(T const& x, T const& y) const
-        {
-        return std::max(x, y);
-        }
-};
-
     // Global variables for timing tests. They could alternatively be
     // passed as arguments, e.g., by using std::bind, but that would
     // increase complexity in return for no real benefit.
@@ -362,7 +353,7 @@ void mete_pete_typical()
 
 // This works. It's commented out only for comparability to other
 // approaches.
-//    assign(pv0, apply_binary(greater_of<double>(), pv8, pv9));
+//    assign(pv0, Max(pv8, pv9));
 
         assign(pv9, (1.0 - pv8) * pv9);
         }
diff --git a/i7702.cpp b/i7702.cpp
index 713ce08..1c37df1 100644
--- a/i7702.cpp
+++ b/i7702.cpp
@@ -75,11 +75,7 @@ i7702::i7702
             database_.query_into(DB_GuarRegLoanSpread, guar_loan_spread);
             assign
                 (guar_int
-                ,apply_binary
-                    (greater_of<double>()
-                    ,guar_int
-                    ,gross_loan_rate - guar_loan_spread
-                    )
+                ,Max(guar_int, gross_loan_rate - guar_loan_spread)
                 );
             }
         }
@@ -93,7 +89,7 @@ i7702::i7702
         (gross_
         ,apply_unary
             (i_upper_12_over_12_from_i<double>()
-            ,apply_binary(greater_of<double>(), statutory7702i, guar_int)
+            ,Max(statutory7702i, guar_int)
             )
         );
 
@@ -102,7 +98,7 @@ i7702::i7702
         (net_glp_
         ,apply_unary
             (i_upper_12_over_12_from_i<double>()
-            ,apply_binary(greater_of<double>(), statutory7702i, guar_int) - 
spread_
+            ,Max(statutory7702i, guar_int) - spread_
             )
         );
 
@@ -111,7 +107,7 @@ i7702::i7702
         (net_gsp_
         ,apply_unary
             (i_upper_12_over_12_from_i<double>()
-            ,apply_binary(greater_of<double>(), 0.02 + statutory7702i, 
guar_int) - spread_
+            ,Max(0.02 + statutory7702i, guar_int) - spread_
             )
         );
 
diff --git a/ihs_mortal.cpp b/ihs_mortal.cpp
index e7142fa..d04768e 100644
--- a/ihs_mortal.cpp
+++ b/ihs_mortal.cpp
@@ -254,9 +254,8 @@ void 
MortalityRates::MakeCoiRateSubstandard(std::vector<double>& coi_rates)
         {0.0, 0.25, 0.50, 0.75, 1.00, 1.25, 1.50, 2.00, 2.50, 3.00, 4.00,};
     assign
         (coi_rates
-        ,apply_binary
-            (lesser_of<double>()
-            ,MaxMonthlyCoiRate_
+        ,Min
+            (MaxMonthlyCoiRate_
             ,   AnnualFlatExtra_ / 12000.0
               + coi_rates * (1.0 + SubstdTblMult_ * factors[SubstandardTable_])
             )
diff --git a/math_functions.hpp b/math_functions.hpp
index 6935035..b39090b 100644
--- a/math_functions.hpp
+++ b/math_functions.hpp
@@ -57,30 +57,6 @@ std::vector<T>& back_sum(std::vector<T>& v)
 // std::binary_function would have provided, because they're still
 // required for std::binder1st() or std::binder2nd(), or for PETE.
 
-template<typename T>
-struct greater_of
-{
-    using first_argument_type  = T;
-    using second_argument_type = T;
-    using result_type          = T;
-    T operator()(T const& x, T const& y) const
-        {
-        return std::max(x, y);
-        }
-};
-
-template<typename T>
-struct lesser_of
-{
-    using first_argument_type  = T;
-    using second_argument_type = T;
-    using result_type          = T;
-    T operator()(T const& x, T const& y) const
-        {
-        return std::min(x, y);
-        }
-};
-
 /// Arithmetic mean.
 ///
 /// Calculate mean as
diff --git a/math_functions_test.cpp b/math_functions_test.cpp
index 6001fb0..cf7c283 100644
--- a/math_functions_test.cpp
+++ b/math_functions_test.cpp
@@ -260,9 +260,6 @@ int test_main(int, char*[])
     long double smallnumL = std::numeric_limits<long double>::min();
     long double bignumL   = std::numeric_limits<long double>::max();
 
-    BOOST_TEST_EQUAL(2.0, greater_of<double>()(1.0, 2.0));
-    BOOST_TEST_EQUAL(1.0, lesser_of <double>()(1.0, 2.0));
-
     // Test mean<>().
 
     BOOST_TEST_EQUAL(1.5, mean<double>()(1.0, 2.0));



reply via email to

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