mpn_tdiv_q

Fredrik Johansson fredrik.johansson at gmail.com
Tue Dec 9 14:39:28 UTC 2014


Hi all,

I suggest adding a public mpn function

mpn_tdiv_q(mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t)

that computes a correctly rounded truncated quotient, disallowing aliasing.

This could simply be implemented using TMP_ALLOC_LIMBS + mpn_div_q
(possibly with a special case for mpn_divrem_1).

Such a function would be very useful for dividing floating-point
numbers, among other things. Currently, if one works with mpn data,
the options are:

* mpn_div_q, but this is undocumented and requires the user to handle
temporary space -- see the discussion 4 years ago:
https://gmplib.org/list-archives/gmp-devel/2010-September/001651.html
* mpn_tdiv_qr, but mpn_div_q is vastly faster for generic divisions
when one does not need the remainder
* mpz_tdiv_q, but this requires moving data in and out of mpz variables

An mpn_tdiv_q function would provide a stable and obvious division
interface without either of those drawbacks. It could be added
independently of other potential changes such as changing the amount
of temp space required by mpn_div_q (or removing this parameter
entirely, effectively making mpn_div_q/mpn_tdiv_q aliases for the same
thing).

The overhead of the extra temporary allocation (sometimes avoidable
with mpn_div_q as one can reuse memory intended for something else)
would usually be minor compared to calling mpn_tdiv_qr or mpz_tdiv_q.

The interface would also happen to be compatible with a certain GMP
fork, which is convenient for third party software.

Best wishes,
Fredrik


More information about the gmp-devel mailing list