On Fri, 27 Apr 2018, Niels Möller wrote:

Marc Glisse <marc.gli...@inria.fr> 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
where only some mpz functions would work, it seems safer to document
that none work.

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.

Then mpq_init wouldn't do any allocation, right?

Right.

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.

--
Marc Glisse
_______________________________________________
gmp-devel mailing list
gmp-devel@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-devel

Reply via email to