diff options
author | John Wiegley <johnw@newartisans.com> | 2009-01-31 05:00:49 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-01-31 05:00:49 -0400 |
commit | ec6a3e80814f799d7fc0b416499bea7ac0a8cb5e (patch) | |
tree | a7447c3994926749601ab9a178da7b07010dc22c | |
parent | cce65b8dd2f9cb22a20acb891a8a83cdfce90c7b (diff) | |
download | fork-ledger-ec6a3e80814f799d7fc0b416499bea7ac0a8cb5e.tar.gz fork-ledger-ec6a3e80814f799d7fc0b416499bea7ac0a8cb5e.tar.bz2 fork-ledger-ec6a3e80814f799d7fc0b416499bea7ac0a8cb5e.zip |
Made amount_t::is_zero() slightly more efficient.
-rw-r--r-- | src/amount.cc | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/amount.cc b/src/amount.cc index bc8b0b6f..36539232 100644 --- a/src/amount.cc +++ b/src/amount.cc @@ -625,7 +625,18 @@ bool amount_t::is_zero() const if (has_commodity()) { if (keep_precision() || quantity->prec <= commodity().precision()) { return is_realzero(); - } else { + } + else if (is_realzero()) { + return true; + } + else if (mpz_cmp(mpq_numref(MP(quantity)), + mpq_denref(MP(quantity))) > 0) { + DEBUG("amount.is_zero", "Numerator is larger than the denominator"); + return false; + } + else { + DEBUG("amount.is_zero", "We have to print the number to check for zero"); + std::ostringstream out; stream_out_mpq(out, MP(quantity), commodity().precision()); |