[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] valyuta/002 63419d4 14/21: Improve documentation
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] valyuta/002 63419d4 14/21: Improve documentation |
Date: |
Fri, 18 Sep 2020 21:53:49 -0400 (EDT) |
branch: valyuta/002
commit 63419d484f25c409154f2903b4ba9d90d9324968
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Improve documentation
---
currency.hpp | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/currency.hpp b/currency.hpp
index 55ba053..ca6cd74 100644
--- a/currency.hpp
+++ b/currency.hpp
@@ -100,7 +100,15 @@ class currency
// 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.
+ // $1 monthly really does equal $12 annually. No operator/(int)
+ // is provided because $1 annually doesn't equal any integral
+ // number of cents per month.
+ //
+ // Ignore the possibility of overflow, at least for now:
+ // - multiplying by an enormous integer would be unreasonable;
+ // - C++ can't detect integer overflow very well anyway; and
+ // ultimately this class might use a floating data_type, which is
+ // highly unlikely to overflow on multiplication by an int.
currency const& operator*=(int z) {m_ *= z; return *this;}
data_type m() const {return m_;} // restrict to friends?
@@ -151,13 +159,18 @@ inline bool operator>=(currency const& lhs, currency
const& rhs){return !operato
inline currency operator+(currency lhs, currency rhs) {return lhs += rhs;}
inline currency operator-(currency lhs, currency rhs) {return lhs -= rhs;}
-// Don't actually want any member operator*() for double:
+inline currency operator*(currency lhs, int rhs) {return lhs *= rhs;}
+inline currency operator*(int lhs, currency rhs) {return rhs *= lhs;}
+
+// There is deliberately no operator*=(double) or operator/=(double).
+// These operators are safe because they return double. Yet because
+// they are implicit, they hide conversions. At least the conversions
+// they hide are the comparatively inexpensive and value-preserving
+// to_double() instead of the expensive from_double() that does not
+// preserve value. Probably either analogous additive operators should
+// be provided, or these should not be provided.
inline double operator*(currency lhs, double rhs) {return lhs.d() * rhs;}
inline double operator*(double lhs, currency rhs) {return lhs * rhs.d();}
-inline currency operator*(currency lhs, int rhs) {return lhs *= rhs;}
-inline currency operator*(int lhs, currency rhs) {return rhs *= lhs;}
-//inline currency operator*(currency lhs, int rhs) {return lhs *= rhs;}
-//inline currency operator*(int lhs, currency rhs) {return rhs *= lhs;}
inline double operator/(currency lhs, double rhs) {return lhs.d() / rhs;}
inline double operator/(double lhs, currency rhs) {return lhs / rhs.d();}
- [lmi-commits] [lmi] valyuta/002 4b313b0 07/21: Discard some commented-out code, (continued)
- [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, 2020/09/18
- [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 <=
- [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
- [lmi-commits] [lmi] valyuta/002 8785c00 19/21: Implement negation operator, Greg Chicares, 2020/09/18
- [lmi-commits] [lmi] valyuta/002 97eb31d 20/21: Use negation operator, Greg Chicares, 2020/09/18