[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] valyuta/005 61396fd 06/10: Expunge the unclean macro
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] valyuta/005 61396fd 06/10: Expunge the unclean macro just added |
Date: |
Thu, 21 Jan 2021 17:48:16 -0500 (EST) |
branch: valyuta/005
commit 61396fdaa73e88fca2f61432f77710a39098bef6
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Expunge the unclean macro just added
DETECT_NONINTEGRAL_CENTS felt too much like the standard DEBUG macro.
Given that currency objects are almost always constructed from a rounded
value in round_to<>::c(), it's better to perform the integrality test,
unconditionally, only in from_cents().
---
currency.hpp | 20 ++++++--------------
1 file changed, 6 insertions(+), 14 deletions(-)
diff --git a/currency.hpp b/currency.hpp
index b94c9d2..bdea412 100644
--- a/currency.hpp
+++ b/currency.hpp
@@ -37,7 +37,6 @@
#if !defined USE_CURRENCY_CLASS
# undef CURRENCY_UNIT_IS_CENTS // Requires currency class.
-# undef DETECT_NONINTEGRAL_CENTS // Meaningful only with currency class.
using currency = double;
@@ -53,7 +52,6 @@ inline std::vector<double> dblize(std::vector<currency>
const& z)
#else // defined USE_CURRENCY_CLASS
# define CURRENCY_UNIT_IS_CENTS
-# define DETECT_NONINTEGRAL_CENTS
class raw_cents {}; // Tag class.
@@ -79,17 +77,7 @@ class currency
currency& operator=(currency const&) = default;
~currency() = default;
- explicit currency(data_type z, raw_cents) : m_ {z}
- {
-# if defined DETECT_NONINTEGRAL_CENTS
- // CURRENCY !! Consider removing this test altogether, and
- // making the explicit ctor private so that only friend
- // template class round_to can use it (with arguments that
- // are certainly exact integers because they have just been
- // rounded).
- if(z != std::rint(z)) throw std::runtime_error("Nonintegral cents.");
-# endif // defined DETECT_NONINTEGRAL_CENTS
- }
+ 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;}
@@ -141,7 +129,11 @@ inline double operator/(currency lhs, double rhs)
inline std::ostream& operator<<(std::ostream& os, currency z)
{return os << z.d();}
-inline currency from_cents(double z) {return currency(z, raw_cents{});}
+inline currency from_cents(double z)
+ {
+ if(z != std::rint(z)) throw std::runtime_error("Nonintegral cents.");
+ return currency(z, raw_cents{});
+ }
inline double dblize(currency z) {return z.d();}
- [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 <=
- [lmi-commits] [lmi] valyuta/005 4b0bf87 07/10: Detect nonintegral cents along every path, Greg Chicares, 2021/01/21
- [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