lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [lmi] valyuta/002 b803441 12/21: Improve documentation


From: Greg Chicares
Subject: [lmi-commits] [lmi] valyuta/002 b803441 12/21: Improve documentation
Date: Fri, 18 Sep 2020 21:53:48 -0400 (EDT)

branch: valyuta/002
commit b803441d082825c12d275da4567842409ebce724
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Improve documentation
---
 currency.hpp | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)

diff --git a/currency.hpp b/currency.hpp
index 80b5171..75836cc 100644
--- a/currency.hpp
+++ b/currency.hpp
@@ -82,10 +82,6 @@ class currency
     explicit currency(data_type i, bool) : m_ {i} {}
 
     currency& operator=(currency const&) = default;
-    // IMPORTANT eventually suppress this? or both of these?
-    // defining both causes real problems
-//  currency& operator=(double d) {m_ = from_double(d);           return 
*this;}
-//  currency& operator=(int    i) {m_ = cents_per_dollar * 
bourn_cast<data_type>(i); return *this;}
 
     double d() const {return to_double();}
 
@@ -97,20 +93,14 @@ class currency
 
     currency& operator+=(currency z) {m_ += z.m_; return *this;}
     currency& operator-=(currency z) {m_ -= z.m_; return *this;}
-    // NOPE!
-//  currency& operator*=(currency z) {m_ *= z.m_; return *this;}
+    // There can be no operator*() that returns a result in dollars^2.
 
     currency& operator+=(double z) {m_ += from_double(z); return *this;}
     currency& operator-=(double z) {m_ -= from_double(z); return *this;}
-    // NOPE!
-//  currency& operator*=(double z) {m_ *= from_double(z); return *this;}
-    // Check result range (and avoid multiplying by 100/100):
-//  currency& operator*=(double z) {m_ = bourn_cast<data_type>(100.0 * 
to_double() * z); return *this;}
-    // Far too permissive:
-//  currency& operator*=(double z) {m_ = static_cast<data_type>(100.0 * 
to_double() * z); return *this;}
-    // wrong: doesn't affect '*this'
-//  double operator*=(double z) {return to_double() * z;}
-// Dangerous--can somehow take the place of operator*(double)
+
+    // Mixed-mode arithmetic is generally to be avoided, but it is
+    // safe to multiply currency by an integer such as twelve:
+    // $1 monthly really does equal $12 annually.
     currency const& operator*=(int z) {m_ *= z; return *this;}
 
     data_type m() const {return m_;} // restrict to friends?
@@ -131,8 +121,6 @@ class currency
     data_type from_double(double d) const {return d;}
     double to_double() const {return m_;}
 #endif // defined MAKE_IT_EVEN_FASTER
-//  data_type from_double(double d) const {return 
static_cast<data_type>(cents_per_dollar * d);}
-//  double to_double() const {return static_cast<double>(m_) / 
cents_per_dollar;}
 #if 0 // will a fwd decl be wanted somewhere?
     data_type round(double d) const
         {



reply via email to

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