[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
{
- [lmi-commits] [lmi] valyuta/002 updated (3f71218 -> 97e9057), Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 da89fe3 04/21: Revert "Make it faster", Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 4b313b0 07/21: Discard some commented-out code, Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 e474aa4 09/21: Remove int relops, Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 d1c1af3 01/21: Revert "Trivially avoid spurious regression errors", Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 693dac0 02/21: Revert "Make it even faster", Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 24abb3f 03/21: Revert "Make it more faster", Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 95f34c4 06/21: Get rid of unneeded scalar doubleize(), Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 9dc1602 10/21: Remove double relops, Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 b803441 12/21: Improve documentation,
Greg Chicares <=
- [lmi-commits] [lmi] valyuta/002 06046b6 05/21: Revert "Make it float", Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 215244a 13/21: Avoid implicit mixed-mode calculations more avidly, Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 63419d4 14/21: Improve documentation, Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 d8e2470 15/21: Refactor for clarity, Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 b07371e 17/21: Avoid implicit conversions yet more avidly, Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 331e748 18/21: Unbreak a unit test, Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 02d03f2 08/21: Discard more commented-out code, Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 3266cfe 11/21: Establish a separate test/ directory for this branch, Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 0e9baa5 16/21: Use currency where currency is wanted, Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 97e9057 21/21: Fix a unit test, Greg Chicares, 2020/09/18