diff options
-rw-r--r-- | src/amount.h | 14 | ||||
-rw-r--r-- | src/py_amount.cc | 47 | ||||
-rw-r--r-- | tests/numerics/CommodityAmount.cc | 2 |
3 files changed, 26 insertions, 37 deletions
diff --git a/src/amount.h b/src/amount.h index f3109f33..f90a5e4c 100644 --- a/src/amount.h +++ b/src/amount.h @@ -73,7 +73,7 @@ DECLARE_EXCEPTION(amount_error); : public ordered_field_operators<amount_t, ordered_field_operators<amount_t, long, ordered_field_operators<amount_t, unsigned long, - ordered_field_operators<amount_t, double > > > > + ordered_field_operators<amount_t, double> > > > { public: class bigint_t; @@ -137,9 +137,19 @@ public: // comparisons between amounts int compare(const amount_t& amt) const; bool operator==(const amount_t& amt) const; - bool operator<(const amount_t& amt) const { + + template <typename T> + bool operator==(const T& val) const { + return compare(val) == 0; + } + template <typename T> + bool operator<(const T& amt) const { return compare(amt) < 0; } + template <typename T> + bool operator>(const T& amt) const { + return compare(amt) > 0; + } // in-place arithmetic amount_t& operator+=(const amount_t& amt); diff --git a/src/py_amount.cc b/src/py_amount.cc index 49d0c23b..86dac640 100644 --- a/src/py_amount.cc +++ b/src/py_amount.cc @@ -55,21 +55,6 @@ commodity_t * py_find_commodity(const string& symbol) EXC_TRANSLATOR(amount_error) -namespace { - template <typename T> - amount_t operator+(const amount_t& amt, const T val) { - amount_t temp(amt); - temp += amount_t(val); - return temp; - } - template <typename T> - amount_t operator+(const T val, const amount_t& amt) { - amount_t temp(val); - temp += amt; - return temp; - } -} - void export_amount() { scope().attr("AMOUNT_PARSE_NO_MIGRATE") = AMOUNT_PARSE_NO_MIGRATE; @@ -97,80 +82,75 @@ void export_amount() .def(self -= double()) .def(self - self) -#if 0 .def(self - long()) .def(long() - self) .def(self - double()) .def(double() - self) -#endif .def(self *= self) .def(self *= long()) .def(self *= double()) .def(self * self) -#if 0 .def(self * long()) .def(long() * self) .def(self * double()) .def(double() * self) -#endif .def(self /= self) .def(self /= long()) .def(self /= double()) .def(self / self) -#if 0 .def(self / long()) .def(long() / self) .def(self / double()) .def(double() / self) -#endif .def(- self) .def(self < self) -#if 0 .def(self < long()) .def(long() < self) -#endif + .def(self < double()) + .def(double() < self) .def(self <= self) -#if 0 .def(self <= long()) .def(long() <= self) -#endif + .def(self <= double()) + .def(double() <= self) .def(self > self) -#if 0 .def(self > long()) .def(long() > self) -#endif + .def(self > double()) + .def(double() > self) .def(self >= self) -#if 0 .def(self >= long()) .def(long() >= self) -#endif + .def(self >= double()) + .def(double() >= self) .def(self == self) -#if 0 .def(self == long()) .def(long() == self) -#endif + .def(self == double()) + .def(double() == self) .def(self != self) -#if 0 .def(self != long()) .def(long() != self) -#endif + .def(self != double()) + .def(double() != self) .def(! self) .def(self_ns::int_(self)) .def(self_ns::float_(self)) + .def("__abs__", &amount_t::abs) .def("__str__", &amount_t::to_string) .def("__repr__", &amount_t::to_fullstring) @@ -195,7 +175,6 @@ void export_amount() .def("exact", &amount_t::exact) .staticmethod("exact") - .def("__abs__", &amount_t::abs) .def("compare", &amount_t::compare) .def("date", &amount_t::date) .def("negate", &amount_t::negate) diff --git a/tests/numerics/CommodityAmount.cc b/tests/numerics/CommodityAmount.cc index 2f676697..ffedbdac 100644 --- a/tests/numerics/CommodityAmount.cc +++ b/tests/numerics/CommodityAmount.cc @@ -183,7 +183,7 @@ void CommodityAmountTestCase::testEquality() amount_t x9 = "123.45€"; amount_t x10 = "-123.45€"; - assertTrue(x0.null()); + assertTrue(x0.is_null()); assertTrue(x0.zero()); assertTrue(x0.realzero()); assertTrue(x0.sign() == 0); |