summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/balance.h3
-rw-r--r--src/value.cc28
2 files changed, 28 insertions, 3 deletions
diff --git a/src/balance.h b/src/balance.h
index 765c46dd..fe8afe2b 100644
--- a/src/balance.h
+++ b/src/balance.h
@@ -417,6 +417,9 @@ public:
bool is_empty() const {
return amounts.size() == 0;
}
+ bool single_amount() const {
+ return amounts.size() == 1;
+ }
/**
* Conversion methods. A balance can be converted to an amount, but
diff --git a/src/value.cc b/src/value.cc
index 5c5e09cb..cd4c4aa1 100644
--- a/src/value.cc
+++ b/src/value.cc
@@ -263,7 +263,7 @@ 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_("as a balance it looks like: " << *this);
in_place_cast(AMOUNT);
@@ -587,6 +587,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;
}
@@ -598,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;
}
@@ -645,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;
}
@@ -656,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;
}