From ce4ed2b25cd4ead67a52cf42e05c7091aff9b3c7 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 21 May 2007 20:45:46 +0000 Subject: Getting things to compile again. --- src/numerics/amount.cc | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'src/numerics/amount.cc') 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& 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 -- cgit v1.2.3