mini-gmp and mpq

Marco Bodrato bodrato at mail.dm.unipi.it
Tue Feb 27 19:49:38 UTC 2018


Ciao,

Il Mar, 27 Febbraio 2018 8:22 pm, Marc Glisse ha scritto:
> If I write q = 1 + 1 / q, gmpxx currently generates:
> mpq_inv(q, q);
> mpz_addmul_ui(num, den, 1);
>
> Not quite optimal yet :-(

May the following help?

diff -r dbd767bb43bf gmpxx.h
--- a/gmpxx.h	Mon Feb 26 08:34:53 2018 +0100
+++ b/gmpxx.h	Tue Feb 27 20:45:54 2018 +0100
@@ -220,7 +220,12 @@
     {
       if (q != r) mpq_set(q, r);
     }
+    else if (__GMPXX_CONSTANT(l) && l == 1)
+    {
+      mpz_add (mpq_numref(q), mpq_numref(r), mpq_denref(r));
+      if (q != r) mpz_set(mpq_denref(q), mpq_denref(r));
+    }
     else
     {
       if (q == r)
         mpz_addmul_ui(mpq_numref(q), mpq_denref(q), l);
@@ -339,7 +344,12 @@
     {
       if (q != r) mpq_set(q, r);
     }
+    else if (__GMPXX_CONSTANT(l) && l == 1)
+    {
+      mpz_sub (mpq_numref(q), mpq_numref(r), mpq_denref(r));
+      if (q != r) mpz_set(mpq_denref(q), mpq_denref(r));
+    }
     else
     {
       if (q == r)
         mpz_submul_ui(mpq_numref(q), mpq_denref(q), l);


Ĝis,
m

-- 
http://bodrato.it/papers/



More information about the gmp-devel mailing list