[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] valyuta/005 4b0bf87 07/10: Detect nonintegral cents
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] valyuta/005 4b0bf87 07/10: Detect nonintegral cents along every path |
Date: |
Thu, 21 Jan 2021 17:48:16 -0500 (EST) |
branch: valyuta/005
commit 4b0bf87facbf77c40771d3ce42efa183144d7413
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Detect nonintegral cents along every path
Made the explicit ctor private, ensuring that it's used only with values
that are certain to be integral:
- in round_to, because they've been rounded; else
- in from_cents(), because they've been tested.
Testing that precondition makes the latter case slower, but that case is
so uncommon as to be negligible, so speed is essentially the same as it
was without this guarantee.
---
Speed_gcc_i686-w64-mingw32 | 12 ++++++------
Speed_gcc_x86_64-pc-linux-gnu | 12 ++++++------
Speed_gcc_x86_64-w64-mingw32 | 12 ++++++------
currency.hpp | 16 ++++++++--------
loads_test.cpp | 14 +++++++-------
5 files changed, 33 insertions(+), 33 deletions(-)
diff --git a/Speed_gcc_i686-w64-mingw32 b/Speed_gcc_i686-w64-mingw32
index 92be5a8..879f80b 100644
--- a/Speed_gcc_i686-w64-mingw32
+++ b/Speed_gcc_i686-w64-mingw32
@@ -1,7 +1,7 @@
Test speed:
- naic, no solve : 6.283e-02 s mean; 62216 us least of 16 runs
- naic, specamt solve : 1.158e-01 s mean; 115250 us least of 9 runs
- naic, ee prem solve : 1.053e-01 s mean; 104619 us least of 10 runs
- finra, no solve : 1.770e-02 s mean; 17407 us least of 57 runs
- finra, specamt solve: 6.567e-02 s mean; 65102 us least of 16 runs
- finra, ee prem solve: 6.045e-02 s mean; 59822 us least of 17 runs
+ naic, no solve : 5.379e-02 s mean; 53446 us least of 19 runs
+ naic, specamt solve : 1.001e-01 s mean; 99577 us least of 10 runs
+ naic, ee prem solve : 9.113e-02 s mean; 90771 us least of 11 runs
+ finra, no solve : 1.657e-02 s mean; 16402 us least of 61 runs
+ finra, specamt solve: 5.885e-02 s mean; 58558 us least of 17 runs
+ finra, ee prem solve: 5.412e-02 s mean; 53919 us least of 19 runs
diff --git a/Speed_gcc_x86_64-pc-linux-gnu b/Speed_gcc_x86_64-pc-linux-gnu
index 5bb8ad4..a4432b6 100644
--- a/Speed_gcc_x86_64-pc-linux-gnu
+++ b/Speed_gcc_x86_64-pc-linux-gnu
@@ -1,7 +1,7 @@
Test speed:
- naic, no solve : 2.228e-02 s mean; 21562 us least of 45 runs
- naic, specamt solve : 3.938e-02 s mean; 38908 us least of 26 runs
- naic, ee prem solve : 3.572e-02 s mean; 35374 us least of 28 runs
- finra, no solve : 6.131e-03 s mean; 5817 us least of 100 runs
- finra, specamt solve: 2.200e-02 s mean; 21553 us least of 46 runs
- finra, ee prem solve: 2.026e-02 s mean; 19766 us least of 50 runs
+ naic, no solve : 2.039e-02 s mean; 20072 us least of 50 runs
+ naic, specamt solve : 3.704e-02 s mean; 36518 us least of 27 runs
+ naic, ee prem solve : 3.374e-02 s mean; 33142 us least of 30 runs
+ finra, no solve : 5.961e-03 s mean; 5834 us least of 100 runs
+ finra, specamt solve: 2.107e-02 s mean; 20472 us least of 48 runs
+ finra, ee prem solve: 1.947e-02 s mean; 19032 us least of 52 runs
diff --git a/Speed_gcc_x86_64-w64-mingw32 b/Speed_gcc_x86_64-w64-mingw32
index f4554d9..7f2b2d3 100644
--- a/Speed_gcc_x86_64-w64-mingw32
+++ b/Speed_gcc_x86_64-w64-mingw32
@@ -1,7 +1,7 @@
Test speed:
- naic, no solve : 2.955e-02 s mean; 29217 us least of 34 runs
- naic, specamt solve : 5.044e-02 s mean; 49875 us least of 20 runs
- naic, ee prem solve : 4.615e-02 s mean; 45675 us least of 22 runs
- finra, no solve : 1.073e-02 s mean; 10507 us least of 94 runs
- finra, specamt solve: 2.965e-02 s mean; 29297 us least of 34 runs
- finra, ee prem solve: 2.767e-02 s mean; 27244 us least of 37 runs
+ naic, no solve : 2.780e-02 s mean; 27428 us least of 36 runs
+ naic, specamt solve : 4.750e-02 s mean; 46912 us least of 22 runs
+ naic, ee prem solve : 4.361e-02 s mean; 43042 us least of 23 runs
+ finra, no solve : 1.057e-02 s mean; 10328 us least of 95 runs
+ finra, specamt solve: 2.841e-02 s mean; 28041 us least of 36 runs
+ finra, ee prem solve: 2.641e-02 s mean; 26042 us least of 38 runs
diff --git a/currency.hpp b/currency.hpp
index bdea412..a87a9a3 100644
--- a/currency.hpp
+++ b/currency.hpp
@@ -58,8 +58,9 @@ class raw_cents {}; // Tag class.
class currency
{
friend class currency_test;
- template<typename> friend class round_to;
- friend class round_to_test;
+ friend currency from_cents(double); // explicit ctor
+ template<typename> friend class round_to; // explicit ctor
+ friend class round_to_test; // currency::cents_digits
# if defined CURRENCY_UNIT_IS_CENTS
static constexpr int cents_digits = 2;
@@ -77,12 +78,12 @@ class currency
currency& operator=(currency const&) = default;
~currency() = default;
- explicit currency(data_type z, raw_cents) : m_ {z} {}
-
currency& operator+=(currency z) {m_ += z.m_; return *this;}
currency& operator-=(currency z) {m_ -= z.m_; return *this;}
- currency& operator*=(int z) {m_ *= z ; return *this;}
+ currency& operator*=(int z) {m_ *= z ; return *this;}
+
+ currency operator-() const {return currency(-cents(), raw_cents {});}
data_type cents() const {return m_;}
// CURRENCY !! add a unit test for possible underflow
@@ -90,6 +91,8 @@ class currency
double d() const {return m_ / cents_per_dollar;}
private:
+ explicit currency(data_type z, raw_cents) : m_ {z} {}
+
data_type m_ = {};
};
@@ -106,9 +109,6 @@ inline bool operator<=(currency lhs, currency rhs)
inline bool operator>=(currency lhs, currency rhs)
{return !operator< (lhs, rhs);}
-inline currency operator-(currency z)
- {return currency(-z.cents(), raw_cents {});}
-
inline currency operator+(currency lhs, currency rhs)
{return currency {lhs} += rhs;}
inline currency operator-(currency lhs, currency rhs)
diff --git a/loads_test.cpp b/loads_test.cpp
index 00bdf56..11a0249 100644
--- a/loads_test.cpp
+++ b/loads_test.cpp
@@ -86,8 +86,8 @@ void LoadsTest::Reinitialize()
loads_.refundable_sales_load_proportion_ = std::vector<double>
(length, 0.50000);
loads_.dac_tax_load_ = std::vector<double>
(length, 0.00500);
- loads_.monthly_policy_fee_ [mce_gen_guar] =
std::vector<currency>(length, currency(800, raw_cents{}));
- loads_.annual_policy_fee_ [mce_gen_guar] =
std::vector<currency>(length, currency(200, raw_cents{}));
+ loads_.monthly_policy_fee_ [mce_gen_guar] =
std::vector<currency>(length, from_cents(800));
+ loads_.annual_policy_fee_ [mce_gen_guar] =
std::vector<currency>(length, from_cents(200));
loads_.specified_amount_load_[mce_gen_guar] = std::vector<double>
(length, 0.00003);
loads_.separate_account_load_[mce_gen_guar] = std::vector<double>
(length, 0.00130);
loads_.target_premium_load_ [mce_gen_guar] = std::vector<double>
(length, 0.04000);
@@ -95,8 +95,8 @@ void LoadsTest::Reinitialize()
loads_.target_sales_load_ [mce_gen_guar] = std::vector<double>
(length, 0.30000);
loads_.excess_sales_load_ [mce_gen_guar] = std::vector<double>
(length, 0.15000);
- loads_.monthly_policy_fee_ [mce_gen_curr] =
std::vector<currency>(length, currency(525, raw_cents{}));
- loads_.annual_policy_fee_ [mce_gen_curr] =
std::vector<currency>(length, currency(100, raw_cents{}));
+ loads_.monthly_policy_fee_ [mce_gen_curr] =
std::vector<currency>(length, from_cents(525));
+ loads_.annual_policy_fee_ [mce_gen_curr] =
std::vector<currency>(length, from_cents(100));
loads_.specified_amount_load_[mce_gen_curr] = std::vector<double>
(length, 0.00002);
loads_.separate_account_load_[mce_gen_curr] = std::vector<double>
(length, 0.00110);
loads_.target_premium_load_ [mce_gen_curr] = std::vector<double>
(length, 0.02000);
@@ -159,8 +159,8 @@ void LoadsTest::TestCalculations(char const* file, int line)
INVOKE_BOOST_TEST(materially_equal(0.500000,
loads_.refundable_sales_load_proportion()[0]), file, line);
// (8.00 + 5.25 + 0.50) / 2 = 13.75 / 2 = 6.875, rounded to cents
- INVOKE_BOOST_TEST(currency(688, raw_cents{}) == loads_.monthly_policy_fee
(mce_gen_mdpt)[0] , file, line);
- INVOKE_BOOST_TEST(currency(150, raw_cents{}) == loads_.annual_policy_fee
(mce_gen_mdpt)[0] , file, line);
+ INVOKE_BOOST_TEST(from_cents(688) == loads_.monthly_policy_fee
(mce_gen_mdpt)[0] , file, line);
+ INVOKE_BOOST_TEST(from_cents(150) == loads_.annual_policy_fee
(mce_gen_mdpt)[0] , file, line);
INVOKE_BOOST_TEST(materially_equal(0.000625, loads_.specified_amount_load
(mce_gen_mdpt)[0]), file, line);
// 12 bp and 19 bp, both converted to monthly, then added together.
INVOKE_BOOST_TEST(materially_equal(0.0002581402795930,
loads_.separate_account_load (mce_gen_mdpt)[0]), file, line);
@@ -196,7 +196,7 @@ int test_main(int, char*[])
round_to<double> round_minutiae (2, r_to_nearest);
std::vector<double> extra_comp_load (length, 0.0170);
std::vector<double> extra_asset_comp (length, 0.0019);
- std::vector<currency> extra_policy_fee (length, currency(50, raw_cents{}));
+ std::vector<currency> extra_policy_fee (length, from_cents(50));
std::vector<double> guar_specamt_load(length, 0.0007);
std::vector<double> curr_specamt_load(length, 0.0005);
- [lmi-commits] [lmi] valyuta/005 updated (133d646 -> 9e42155), Greg Chicares, 2021/01/21
- [lmi-commits] [lmi] valyuta/005 d763c34 04/10: Clean up, Greg Chicares, 2021/01/21
- [lmi-commits] [lmi] valyuta/005 2712277 02/10: Default class currency's special member functions, Greg Chicares, 2021/01/21
- [lmi-commits] [lmi] valyuta/005 86cba7f 09/10: Temporarily don't use currency class, Greg Chicares, 2021/01/21
- [lmi-commits] [lmi] valyuta/005 7f6a453 01/10: Revert "Partially revert the last commit", Greg Chicares, 2021/01/21
- [lmi-commits] [lmi] valyuta/005 c0a93cf 03/10: Reorder currency unit tests, Greg Chicares, 2021/01/21
- [lmi-commits] [lmi] valyuta/005 e40980b 05/10: Optionally detect nonintegral cents at run time, Greg Chicares, 2021/01/21
- [lmi-commits] [lmi] valyuta/005 61396fd 06/10: Expunge the unclean macro just added, Greg Chicares, 2021/01/21
- [lmi-commits] [lmi] valyuta/005 4b0bf87 07/10: Detect nonintegral cents along every path,
Greg Chicares <=
- [lmi-commits] [lmi] valyuta/005 6767160 08/10: Temporarily don't use cents, Greg Chicares, 2021/01/21
- [lmi-commits] [lmi] valyuta/005 9e42155 10/10: Undo temporary changes: use currency class with cents, Greg Chicares, 2021/01/21