documentation on internals not up to date

Marco Bodrato bodrato at
Fri Apr 27 17:38:58 UTC 2018


Il Ven, 27 Aprile 2018 2:46 pm, Marc Glisse ha scritto:
> On Fri, 27 Apr 2018, Niels Möller wrote:
>> Marc Glisse <marc.glisse at> writes:
>>> There would be a significant advantage to mpq if we could have a
>>> non-allocated 1 for the denominator. But indeed, with the current code
>> We could do that internally, even if we don't advertise it for other gmp
>> users.
> We document that users can use the denominator of a mpq_t as a regular
> mpz_t and apply pretty much any mpz_t operation to it. So it seems hard to
> handle just that case internally.

I agree, mpq_denref(Q) should work as a generic mpz_t. That's why I also
pushed the "Support lazy mpq_t also in the denominator" patch.

>> We could have a single mpq object representing 0/1 with _mp_alloc == 0
>> for both parts, and initialize with struct assignment or memcpy.
>> We would just ensure that mpz realloc keeps supporting thuis case.

... and it's not just a problem of supporting mpq_denref() we should also
change some mpq_ functions. If someone does init an mpq_t with:
  mpz_init (mpq_numref (accumulator));
  mpz_roinit_n (mpq_denref (accumulator), &const_one, 1);

then a simple, mpq_add (accumulator, accumulator, another_mpq) might fail.

Niels is right when he says we should not mention on the manual that
sometimes writing on a read-only mpz does actually work.
It does not work as a general rule and it may not be supported by future
releases, that's the only information we can document.



More information about the gmp-devel mailing list