summaryrefslogtreecommitdiff
path: root/src/value.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-10-27 08:32:42 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-10-27 08:32:42 -0400
commit027c255a4fa8dd8ab9cf433e6f9491ce7e5658aa (patch)
treeeb5ab88d751ec975681ae748d441f44d4799bd63 /src/value.cc
parent7fae606d622d8cd463ce5f81f5d7872a4fdebc60 (diff)
parent3ea7fbd5f6db4d362af79953b23bacc904909cff (diff)
downloadledger-027c255a4fa8dd8ab9cf433e6f9491ce7e5658aa.tar.gz
ledger-027c255a4fa8dd8ab9cf433e6f9491ce7e5658aa.tar.bz2
ledger-027c255a4fa8dd8ab9cf433e6f9491ce7e5658aa.zip
Merge branch 'next'
Diffstat (limited to 'src/value.cc')
-rw-r--r--src/value.cc40
1 files changed, 30 insertions, 10 deletions
diff --git a/src/value.cc b/src/value.cc
index 6ce46f5c..cd4c4aa1 100644
--- a/src/value.cc
+++ b/src/value.cc
@@ -254,7 +254,7 @@ value_t::sequence_t value_t::to_sequence() const
void value_t::in_place_simplify()
{
#if defined(DEBUG_ON)
- LOGGER("amounts.values.simplify");
+ LOGGER("value.simplify");
#endif
if (is_realzero()) {
@@ -263,11 +263,11 @@ void value_t::in_place_simplify()
return;
}
- if (is_balance() && as_balance().amounts.size() == 1) {
+ if (is_balance() && as_balance().single_amount()) {
DEBUG_("Reducing balance to amount");
- DEBUG("ledger.value.reduce", "as a balance it looks like: " << *this);
+ DEBUG_("as a balance it looks like: " << *this);
in_place_cast(AMOUNT);
- DEBUG("ledger.value.reduce", "as an amount it looks like: " << *this);
+ DEBUG_("as an amount it looks like: " << *this);
}
#ifdef REDUCE_TO_INTEGER // this is off by default
@@ -585,10 +585,11 @@ value_t& value_t::operator*=(const value_t& val)
as_amount_lval() *= val.as_long();
return *this;
case AMOUNT:
- if (as_amount().commodity() == val.as_amount().commodity() ||
- ! as_amount().has_commodity() ||
- ! val.as_amount().has_commodity()) {
- as_amount_lval() *= val.as_amount();
+ as_amount_lval() *= val.as_amount();
+ return *this;
+ case BALANCE:
+ if (val.as_balance().single_amount()) {
+ as_amount_lval() *= val.simplified().as_amount();
return *this;
}
break;
@@ -603,7 +604,12 @@ value_t& value_t::operator*=(const value_t& val)
as_balance_lval() *= val.as_long();
return *this;
case AMOUNT:
- if (! val.as_amount().has_commodity()) {
+ if (as_balance().single_amount()) {
+ in_place_simplify();
+ as_amount_lval() *= val.as_amount();
+ return *this;
+ }
+ else if (! val.as_amount().has_commodity()) {
as_balance_lval() *= val.as_amount();
return *this;
}
@@ -617,6 +623,9 @@ value_t& value_t::operator*=(const value_t& val)
break;
}
+ DEBUG("value.multiply.error", "Left: " << *this);
+ DEBUG("value.multiply.error", "Right: " << val);
+
throw_(value_error, _("Cannot multiply %1 with %2") << label() << val.label());
return *this;
@@ -647,6 +656,12 @@ value_t& value_t::operator/=(const value_t& val)
case AMOUNT:
as_amount_lval() /= val.as_amount();
return *this;
+ case BALANCE:
+ if (val.as_balance().single_amount()) {
+ as_amount_lval() /= val.simplified().as_amount();
+ return *this;
+ }
+ break;
default:
break;
}
@@ -658,7 +673,12 @@ value_t& value_t::operator/=(const value_t& val)
as_balance_lval() /= val.as_long();
return *this;
case AMOUNT:
- if (! val.as_amount().has_commodity()) {
+ if (as_balance().single_amount()) {
+ in_place_simplify();
+ as_amount_lval() /= val.as_amount();
+ return *this;
+ }
+ else if (! val.as_amount().has_commodity()) {
as_balance_lval() /= val.as_amount();
return *this;
}