Removed the special "one" variable, and added amount_t::inverted().
This commit is contained in:
parent
e9ff5caa13
commit
5a44784817
3 changed files with 15 additions and 9 deletions
|
|
@ -100,8 +100,6 @@ uint_fast32_t amount_t::sizeof_bigint_t()
|
||||||
return sizeof(bigint_t);
|
return sizeof(bigint_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
amount_t * one = NULL;
|
|
||||||
|
|
||||||
void amount_t::initialize()
|
void amount_t::initialize()
|
||||||
{
|
{
|
||||||
mpz_init(temp);
|
mpz_init(temp);
|
||||||
|
|
@ -109,8 +107,6 @@ void amount_t::initialize()
|
||||||
mpfr_init(tempf);
|
mpfr_init(tempf);
|
||||||
mpfr_init(tempfb);
|
mpfr_init(tempfb);
|
||||||
|
|
||||||
one = new amount_t(amount_t(1L).unrounded());
|
|
||||||
|
|
||||||
if (! current_pool)
|
if (! current_pool)
|
||||||
current_pool = new commodity_pool_t;
|
current_pool = new commodity_pool_t;
|
||||||
|
|
||||||
|
|
@ -133,8 +129,6 @@ void amount_t::shutdown()
|
||||||
mpfr_clear(tempf);
|
mpfr_clear(tempf);
|
||||||
mpfr_clear(tempfb);
|
mpfr_clear(tempfb);
|
||||||
|
|
||||||
checked_delete(one);
|
|
||||||
|
|
||||||
if (current_pool) {
|
if (current_pool) {
|
||||||
checked_delete(current_pool);
|
checked_delete(current_pool);
|
||||||
current_pool = NULL;
|
current_pool = NULL;
|
||||||
|
|
@ -455,6 +449,18 @@ amount_t& amount_t::in_place_negate()
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
amount_t amount_t::inverted() const
|
||||||
|
{
|
||||||
|
if (! quantity)
|
||||||
|
throw_(amount_error, "Cannot invert an uninitialized amount");
|
||||||
|
|
||||||
|
amount_t t(*this);
|
||||||
|
t._dup();
|
||||||
|
mpq_inv(MP(t.quantity), MP(t.quantity));
|
||||||
|
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
amount_t amount_t::rounded() const
|
amount_t amount_t::rounded() const
|
||||||
{
|
{
|
||||||
if (! quantity)
|
if (! quantity)
|
||||||
|
|
|
||||||
|
|
@ -346,6 +346,8 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
amount_t inverted() const;
|
||||||
|
|
||||||
/** Yields an amount whose display precision when output is truncated
|
/** Yields an amount whose display precision when output is truncated
|
||||||
to the display precision of its commodity. This is normally the
|
to the display precision of its commodity. This is normally the
|
||||||
default state of an amount, but if one has become unrounded, this
|
default state of an amount, but if one has become unrounded, this
|
||||||
|
|
@ -740,8 +742,6 @@ public:
|
||||||
/*@}*/
|
/*@}*/
|
||||||
};
|
};
|
||||||
|
|
||||||
extern amount_t * one;
|
|
||||||
|
|
||||||
inline amount_t amount_t::exact(const string& value) {
|
inline amount_t amount_t::exact(const string& value) {
|
||||||
amount_t temp;
|
amount_t temp;
|
||||||
temp.parse(value, PARSE_NO_MIGRATE);
|
temp.parse(value, PARSE_NO_MIGRATE);
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ void commodity_t::base_t::history_t::add_price(const commodity_t& source,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reflexive && ! price.commodity().has_flags(COMMODITY_NOMARKET)) {
|
if (reflexive && ! price.commodity().has_flags(COMMODITY_NOMARKET)) {
|
||||||
amount_t inverse(*one / price);
|
amount_t inverse = price.inverted();
|
||||||
inverse.set_commodity(const_cast<commodity_t&>(source));
|
inverse.set_commodity(const_cast<commodity_t&>(source));
|
||||||
price.commodity().add_price(date, inverse, false);
|
price.commodity().add_price(date, inverse, false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue