summaryrefslogtreecommitdiff
path: root/src/amount.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-01-19 16:24:06 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-01-19 16:24:06 -0400
commit60f9748da1a316943229087860b74ed48f9bc657 (patch)
treefa0f843c733856f5130607d4000a66ae05c52514 /src/amount.cc
parent0ec53e4a6cfa37f4de3e2e696bb1e8aeabfc8386 (diff)
downloadfork-ledger-60f9748da1a316943229087860b74ed48f9bc657.tar.gz
fork-ledger-60f9748da1a316943229087860b74ed48f9bc657.tar.bz2
fork-ledger-60f9748da1a316943229087860b74ed48f9bc657.zip
Create an unrounded global amount variable 'one' for creating inverse price
mappings.
Diffstat (limited to 'src/amount.cc')
-rw-r--r--src/amount.cc12
1 files changed, 9 insertions, 3 deletions
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> amount_t::value(const optional<datetime_t>& moment) const
{
if (quantity) {
// jww (2008-09-21): 'none' is not the right argument here.
- optional<amount_t> amt(commodity().find_price(none, moment));
- if (amt)
- return (*amt * number()).round();
+ optional<price_point_t> point(commodity().find_price(none, moment));
+ if (point)
+ return (point->price * number()).round();
} else {
throw_(amount_error, "Cannot determine value of an uninitialized amount");
}