Extending the mpn interface

Bill Allombert Bill.Allombert at math.u-bordeaux.fr
Mon Feb 16 00:37:03 UTC 2015


On Fri, Feb 15, 2013 at 03:51:02PM +0100, Niels Möller wrote:
> /* Second revision of a minimal mpz/mpn interface. Question: Should we
>    use real functions, inline functions, or macros? */

Sorry to answer with two year delay, but I just see that these functions 
were added to GMP 6. I should have been more careful.

After reading the documentation it is unclear to me how to use them
to emulate mpn_* functions. Basically I have a input mpn (x,nx) and 
a output mpn (z,nz). I know nz is large enough to hold the result.

I would like to call mpz_divexact_ui on (x,nx) and put the result 
in (z,nz), and I would like to avoid doing extra copies (because
mpz_divexact_ui run in linear time).

How can I do that ?
I assume I should start with
mpz_t X,Z;
mpz_roinit_n(X,x,nx);
???
mpz_divexact_ui(Z,X,3);
???

There are well-known unofficial macros to perform this task, but I would
like to avoid unofficial interfaces: 
They works like this:

mpz_t X,Z;
X->_mp_alloc = nx;
X->_mp_size = nx;
X->_mp_d = x;
Z->_mp_alloc = nz;
Z->_mp_size  = nz;
Z->_mp_d = z;
mpz_divexact_ui(Z, X, 3);

Cheers,
Bill.


More information about the gmp-devel mailing list