diff --git a/ex-2/fancier.c b/ex-2/fancier.c index 46ce770..eb0c0ed 100644 --- a/ex-2/fancier.c +++ b/ex-2/fancier.c @@ -432,7 +432,8 @@ void a_series(mpq_t rop, size_t N) { mpz_set_ui(fact, 1); mpz_set_ui(power, 1); - for (size_t k = 0; k < 5*N; k++) { + size_t kmax = 4.97 * N; + for (size_t k = 0; k <= kmax; k++) { if (k > 0) { mpz_mul_ui(fact, fact, k); mpz_mul(power, power, stop); @@ -469,7 +470,8 @@ void b_series(mpq_t rop, size_t N){ mpz_set_ui(fact, 1); mpz_set_ui(power, 1); - for (size_t k = 0; k < 5*N; k++) { + size_t kmax = 4.97 * N; + for (size_t k = 0; k <= kmax; k++) { if (k > 0) { mpz_mul_ui(fact, fact, k); mpz_mul(power, power, stop); diff --git a/ex-2/fast.c b/ex-2/fast.c index 17e43b8..22a2b33 100644 --- a/ex-2/fast.c +++ b/ex-2/fast.c @@ -146,10 +146,10 @@ void mpf_gamma(mpf_t rop, size_t digits) { * ignoring the C/B² term, to less than 10^-D is α⋅2^p where α * is the solution of: * - * α log(α) = 3 + α ⇒ α = exp(W(3e) - 1) ≈ 4.97 + * α log(α) = 1 + α ⇒ α = exp(W(3e) - 1) ≈ 4.97 * */ - size_t kmax = 4.97 * (1 << p); + size_t kmax = 3.59 * (1 << p); fprintf(stderr, "[mpf_gamma] iterations: %ld\n", kmax); // initialise variables