Skip to content

Commit

Permalink
Add Python bindings for roundto
Browse files Browse the repository at this point in the history
Expose `roundto` and `in_place_roundto` to `Amount`, `Balance`, and
`Value` Python classes.  They may be handy for debugging.
The methods were added after introducing of bindings and likely
it is a reason why they were missed.

Closes: #2365
  • Loading branch information
maxnikulin authored and jwiegley committed Aug 7, 2024
1 parent c744039 commit 093190e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/py_amount.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ internal precision."))
.def("in_place_round", &amount_t::in_place_round,
return_internal_reference<>())

.def("__round__", &amount_t::roundto)
.def("in_place_roundto", &amount_t::in_place_roundto,
return_internal_reference<>())

.def("truncated", &amount_t::truncated)
.def("in_place_truncate", &amount_t::in_place_truncate,
return_internal_reference<>())
Expand Down
4 changes: 4 additions & 0 deletions src/py_balance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ void export_balance()
.def("in_place_round", &balance_t::in_place_round,
return_internal_reference<>())

.def("__round__", &balance_t::roundto)
.def("in_place_roundto", &balance_t::in_place_roundto,
return_internal_reference<>())

.def("truncated", &balance_t::truncated)
.def("in_place_truncate", &balance_t::in_place_truncate,
return_internal_reference<>())
Expand Down
2 changes: 2 additions & 0 deletions src/py_value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ void export_value()

.def("rounded", &value_t::rounded)
.def("in_place_round", &value_t::in_place_round)
.def("__round__", &value_t::roundto)
.def("in_place_roundto", &value_t::in_place_roundto)
.def("truncated", &value_t::truncated)
.def("in_place_truncate", &value_t::in_place_truncate)
.def("floored", &value_t::floored)
Expand Down

0 comments on commit 093190e

Please sign in to comment.