Niels Möller nisse at
Fri Dec 18 14:53:09 CET 2009

I've rewritten mpz_divexact in terms of mpn_divexact, result attached.

Some comments: I removed the code for stripping of trailing zeros, and
special case handling of dn == 1. That is now done by mpn_divexact. In
case of operand overlap, I compute the quotient to a temporary area, and
then copy it to the result. This should be a good strategy except

 * when d and n are shifted into a temporary area anyway by mpn_divexact
   before the call to mpn_bdiv_q. I think it would make sense to let
   mpn_bdiv_q do that shifting on the fly.

 * if q and d overlap, n is distinct, and dn < qn; then it would be
   better to copy the smaller d to temporary storage

 * if the mpn_divexact interfaces is changed to allow some overlap. For
   at least some of the hensel division code, it would be natural to
   allow np = qp. That might work also with the bidirectional algorithm,
   at least in the balanced case, since the quotient for the truncation
   division would overwrite the second quarter of the input n, which is
   otherwise ignored by divexact.

Should I check this in straight away?


-------------- next part --------------
A non-text attachment was scrubbed...
Name: divexact.c
Type: text/x-csrc
Size: 2533 bytes
Desc: not available
URL: <>
-------------- next part --------------

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