Corrected a bad rounding bug that affecting very small commodity entries.

This commit is contained in:
John Wiegley 2008-07-28 02:04:29 -04:00
parent c93175183e
commit dede5e71bf
2 changed files with 5 additions and 6 deletions

View file

@ -548,13 +548,11 @@ amount_t::operator bool() const
if (! quantity) if (! quantity)
return false; return false;
if (quantity->prec <= commodity().precision()) { if (quantity->prec <= commodity().precision() ||
(quantity->flags & BIGINT_KEEP_PREC)) {
return mpz_sgn(MPZ(quantity)) != 0; return mpz_sgn(MPZ(quantity)) != 0;
} else { } else {
mpz_set(temp, MPZ(quantity)); mpz_set(temp, MPZ(quantity));
if (quantity->flags & BIGINT_KEEP_PREC)
mpz_ui_pow_ui(divisor, 10, quantity->prec);
else
mpz_ui_pow_ui(divisor, 10, quantity->prec - commodity().precision()); mpz_ui_pow_ui(divisor, 10, quantity->prec - commodity().precision());
mpz_tdiv_q(temp, temp, divisor); mpz_tdiv_q(temp, temp, divisor);
bool zero = mpz_sgn(temp) == 0; bool zero = mpz_sgn(temp) == 0;

View file

@ -259,13 +259,14 @@ bool entry_base_t::finalize()
} }
} }
balance.round();
if (balance) { if (balance) {
error * err = error * err =
new balance_error("Entry does not balance", new balance_error("Entry does not balance",
new entry_context(*this, "While balancing entry:")); new entry_context(*this, "While balancing entry:"));
DEBUG_PRINT("ledger.journal.unbalanced_remainder", DEBUG_PRINT("ledger.journal.unbalanced_remainder",
"balance = " << balance); "balance = " << balance);
balance.round();
err->context.push_front err->context.push_front
(new value_context(balance, "Unbalanced remainder is:")); (new value_context(balance, "Unbalanced remainder is:"));
throw err; throw err;