Division using GMP's low-level API

Torbjörn Granlund tg at gmplib.org
Sun Aug 28 10:46:32 CEST 2022


Bernhard Lindner <private at bernhard-lindner.de> writes:

  So there is an obsolete function (mpn_divrem), a function that takes
  small (<= 64bit) divisors only (mpn_divrem_1), one that has undefined
  behavior with remainders (mpn_divexact_1) and one that takes large (>=
  129bit) divisors only (mpn_tdiv_qr).

Where did you get ">= 129 bit" from?  There is no such limitation for
mpn_tdiv_qr.

  I tried mpn_tdiv_qr() (without limb overlaps) since I thought I'm
  misunderstanding the documentation and because it replaces the obsolete
  function. But it actually crashes when the most significant limb is
  zero.

Yes, as documented it must be non-zero.

  Did I miss something? How can I divide two random uint192 non-zero
  numbers using mpn_?

Use mpn_tdiv_qr, but pass a size which make the most significant limb !=
0.

-- 
Torbjörn
Please encrypt, key id 0xC8601622


More information about the gmp-discuss mailing list