summaryrefslogtreecommitdiff
path: root/amount.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2004-08-13 17:41:29 -0400
committerJohn Wiegley <johnw@newartisans.com>2004-08-13 17:41:29 -0400
commit0cac03ba7d0a5ab95e1d81d68102778cb995a363 (patch)
tree71fc1e4f14874d1654cb958a7708acc6803b1972 /amount.cc
parent0c8dff61edf2db560c92c25468520cd1bc773d77 (diff)
downloadfork-ledger-0cac03ba7d0a5ab95e1d81d68102778cb995a363.tar.gz
fork-ledger-0cac03ba7d0a5ab95e1d81d68102778cb995a363.tar.bz2
fork-ledger-0cac03ba7d0a5ab95e1d81d68102778cb995a363.zip
performance tweaks
Diffstat (limited to 'amount.cc')
-rw-r--r--amount.cc27
1 files changed, 4 insertions, 23 deletions
diff --git a/amount.cc b/amount.cc
index daf323aa..2e8fc8fb 100644
--- a/amount.cc
+++ b/amount.cc
@@ -392,13 +392,7 @@ amount_t& amount_t::operator*=(const amount_t& amt)
INIT();
mpz_mul(MPZ(quantity), MPZ(quantity), MPZ(amt.quantity));
-
- // Truncate to the recorded precision: MAX_PRECISION.
- mpz_t divisor;
- mpz_init(divisor);
- mpz_ui_pow_ui(divisor, 10, MAX_PRECISION);
- mpz_tdiv_q(MPZ(quantity), MPZ(quantity), divisor);
- mpz_clear(divisor);
+ mpz_tdiv_q(MPZ(quantity), MPZ(quantity), full_divisor);
return *this;
}
@@ -410,15 +404,9 @@ amount_t& amount_t::operator/=(const amount_t& amt)
INIT();
- mpz_t divisor;
- mpz_init(divisor);
- mpz_ui_pow_ui(divisor, 10, MAX_PRECISION);
-
- mpz_mul(MPZ(quantity), MPZ(quantity), divisor);
+ mpz_mul(MPZ(quantity), MPZ(quantity), full_divisor);
mpz_tdiv_q(MPZ(quantity), MPZ(quantity), MPZ(amt.quantity));
- mpz_clear(divisor);
-
return *this;
}
@@ -429,15 +417,9 @@ amount_t& amount_t::operator%=(const amount_t& amt)
INIT();
- mpz_t divisor;
- mpz_init(divisor);
- mpz_ui_pow_ui(divisor, 10, MAX_PRECISION);
-
- mpz_mul(MPZ(quantity), MPZ(quantity), divisor);
+ mpz_mul(MPZ(quantity), MPZ(quantity), full_divisor);
mpz_tdiv_r(MPZ(quantity), MPZ(quantity), MPZ(amt.quantity));
- mpz_clear(divisor);
-
return *this;
}
@@ -476,8 +458,7 @@ std::ostream& operator<<(std::ostream& out, const amount_t& amt)
if (amt.commodity->precision != MAX_PRECISION)
mpz_round(rquotient, MPZ(amt.quantity), amt.commodity->precision);
- mpz_ui_pow_ui(divisor, 10, MAX_PRECISION);
- mpz_tdiv_qr(quotient, remainder, rquotient, divisor);
+ mpz_tdiv_qr(quotient, remainder, rquotient, full_divisor);
if (mpz_sgn(quotient) < 0 || mpz_sgn(remainder) < 0)
negative = true;