[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] valyuta/002 8785c00 19/21: Implement negation operat
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] valyuta/002 8785c00 19/21: Implement negation operator |
Date: |
Fri, 18 Sep 2020 21:53:50 -0400 (EDT) |
branch: valyuta/002
commit 8785c00248c5567daa116236a514c97de9c3c696
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Implement negation operator
---
currency.hpp | 5 +----
currency_test.cpp | 3 +++
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/currency.hpp b/currency.hpp
index 4aa8e56..c5d7899 100644
--- a/currency.hpp
+++ b/currency.hpp
@@ -88,10 +88,7 @@ class currency
double d() const {return to_double();}
// Is this the ideal signature for this operator?
-// currency operator-() const {return currency(-m_);}
-// currency& operator-() {m_ = -m_; return *this;}
-// Dangerous--demonstrably makes calculations wrong, but hard to see why
-// currency operator-() const {return currency(bourn_cast<double>(-m_));}
+ currency operator-() const {return currency(-m_, true);}
currency& operator+=(currency z) {m_ += z.m_; return *this;}
currency& operator-=(currency z) {m_ -= z.m_; return *this;}
diff --git a/currency_test.cpp b/currency_test.cpp
index f519c64..0224b03 100644
--- a/currency_test.cpp
+++ b/currency_test.cpp
@@ -61,6 +61,9 @@ void currency_test::test_something()
currency a2 = currency() - a1;
BOOST_TEST(-6.50 == a2.d());
BOOST_TEST( -650 == a2.m_);
+ a2 = -a1;
+ BOOST_TEST(-6.50 == a2.d());
+ BOOST_TEST( -650 == a2.m_);
double d0 = 123.99999999999;
currency c0(d0);
- [lmi-commits] [lmi] valyuta/002 06046b6 05/21: Revert "Make it float", (continued)
- [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
- [lmi-commits] [lmi] valyuta/002 8785c00 19/21: Implement negation operator,
Greg Chicares <=
- [lmi-commits] [lmi] valyuta/002 97eb31d 20/21: Use negation operator, Greg Chicares, 2020/09/18