lmi-commits
[Top][All Lists]
Advanced

[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();}
 



reply via email to

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