From e9ff5caa13e2d60681010dbedcf56459ee7521a4 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 31 Jan 2009 04:25:05 -0400 Subject: Rationals based math is now passing the unit tests. --- python/py_amount.cc | 73 ++++++++++++++++++++++++++++------------------------- python/py_value.cc | 7 ++--- 2 files changed, 40 insertions(+), 40 deletions(-) (limited to 'python') diff --git a/python/py_amount.cc b/python/py_amount.cc index b57687f2..2528f779 100644 --- a/python/py_amount.cc +++ b/python/py_amount.cc @@ -41,29 +41,6 @@ namespace ledger { using namespace boost::python; -#ifdef INTEGER_MATH -amount_t py_round_0(const amount_t& amount) { - return amount.round(); -} -amount_t py_round_1(const amount_t& amount, amount_t::precision_t prec) { - return amount.round(prec); -} -#endif - -double py_to_double_0(amount_t& amount) { - return amount.to_double(); -} -double py_to_double_1(amount_t& amount, bool no_check) { - return amount.to_double(no_check); -} - -long py_to_long_0(amount_t& amount) { - return amount.to_long(); -} -long py_to_long_1(amount_t& amount, bool no_check) { - return amount.to_long(no_check); -} - boost::optional py_value_0(const amount_t& amount) { return amount.value(); } @@ -169,7 +146,9 @@ void export_amount() make_getter(&amount_t::stream_fullstrings), make_setter(&amount_t::stream_fullstrings)) +#if 0 .def(init()) +#endif .def(init()) .def(init()) @@ -185,80 +164,108 @@ internal precision.") .def(self == self) .def(self == long()) .def(long() == self) +#if 0 .def(self == double()) .def(double() == self) +#endif .def(self != self) .def(self != long()) .def(long() != self) +#if 0 .def(self != double()) .def(double() != self) +#endif .def(! self) .def(self < self) .def(self < long()) .def(long() < self) +#if 0 .def(self < double()) .def(double() < self) +#endif .def(self <= self) .def(self <= long()) .def(long() <= self) +#if 0 .def(self <= double()) .def(double() <= self) +#endif .def(self > self) .def(self > long()) .def(long() > self) +#if 0 .def(self > double()) .def(double() > self) +#endif .def(self >= self) .def(self >= long()) .def(long() >= self) +#if 0 .def(self >= double()) .def(double() >= self) +#endif .def(self += self) .def(self += long()) +#if 0 .def(self += double()) +#endif .def(self + self) .def(self + long()) .def(long() + self) +#if 0 .def(self + double()) .def(double() + self) +#endif .def(self -= self) .def(self -= long()) +#if 0 .def(self -= double()) +#endif .def(self - self) .def(self - long()) .def(long() - self) +#if 0 .def(self - double()) .def(double() - self) +#endif .def(self *= self) .def(self *= long()) +#if 0 .def(self *= double()) +#endif .def(self * self) .def(self * long()) .def(long() * self) +#if 0 .def(self * double()) .def(double() * self) +#endif .def(self /= self) .def(self /= long()) +#if 0 .def(self /= double()) +#endif .def(self / self) .def(self / long()) .def(long() / self) +#if 0 .def(self / double()) .def(double() / self) +#endif .def("precision", &amount_t::precision) @@ -270,11 +277,8 @@ internal precision.") .def("abs", &amount_t::abs) .def("__abs__", &amount_t::abs) -#ifdef INTEGER_MATH - .def("round", py_round_0) - .def("round", py_round_1) -#endif - .def("unround", &amount_t::unround) + .def("rounded", &amount_t::rounded) + .def("unrounded", &amount_t::unrounded) .def("reduce", &amount_t::reduce) .def("in_place_reduce", &amount_t::in_place_reduce, @@ -295,18 +299,15 @@ internal precision.") .def("is_realzero", &amount_t::is_realzero) .def("is_null", &amount_t::is_null) - .def("to_double", py_to_double_0) - .def("to_double", py_to_double_1) - .def("__float__", py_to_double_0) - .def("to_long", py_to_long_0) - .def("to_long", py_to_long_1) - .def("__int__", py_to_long_0) + .def("to_double", &amount_t::to_double) + .def("__float__", &amount_t::to_double) + .def("to_long", &amount_t::to_long) + .def("__int__", &amount_t::to_long) .def("to_string", &amount_t::to_string) .def("__str__", &amount_t::to_string) .def("to_fullstring", &amount_t::to_fullstring) .def("__repr__", &amount_t::to_fullstring) - .def("fits_in_double", &amount_t::fits_in_double) .def("fits_in_long", &amount_t::fits_in_long) .def("quantity_string", &amount_t::quantity_string) @@ -359,7 +360,9 @@ internal precision.") register_optional_to_python(); +#if 0 implicitly_convertible(); +#endif implicitly_convertible(); implicitly_convertible(); diff --git a/python/py_value.cc b/python/py_value.cc index 48cd0feb..4556c31e 100644 --- a/python/py_value.cc +++ b/python/py_value.cc @@ -195,11 +195,8 @@ void export_value() .def("abs", &value_t::abs) .def("__abs__", &value_t::abs) -#ifdef INTEGER_MATH - .def("round", &value_t::round) - .def("in_place_round", &value_t::in_place_round) -#endif - .def("unround", &value_t::unround) + .def("rounded", &value_t::rounded) + .def("unrounded", &value_t::unrounded) .def("reduce", &value_t::reduce) .def("in_place_reduce", &value_t::in_place_reduce) -- cgit v1.2.3