diff --git a/src/amount.cc b/src/amount.cc index 5958962d..32dbf856 100644 --- a/src/amount.cc +++ b/src/amount.cc @@ -115,11 +115,15 @@ uint_fast32_t amount_t::sizeof_bigint_t() return sizeof(bigint_t); } +amount_t * one = NULL; + void amount_t::initialize() { mpz_init(temp); mpz_init(divisor); + one = new amount_t(amount_t(1L).unround()); + if (! current_pool) current_pool = new commodity_pool_t; @@ -140,6 +144,8 @@ void amount_t::shutdown() mpz_clear(temp); mpz_clear(divisor); + delete one; + if (current_pool) { checked_delete(current_pool); current_pool = NULL; @@ -661,9 +667,9 @@ optional amount_t::value(const optional& moment) const { if (quantity) { // jww (2008-09-21): 'none' is not the right argument here. - optional amt(commodity().find_price(none, moment)); - if (amt) - return (*amt * number()).round(); + optional point(commodity().find_price(none, moment)); + if (point) + return (point->price * number()).round(); } else { throw_(amount_error, "Cannot determine value of an uninitialized amount"); } diff --git a/src/amount.h b/src/amount.h index 0a9038f2..0667d9c3 100644 --- a/src/amount.h +++ b/src/amount.h @@ -722,6 +722,8 @@ public: bool valid() const; }; +extern amount_t * one; + inline amount_t amount_t::exact(const string& value) { amount_t temp; temp.parse(value, AMOUNT_PARSE_NO_MIGRATE);