Completed commodity math tests.
This commit is contained in:
parent
269a7c6f3b
commit
d8296ddc57
1 changed files with 11 additions and 1 deletions
12
amount.cc
12
amount.cc
|
|
@ -635,11 +635,21 @@ amount_t& amount_t::operator/=(const amount_t& amt)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (has_commodity() && amt.has_commodity() &&
|
if (has_commodity() && amt.has_commodity() &&
|
||||||
commodity() != amt.commodity())
|
commodity() != amt.commodity()) {
|
||||||
throw new amount_error
|
throw new amount_error
|
||||||
(std::string("Dividing amounts with different commodities: ") +
|
(std::string("Dividing amounts with different commodities: ") +
|
||||||
(has_commodity() ? commodity_->qualified_symbol : "NONE") + " != " +
|
(has_commodity() ? commodity_->qualified_symbol : "NONE") + " != " +
|
||||||
(amt.has_commodity() ? amt.commodity_->qualified_symbol : "NONE"));
|
(amt.has_commodity() ? amt.commodity_->qualified_symbol : "NONE"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! amt.quantity || ! amt) {
|
||||||
|
throw new amount_error("Divide by zero");
|
||||||
|
}
|
||||||
|
else if (! quantity) {
|
||||||
|
*this = amt;
|
||||||
|
*this = *this - *this; // preserve the foreign commodity
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
|
||||||
_dup();
|
_dup();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue