lmi-commits
[Top][All Lists]
Advanced

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



reply via email to

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