summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/COPYRIGHT30
-rw-r--r--src/balance.h11
-rw-r--r--src/value.cc16
-rw-r--r--tests/numerics/BasicAmount.cc7
-rw-r--r--tests/python/numerics/BasicAmount.py5
5 files changed, 29 insertions, 40 deletions
diff --git a/src/COPYRIGHT b/src/COPYRIGHT
deleted file mode 100644
index c9d4bd18..00000000
--- a/src/COPYRIGHT
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (c) 2003-2007, John Wiegley. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * - Neither the name of New Artisans LLC nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
diff --git a/src/balance.h b/src/balance.h
index a7c95870..40f1eec0 100644
--- a/src/balance.h
+++ b/src/balance.h
@@ -41,7 +41,9 @@ class balance_t
equality_comparable<balance_t, amount_t,
additive<balance_t,
additive<balance_t, amount_t,
- multiplicative<balance_t, amount_t> > > > >
+ multiplicative<balance_t, amount_t,
+ multiplicative<balance_t, unsigned long,
+ multiplicative<balance_t, long> > > > > > >
{
public:
typedef std::map<const commodity_t *, amount_t> amounts_map;
@@ -235,7 +237,9 @@ class balance_pair_t
additive<balance_pair_t,
additive<balance_pair_t, balance_t,
additive<balance_pair_t, amount_t,
- multiplicative<balance_pair_t, amount_t> > > > > > >
+ multiplicative<balance_pair_t, unsigned long,
+ multiplicative<balance_pair_t, long,
+ multiplicative<balance_pair_t, amount_t> > > > > > > > >
{
balance_t quantity;
optional<balance_t> cost;
@@ -298,6 +302,9 @@ public:
bool operator==(const balance_t& bal) const {
return quantity == bal;
}
+ bool operator==(const amount_t& amt) const {
+ return quantity == amt;
+ }
balance_pair_t& operator*=(const amount_t& amt) {
quantity *= amt;
diff --git a/src/value.cc b/src/value.cc
index c4d22f60..6623e1a1 100644
--- a/src/value.cc
+++ b/src/value.cc
@@ -598,7 +598,7 @@ value_t& value_t::operator*=(const value_t& val)
case BALANCE:
switch (val.type) {
case INTEGER:
- as_balance() *= val.to_amount();
+ as_balance() *= val.as_long();
return *this;
case AMOUNT:
if (! val.as_amount().has_commodity()) {
@@ -612,7 +612,7 @@ value_t& value_t::operator*=(const value_t& val)
case BALANCE_PAIR:
switch (val.type) {
case INTEGER:
- as_balance_pair() *= val.to_amount();
+ as_balance_pair() *= val.as_long();
return *this;
case AMOUNT:
if (! val.as_amount().has_commodity()) {
@@ -667,7 +667,7 @@ value_t& value_t::operator/=(const value_t& val)
case BALANCE:
switch (val.type) {
case INTEGER:
- as_balance() /= val.to_amount();
+ as_balance() /= val.as_long();
return *this;
case AMOUNT:
if (! val.as_amount().has_commodity()) {
@@ -681,7 +681,7 @@ value_t& value_t::operator/=(const value_t& val)
case BALANCE_PAIR:
switch (val.type) {
case INTEGER:
- as_balance_pair() /= val.to_amount();
+ as_balance_pair() /= val.as_long();
return *this;
case AMOUNT:
if (! val.as_amount().has_commodity()) {
@@ -727,7 +727,7 @@ bool value_t::operator==(const value_t& val) const
case BALANCE:
return val.as_balance() == to_amount();
case BALANCE_PAIR:
- return val.as_balance_pair() == to_balance();
+ return val.as_balance_pair() == to_amount();
default:
break;
}
@@ -742,7 +742,7 @@ bool value_t::operator==(const value_t& val) const
case BALANCE:
return val.as_balance() == as_amount();
case BALANCE_PAIR:
- return val.as_balance_pair() == to_balance();
+ return val.as_balance_pair() == as_amount();
default:
break;
}
@@ -766,9 +766,9 @@ bool value_t::operator==(const value_t& val) const
case BALANCE_PAIR:
switch (val.type) {
case INTEGER:
- return as_balance_pair() == val.to_balance();
+ return as_balance_pair() == val.to_amount();
case AMOUNT:
- return as_balance_pair() == val.to_balance();
+ return as_balance_pair() == val.as_amount();
case BALANCE:
return as_balance_pair() == val.as_balance();
case BALANCE_PAIR:
diff --git a/tests/numerics/BasicAmount.cc b/tests/numerics/BasicAmount.cc
index a6772b13..6d9e3dc7 100644
--- a/tests/numerics/BasicAmount.cc
+++ b/tests/numerics/BasicAmount.cc
@@ -149,6 +149,13 @@ void BasicAmountTestCase::testComparisons()
CPPUNIT_ASSERT(x3 < x1);
CPPUNIT_ASSERT(x3 < x4);
+ CPPUNIT_ASSERT(x1 < 100L);
+ CPPUNIT_ASSERT(x1 < 100UL);
+ CPPUNIT_ASSERT(x1 < 100.0);
+ CPPUNIT_ASSERT(100L > x1);
+ CPPUNIT_ASSERT(100UL > x1);
+ CPPUNIT_ASSERT(100.0 > x1);
+
CPPUNIT_ASSERT(x0.valid());
CPPUNIT_ASSERT(x1.valid());
CPPUNIT_ASSERT(x2.valid());
diff --git a/tests/python/numerics/BasicAmount.py b/tests/python/numerics/BasicAmount.py
index 9654f6a7..07c1f426 100644
--- a/tests/python/numerics/BasicAmount.py
+++ b/tests/python/numerics/BasicAmount.py
@@ -475,6 +475,11 @@ class BasicAmountTestCase(unittest.TestCase):
self.assertTrue(x3 < x1)
self.assertTrue(x3 < x4)
+ self.assertTrue(x1 < 100)
+ self.assertTrue(x1 < 100.0)
+ self.assertTrue(100 > x1)
+ self.assertTrue(100.0 > x1)
+
self.assertTrue(x0.valid())
self.assertTrue(x1.valid())
self.assertTrue(x2.valid())