summaryrefslogtreecommitdiff
path: root/src/amount.cc
diff options
context:
space:
mode:
authorCraig Earls <enderw88@gmail.com>2012-10-25 22:28:26 -0700
committerCraig Earls <enderw88@gmail.com>2012-10-25 22:28:26 -0700
commitb044a74bd34afdc27baf6241fe398690ff5e043a (patch)
tree6cf2168e51611a86e04d834b2a507322a8a8fe04 /src/amount.cc
parent4b261f99bc56853b3468a8a1bb5b4af39ed67af5 (diff)
downloadfork-ledger-b044a74bd34afdc27baf6241fe398690ff5e043a.tar.gz
fork-ledger-b044a74bd34afdc27baf6241fe398690ff5e043a.tar.bz2
fork-ledger-b044a74bd34afdc27baf6241fe398690ff5e043a.zip
Bug 634 and 488, Corrected behavior of floor, and added ceiling
This is only a partial fix for 634, since rounding is not fixed.
Diffstat (limited to 'src/amount.cc')
-rw-r--r--src/amount.cc23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/amount.cc b/src/amount.cc
index 6ecb3558..4e658212 100644
--- a/src/amount.cc
+++ b/src/amount.cc
@@ -670,10 +670,27 @@ void amount_t::in_place_floor()
_dup();
- std::ostringstream out;
- stream_out_mpq(out, MP(quantity), precision_t(0), -1, GMP_RNDZ);
+ mpz_t quot;
+ mpz_init(quot);
+ mpz_fdiv_q(quot, mpq_numref(MP(quantity)), mpq_denref(MP(quantity)));
+ mpq_clear(MP(quantity));
+ mpq_init(MP(quantity));
+ mpq_set_num(MP(quantity), quot);
+}
+
+void amount_t::in_place_ceiling()
+{
+ if (! quantity)
+ throw_(amount_error, _("Cannot ceiling an uninitialized amount"));
- mpq_set_str(MP(quantity), out.str().c_str(), 10);
+ _dup();
+
+ mpz_t quot;
+ mpz_init(quot);
+ mpz_cdiv_q(quot, mpq_numref(MP(quantity)), mpq_denref(MP(quantity)));
+ mpq_clear(MP(quantity));
+ mpq_init(MP(quantity));
+ mpq_set_num(MP(quantity), quot);
}
void amount_t::in_place_unround()