mini-gmp and mpq
Marc Glisse
marc.glisse at inria.fr
Tue Feb 27 19:22:10 UTC 2018
On Tue, 27 Feb 2018, Marco Bodrato wrote:
> The realway to speed-up that loop is to use the suggestion in gmpxx.h to
> compute a rational+1, both for mini-gmp and the full GMP library:
>
> struct __gmp_unary_increment
> {
> static void eval(mpz_ptr z) { mpz_add_ui(z, z, 1); }
> static void eval(mpq_ptr q)
> { mpz_add(mpq_numref(q), mpq_numref(q), mpq_denref(q)); }
> static void eval(mpf_ptr f) { mpf_add_ui(f, f, 1); }
> };
If I write q = 1 + 1 / q, gmpxx currently generates:
mpq_inv(q, q);
mpz_addmul_ui(num, den, 1);
Not quite optimal yet :-(
--
Marc Glisse
More information about the gmp-devel
mailing list