diff options
author | John Wiegley <johnw@newartisans.com> | 2007-05-21 20:45:46 +0000 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2008-04-13 03:39:07 -0400 |
commit | ce4ed2b25cd4ead67a52cf42e05c7091aff9b3c7 (patch) | |
tree | 6c5f1667b5bfc908e903f1bc204c7f18d8bd419b /src/numerics/amount.cc | |
parent | d23ed020abf494a046b499cdce1c0957cd5b4783 (diff) | |
download | fork-ledger-ce4ed2b25cd4ead67a52cf42e05c7091aff9b3c7.tar.gz fork-ledger-ce4ed2b25cd4ead67a52cf42e05c7091aff9b3c7.tar.bz2 fork-ledger-ce4ed2b25cd4ead67a52cf42e05c7091aff9b3c7.zip |
Getting things to compile again.
Diffstat (limited to 'src/numerics/amount.cc')
-rw-r--r-- | src/numerics/amount.cc | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/src/numerics/amount.cc b/src/numerics/amount.cc index 79dd663c..7bc2841c 100644 --- a/src/numerics/amount.cc +++ b/src/numerics/amount.cc @@ -586,35 +586,40 @@ amount_t& amount_t::in_place_negate() return *this; } -amount_t amount_t::round(const optional<precision_t>& prec) const +amount_t amount_t::round() const { if (! quantity) throw_(amount_error, "Cannot round an uninitialized amount"); - if (! prec) { - if (! has_commodity()) - return *this; - return round(commodity().precision()); - } else { - amount_t t(*this); - - if (quantity->prec <= *prec) { - if (quantity && quantity->has_flags(BIGINT_KEEP_PREC)) { - t._dup(); - t.quantity->drop_flags(BIGINT_KEEP_PREC); - } - return t; - } + if (! has_commodity()) + return *this; - t._dup(); + return round(commodity().precision()); +} - mpz_round(MPZ(t.quantity), MPZ(t.quantity), t.quantity->prec, *prec); +amount_t amount_t::round(precision_t prec) const +{ + if (! quantity) + throw_(amount_error, "Cannot round an uninitialized amount"); - t.quantity->prec = *prec; - t.quantity->drop_flags(BIGINT_KEEP_PREC); + amount_t t(*this); + if (quantity->prec <= prec) { + if (quantity && quantity->has_flags(BIGINT_KEEP_PREC)) { + t._dup(); + t.quantity->drop_flags(BIGINT_KEEP_PREC); + } return t; } + + t._dup(); + + mpz_round(MPZ(t.quantity), MPZ(t.quantity), t.quantity->prec, prec); + + t.quantity->prec = prec; + t.quantity->drop_flags(BIGINT_KEEP_PREC); + + return t; } amount_t amount_t::unround() const |