[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] valyuta/005 75f8adf 7/9: Add and use free function f
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] valyuta/005 75f8adf 7/9: Add and use free function from_cents() |
Date: |
Wed, 20 Jan 2021 00:51:33 -0500 (EST) |
branch: valyuta/005
commit 75f8adfead85cae76f3ac8da8df654c32a962526
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Add and use free function from_cents()
---
currency.hpp | 4 ++++
currency_test.cpp | 2 ++
ihs_acctval.cpp | 4 ++--
ihs_avmly.cpp | 4 ++--
ihs_avsolve.cpp | 2 +-
5 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/currency.hpp b/currency.hpp
index 8694c78..03fbcf7 100644
--- a/currency.hpp
+++ b/currency.hpp
@@ -35,6 +35,8 @@
using currency = double;
+inline currency from_cents(double z) {return z / 100.0;}
+
inline double d(currency z) {return z;}
inline std::vector<double> doubleize(std::vector<currency> const& z)
@@ -118,6 +120,8 @@ inline double operator/(currency const& lhs, double rhs)
inline std::ostream& operator<<(std::ostream& os, currency const& z)
{return os << z.d();}
+inline currency from_cents(double z) {return currency(z, raw_cents{});}
+
inline double d(currency z) {return z.d();}
inline std::vector<double> doubleize(std::vector<currency> const& z)
diff --git a/currency_test.cpp b/currency_test.cpp
index 1849525..176b474 100644
--- a/currency_test.cpp
+++ b/currency_test.cpp
@@ -227,6 +227,8 @@ void currency_test::test_quodlibet()
currency a1(475, raw_cents{});
BOOST_TEST_EQUAL(4.75, a1.d());
BOOST_TEST_EQUAL(4.75, d(a1));
+ currency const a2 = from_cents(125);
+ BOOST_TEST_EQUAL(1.25, d(a2));
currency b0 = round_to_nearest_cent.c(464.180000000000006821);
currency b1 = round_to_nearest_cent.c(263.01999999999998181);
diff --git a/ihs_acctval.cpp b/ihs_acctval.cpp
index c9e1a39..19f573e 100644
--- a/ihs_acctval.cpp
+++ b/ihs_acctval.cpp
@@ -257,7 +257,7 @@ void AccountValue::SetGuarPrem()
GuarPremium = SolveGuarPremium();
}
// bignum: the largest integer convertible to and from double.
- LMI_ASSERT(GuarPremium < currency(1LL << 53, raw_cents{}));
+ LMI_ASSERT(GuarPremium < from_cents(1LL << 53));
ledger_->SetGuarPremium(d(GuarPremium));
}
@@ -652,7 +652,7 @@ void AccountValue::SetInitialValues()
// which is the identity element for std::max(). Here, it's nearly
// the equivalent for currency::data_type; dividing it by 101 is a
// casual defense against commuting between dollars and cents.
- HoneymoonValue = currency(-std::numeric_limits<currency::data_type>::max()
/ 101, raw_cents{});
+ HoneymoonValue =
from_cents(-std::numeric_limits<currency::data_type>::max() / 101);
if(mce_gen_curr == GenBasis_)
{
HoneymoonActive = yare_input_.HoneymoonEndorsement;
diff --git a/ihs_avmly.cpp b/ihs_avmly.cpp
index 5d75a1a..e9119f1 100644
--- a/ihs_avmly.cpp
+++ b/ihs_avmly.cpp
@@ -1277,7 +1277,7 @@ void AccountValue::TxAscertainDesiredPayment()
;
assert_pmts_add_up(__FILE__, __LINE__, Month);
// bignum: the largest integer convertible to and from double.
- LMI_ASSERT(GrossPmts[Month] < currency(1LL << 53, raw_cents{}));
+ LMI_ASSERT(GrossPmts[Month] < from_cents(1LL << 53));
if(0 == Year && 0 == Month)
{
@@ -2045,7 +2045,7 @@ void AccountValue::TxTestHoneymoonForExpiration()
// which is the identity element for std::max(). Here, it's nearly
// the equivalent for currency::data_type; dividing it by 101 is a
// casual defense against commuting between dollars and cents.
- HoneymoonValue =
currency(-std::numeric_limits<currency::data_type>::max() / 101, raw_cents{});
+ HoneymoonValue =
from_cents(-std::numeric_limits<currency::data_type>::max() / 101);
}
}
diff --git a/ihs_avsolve.cpp b/ihs_avsolve.cpp
index adee894..3ca12db 100644
--- a/ihs_avsolve.cpp
+++ b/ihs_avsolve.cpp
@@ -251,7 +251,7 @@ currency AccountValue::SolveTest(currency a_CandidateValue)
if(mce_solve_for_non_mec == SolveTarget_)
{
- static const currency C1(100, raw_cents{}); // One hundred cents.
+ static const currency C1 = from_cents(100); // One hundred cents.
return InvariantValues().IsMec ? -C1 : C1;
}
- [lmi-commits] [lmi] valyuta/005 updated (4401725 -> ca84095), Greg Chicares, 2021/01/20
- [lmi-commits] [lmi] valyuta/005 4483b09 1/9: Avoid passing 'currency' by const reference, Greg Chicares, 2021/01/20
- [lmi-commits] [lmi] valyuta/005 1dd82ec 3/9: Rationalize argument names, Greg Chicares, 2021/01/20
- [lmi-commits] [lmi] valyuta/005 cb722b2 4/9: Replace a complaint with a solution, Greg Chicares, 2021/01/20
- [lmi-commits] [lmi] valyuta/005 2e73521 5/9: Begin to conditionalize use of currency class, Greg Chicares, 2021/01/20
- [lmi-commits] [lmi] valyuta/005 b835c6d 2/9: Partially revert the last commit, Greg Chicares, 2021/01/20
- [lmi-commits] [lmi] valyuta/005 afa4967 8/9: Make lmi build without currency class, Greg Chicares, 2021/01/20
- [lmi-commits] [lmi] valyuta/005 ca84095 9/9: Record speed measurements, Greg Chicares, 2021/01/20
- [lmi-commits] [lmi] valyuta/005 df368ca 6/9: Replace currency::d() with d(currency) almost everywhere, Greg Chicares, 2021/01/20
- [lmi-commits] [lmi] valyuta/005 75f8adf 7/9: Add and use free function from_cents(),
Greg Chicares <=