summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/amount.cc23
-rw-r--r--src/report.cc14
-rw-r--r--src/report.h2
-rw-r--r--src/stats.cc3
4 files changed, 30 insertions, 12 deletions
diff --git a/src/amount.cc b/src/amount.cc
index 808f118d..99e346b7 100644
--- a/src/amount.cc
+++ b/src/amount.cc
@@ -115,6 +115,7 @@ namespace {
mpq_t quant,
amount_t::precision_t precision,
int zeros_prec = -1,
+ mpfr_rnd_t rnd = MPFR_RNDN,
const optional<commodity_t&>& comm = none)
{
char * buf = NULL;
@@ -135,7 +136,7 @@ namespace {
DEBUG("amount.convert", "num prec = " << num_prec);
mpfr_set_prec(tempfnum, num_prec);
- mpfr_set_z(tempfnum, mpq_numref(quant), GMP_RNDN);
+ mpfr_set_z(tempfnum, mpq_numref(quant), rnd);
mp_prec_t den_prec = mpz_sizeinbase(mpq_denref(quant), 2);
den_prec += amount_t::extend_by_digits*64;
@@ -144,10 +145,10 @@ namespace {
DEBUG("amount.convert", "den prec = " << den_prec);
mpfr_set_prec(tempfden, den_prec);
- mpfr_set_z(tempfden, mpq_denref(quant), GMP_RNDN);
+ mpfr_set_z(tempfden, mpq_denref(quant), rnd);
mpfr_set_prec(tempfb, num_prec + den_prec);
- mpfr_div(tempfb, tempfnum, tempfden, GMP_RNDN);
+ mpfr_div(tempfb, tempfnum, tempfden, rnd);
if (mpfr_asprintf(&buf, "%.*RNf", precision, tempfb) < 0)
throw_(amount_error,
@@ -669,7 +670,7 @@ void amount_t::in_place_floor()
_dup();
std::ostringstream out;
- stream_out_mpq(out, MP(quantity), precision_t(0));
+ stream_out_mpq(out, MP(quantity), precision_t(0), -1, MPFR_RNDZ);
mpq_set_str(MP(quantity), out.str().c_str(), 10);
}
@@ -844,8 +845,8 @@ double amount_t::to_double() const
if (! quantity)
throw_(amount_error, _("Cannot convert an uninitialized amount to a double"));
- mpfr_set_q(tempf, MP(quantity), GMP_RNDN);
- return mpfr_get_d(tempf, GMP_RNDN);
+ mpfr_set_q(tempf, MP(quantity), MPFR_RNDN);
+ return mpfr_get_d(tempf, MPFR_RNDN);
}
long amount_t::to_long() const
@@ -853,14 +854,14 @@ long amount_t::to_long() const
if (! quantity)
throw_(amount_error, _("Cannot convert an uninitialized amount to a long"));
- mpfr_set_q(tempf, MP(quantity), GMP_RNDN);
- return mpfr_get_si(tempf, GMP_RNDN);
+ mpfr_set_q(tempf, MP(quantity), MPFR_RNDN);
+ return mpfr_get_si(tempf, MPFR_RNDN);
}
bool amount_t::fits_in_long() const
{
- mpfr_set_q(tempf, MP(quantity), GMP_RNDN);
- return mpfr_fits_slong_p(tempf, GMP_RNDN);
+ mpfr_set_q(tempf, MP(quantity), MPFR_RNDN);
+ return mpfr_fits_slong_p(tempf, MPFR_RNDN);
}
commodity_t& amount_t::commodity() const
@@ -1239,7 +1240,7 @@ void amount_t::print(std::ostream& _out, const uint_least8_t flags) const
}
stream_out_mpq(out, MP(quantity), display_precision(),
- comm ? commodity().precision() : 0, comm);
+ comm ? commodity().precision() : 0, MPFR_RNDN, comm);
if (comm.has_flags(COMMODITY_STYLE_SUFFIXED)) {
if (comm.has_flags(COMMODITY_STYLE_SEPARATED))
diff --git a/src/report.cc b/src/report.cc
index d3a219a0..548d39df 100644
--- a/src/report.cc
+++ b/src/report.cc
@@ -622,6 +622,16 @@ value_t report_t::fn_floor(call_scope_t& args)
return args[0].floored();
}
+value_t report_t::fn_round(call_scope_t& args)
+{
+ return args[0].rounded();
+}
+
+value_t report_t::fn_unround(call_scope_t& args)
+{
+ return args[0].unrounded();
+}
+
value_t report_t::fn_abs(call_scope_t& args)
{
return args[0].abs();
@@ -1281,6 +1291,8 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
return MAKE_FUNCTOR(report_t::fn_rounded);
else if (is_eq(p, "red"))
return WRAP_FUNCTOR(fn_red);
+ else if (is_eq(p, "round"))
+ return MAKE_FUNCTOR(report_t::fn_round);
break;
case 's':
@@ -1333,6 +1345,8 @@ expr_t::ptr_op_t report_t::lookup(const symbol_t::kind_t kind,
case 'u':
if (is_eq(p, "underline"))
return WRAP_FUNCTOR(fn_underline);
+ else if (is_eq(p, "unround"))
+ return MAKE_FUNCTOR(report_t::fn_unround);
else if (is_eq(p, "unrounded"))
return MAKE_FUNCTOR(report_t::fn_unrounded);
break;
diff --git a/src/report.h b/src/report.h
index e142b0dc..58c12f24 100644
--- a/src/report.h
+++ b/src/report.h
@@ -160,6 +160,8 @@ public:
value_t fn_unrounded(call_scope_t& scope);
value_t fn_truncated(call_scope_t& scope);
value_t fn_floor(call_scope_t& scope);
+ value_t fn_round(call_scope_t& scope);
+ value_t fn_unround(call_scope_t& scope);
value_t fn_abs(call_scope_t& scope);
value_t fn_justify(call_scope_t& scope);
value_t fn_quoted(call_scope_t& scope);
diff --git a/src/stats.cc b/src/stats.cc
index 8899ddf5..524f5a87 100644
--- a/src/stats.cc
+++ b/src/stats.cc
@@ -89,7 +89,8 @@ value_t report_statistics(call_scope_t& args)
out << " (";
out.precision(2);
out << (double(statistics.posts_count)/
- double((statistics.latest_post - statistics.earliest_post).days())) << _(" per day)") << std::endl;
+ double((statistics.latest_post - statistics.earliest_post).days()))
+ << _(" per day)") << std::endl;
out << _(" Uncleared postings: ");
out.width(6);