From d8296ddc57376ab76b2a4a2c99ef3d0e884b33b8 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 17 Apr 2007 09:11:33 +0000 Subject: Completed commodity math tests. --- amount.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/amount.cc b/amount.cc index 73bc6718..4e0e2185 100644 --- a/amount.cc +++ b/amount.cc @@ -635,11 +635,21 @@ amount_t& amount_t::operator/=(const amount_t& amt) } if (has_commodity() && amt.has_commodity() && - commodity() != amt.commodity()) + commodity() != amt.commodity()) { throw new amount_error (std::string("Dividing amounts with different commodities: ") + (has_commodity() ? 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(); -- cgit v1.2.3