mpz_limbs interface

Niels Möller nisse at
Tue Jan 21 20:16:35 UTC 2014

Marc Glisse <marc.glisse at> writes:

> On Tue, 21 Jan 2014, Niels Möller wrote:
>> When does this situation arise?
> __GMPXX_TMPZ_D, for instance.

>From a quick look in gmpxx.h, it appears we could *almost* use
MPZ_ROINIT_N. For the target call, the temp variable always used as an mpz_t
*input* only (from a quick look at gmpxx.h). But the initialization
calls mpz_set_d. Ideal would be something like

  mp_limb_t limbs[__GMPZ_DBL_LIMBS];
  mpz_t temp = MPZ_ROINIT_N(limbs, mpn_set_d(limbs, d));

This assumes that C++ allows initializers with arbitrary non-constant
expressions (does it?), and that we implement mpn_set_d. Then, mpz_set_d
could be reimplemented as

  mpz_set_d (mpz_t r, double d)
    rn = ... needed space for d ...
    mp_ptr rp = MPZ_REALLOC (r, rn);
    SIZ(r) = mpn_set_d (rp, d));

In the current code, there's a related function __gmp_extract_double. I
haven't really tried to understant how mpz_set_d works.


Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.

More information about the gmp-devel mailing list