From 845548fa93a40d9fe3302a8d0049e7dd9a0069d4 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Sun, 24 May 2020 23:11:29 +0200 Subject: [PATCH] ex-2/fancier: optimise out an operation --- ex-2/fancier.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/ex-2/fancier.c b/ex-2/fancier.c index a0d3074..3855581 100644 --- a/ex-2/fancier.c +++ b/ex-2/fancier.c @@ -340,20 +340,17 @@ void mpq_log_ui(mpq_t rop, size_t x, size_t digits) { mpq_div(low, term, temp); mpq_add(low, sum, low); - /* Average the two bounds */ + /* Average the two bounds + * Note: we don't divive the sum by 2 because we + * actually need 2 Σ_{k=0} y^(2k+1)/(2k+1). + */ mpq_add(sum, low, upp); - mpz_div_ui(mpq_numref(sum), mpq_numref(sum), 2); - mpq_canonicalize(sum); size_t d = digits > 50 ? 50 : digits; mpq_fprintf(stderr, d+2, "[mpq_log_ui] upper bound: %q...\n", upp); mpq_fprintf(stderr, d+2, "[mpq_log_ui] lower bound: %q...\n", low); mpq_fprintf(stderr, d, "[mpq_log_ui] series: %q...\n", sum); - // multiply by 2 - mpz_mul_ui(mpq_numref(sum), mpq_numref(sum), 2); - mpq_canonicalize(sum); - // calculate log(2)*(m-1) mpq_t log2; mpq_init(log2); mpq_log2(log2, digits);