diff options
-rw-r--r-- | src/amount.cc | 20 | ||||
-rw-r--r-- | src/commodity.cc | 13 | ||||
-rw-r--r-- | src/compare.cc | 3 | ||||
-rw-r--r-- | src/textual.cc | 10 |
4 files changed, 25 insertions, 21 deletions
diff --git a/src/amount.cc b/src/amount.cc index dde1f96c..6d94cee1 100644 --- a/src/amount.cc +++ b/src/amount.cc @@ -501,11 +501,21 @@ void amount_t::in_place_unreduce() if (! quantity) throw_(amount_error, "Cannot unreduce an uninitialized amount"); - while (commodity_ && commodity().larger()) { - *this /= commodity().larger()->number(); - commodity_ = commodity().larger()->commodity_; - if (abs() < amount_t(1L)) + amount_t temp = *this; + commodity_t * comm = commodity_; + bool shifted = false; + + while (comm && comm->larger()) { + temp /= comm->larger()->number(); + if (temp.abs() < amount_t(1L)) break; + shifted = true; + comm = comm->larger()->commodity_; + } + + if (shifted) { + *this = temp; + commodity_ = comm; } } @@ -718,7 +728,7 @@ void amount_t::annotate(const annotation_t& details) assert(false); #endif - DEBUG("amounts.commodities", " Annotated amount is " << *this); + DEBUG("amounts.commodities", "Annotated amount is " << *this); } bool amount_t::is_annotated() const diff --git a/src/commodity.cc b/src/commodity.cc index 5832e2b8..c65ad0a4 100644 --- a/src/commodity.cc +++ b/src/commodity.cc @@ -638,7 +638,8 @@ void annotation_t::parse(std::istream& in) amount_t temp; temp.parse(buf, amount_t::PARSE_NO_MIGRATE); - temp.in_place_reduce(); + + DEBUG("commodity.annotations", "Parsed annotation price: " << temp); // Since this price will maintain its own precision, make sure // it is at least as large as the base commodity, since the user @@ -683,8 +684,12 @@ void annotation_t::parse(std::istream& in) } } while (true); - DEBUG("amounts.commodities", - "Parsed commodity annotations: " << std::endl << *this); +#if defined(DEBUG_ON) + if (SHOW_DEBUG("amounts.commodities") && *this) { + DEBUG("amounts.commodities", + "Parsed commodity annotations: " << std::endl << *this); + } +#endif } bool annotated_commodity_t::operator==(const commodity_t& comm) const @@ -775,9 +780,7 @@ bool compare_amount_commodities::operator()(const amount_t * left, if (aleftcomm.details.price && arightcomm.details.price) { amount_t leftprice(*aleftcomm.details.price); - leftprice.in_place_reduce(); amount_t rightprice(*arightcomm.details.price); - rightprice.in_place_reduce(); if (leftprice.commodity() == rightprice.commodity()) { return (leftprice - rightprice).sign() < 0; diff --git a/src/compare.cc b/src/compare.cc index d716bcda..e8d96c62 100644 --- a/src/compare.cc +++ b/src/compare.cc @@ -53,8 +53,7 @@ namespace { sort_values.push_back(sort_value_t()); sort_values.back().inverted = inverted; - sort_values.back().value = - expr_t(node).calc(*scope).reduced().simplified(); + sort_values.back().value = expr_t(node).calc(*scope).simplified(); if (sort_values.back().value.is_null()) throw_(calc_error, diff --git a/src/textual.cc b/src/textual.cc index bedfc21a..8012dedf 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -828,10 +828,9 @@ post_t * instance_t::parse_post(char * line, ptristream stream(next, len - beg); if (*next != '(') // indicates a value expression - post->amount.parse(stream, amount_t::PARSE_NO_REDUCE); + post->amount.parse(stream); else parse_amount_expr(session_scope, stream, post->amount, post.get(), - static_cast<uint_least8_t>(expr_t::PARSE_NO_REDUCE) | static_cast<uint_least8_t>(expr_t::PARSE_NO_ASSIGN)); if (! post->amount.is_null() && honor_strict && strict && @@ -843,13 +842,6 @@ post_t * instance_t::parse_post(char * line, << "'" << std::endl; post->amount.commodity().add_flags(COMMODITY_KNOWN); } -#if 0 - // jww (2009-02-12): This isn't quite working yet; it causes cost computes - // to skyrocket, since the per-unit price isn't also being reduced by the - // same factor. - if (! post->amount.is_null()) - post->amount.in_place_reduce(); -#endif DEBUG("textual.parse", "line " << linenum << ": " << "post amount = " << post->amount); |