amount_t::in_place_* now returns void. Added value_t::unreduce.
This commit is contained in:
parent
cb0faac58d
commit
b662509ee9
4 changed files with 32 additions and 9 deletions
|
|
@ -434,7 +434,7 @@ amount_t::precision_t amount_t::display_precision() const
|
||||||
return quantity->prec;
|
return quantity->prec;
|
||||||
}
|
}
|
||||||
|
|
||||||
amount_t& amount_t::in_place_negate()
|
void amount_t::in_place_negate()
|
||||||
{
|
{
|
||||||
if (quantity) {
|
if (quantity) {
|
||||||
_dup();
|
_dup();
|
||||||
|
|
@ -442,7 +442,6 @@ amount_t& amount_t::in_place_negate()
|
||||||
} else {
|
} else {
|
||||||
throw_(amount_error, "Cannot negate an uninitialized amount");
|
throw_(amount_error, "Cannot negate an uninitialized amount");
|
||||||
}
|
}
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
amount_t amount_t::inverted() const
|
amount_t amount_t::inverted() const
|
||||||
|
|
@ -485,7 +484,7 @@ amount_t amount_t::unrounded() const
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
amount_t& amount_t::in_place_reduce()
|
void amount_t::in_place_reduce()
|
||||||
{
|
{
|
||||||
if (! quantity)
|
if (! quantity)
|
||||||
throw_(amount_error, "Cannot reduce an uninitialized amount");
|
throw_(amount_error, "Cannot reduce an uninitialized amount");
|
||||||
|
|
@ -494,10 +493,9 @@ amount_t& amount_t::in_place_reduce()
|
||||||
*this *= commodity().smaller()->number();
|
*this *= commodity().smaller()->number();
|
||||||
commodity_ = commodity().smaller()->commodity_;
|
commodity_ = commodity().smaller()->commodity_;
|
||||||
}
|
}
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
amount_t& amount_t::in_place_unreduce()
|
void amount_t::in_place_unreduce()
|
||||||
{
|
{
|
||||||
if (! quantity)
|
if (! quantity)
|
||||||
throw_(amount_error, "Cannot unreduce an uninitialized amount");
|
throw_(amount_error, "Cannot unreduce an uninitialized amount");
|
||||||
|
|
@ -508,7 +506,6 @@ amount_t& amount_t::in_place_unreduce()
|
||||||
if (abs() < amount_t(1L))
|
if (abs() < amount_t(1L))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
optional<amount_t> amount_t::value(const optional<datetime_t>& moment,
|
optional<amount_t> amount_t::value(const optional<datetime_t>& moment,
|
||||||
|
|
|
||||||
|
|
@ -296,7 +296,7 @@ public:
|
||||||
temp.in_place_negate();
|
temp.in_place_negate();
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
amount_t& in_place_negate();
|
void in_place_negate();
|
||||||
|
|
||||||
amount_t operator-() const {
|
amount_t operator-() const {
|
||||||
return negate();
|
return negate();
|
||||||
|
|
@ -335,7 +335,7 @@ public:
|
||||||
temp.in_place_reduce();
|
temp.in_place_reduce();
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
amount_t& in_place_reduce();
|
void in_place_reduce();
|
||||||
|
|
||||||
/** unreduce(), if used with a "scaling commodity", yields the most
|
/** unreduce(), if used with a "scaling commodity", yields the most
|
||||||
compact form greater than one. That is, \c 3599s will unreduce to
|
compact form greater than one. That is, \c 3599s will unreduce to
|
||||||
|
|
@ -346,7 +346,7 @@ public:
|
||||||
temp.in_place_unreduce();
|
temp.in_place_unreduce();
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
amount_t& in_place_unreduce();
|
void in_place_unreduce();
|
||||||
|
|
||||||
/** Returns the historical value for an amount -- the default moment
|
/** Returns the historical value for an amount -- the default moment
|
||||||
returns the most recently known price -- based on the price history
|
returns the most recently known price -- based on the price history
|
||||||
|
|
|
||||||
19
src/value.cc
19
src/value.cc
|
|
@ -1404,6 +1404,25 @@ void value_t::in_place_reduce()
|
||||||
//throw_(value_error, "Cannot reduce " << label());
|
//throw_(value_error, "Cannot reduce " << label());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void value_t::in_place_unreduce()
|
||||||
|
{
|
||||||
|
switch (type()) {
|
||||||
|
case AMOUNT:
|
||||||
|
as_amount_lval().in_place_unreduce();
|
||||||
|
return;
|
||||||
|
case BALANCE:
|
||||||
|
as_balance_lval().in_place_unreduce();
|
||||||
|
return;
|
||||||
|
case BALANCE_PAIR:
|
||||||
|
as_balance_pair_lval().in_place_unreduce();
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//throw_(value_error, "Cannot reduce " << label());
|
||||||
|
}
|
||||||
|
|
||||||
value_t value_t::abs() const
|
value_t value_t::abs() const
|
||||||
{
|
{
|
||||||
switch (type()) {
|
switch (type()) {
|
||||||
|
|
|
||||||
|
|
@ -421,6 +421,13 @@ public:
|
||||||
}
|
}
|
||||||
void in_place_reduce(); // exists for efficiency's sake
|
void in_place_reduce(); // exists for efficiency's sake
|
||||||
|
|
||||||
|
value_t unreduce() const {
|
||||||
|
value_t temp(*this);
|
||||||
|
temp.in_place_unreduce();
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
void in_place_unreduce(); // exists for efficiency's sake
|
||||||
|
|
||||||
// Return the "market value" of a given value at a specific time.
|
// Return the "market value" of a given value at a specific time.
|
||||||
value_t value(const optional<datetime_t>& moment = none,
|
value_t value(const optional<datetime_t>& moment = none,
|
||||||
const optional<commodity_t&>& in_terms_of = none) const;
|
const optional<commodity_t&>& in_terms_of = none) const;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue