Division using GMP's low-level API

Bernhard Lindner private at bernhard-lindner.de
Sun Aug 28 13:33:43 CEST 2022


Hello Torbjörn,

thanks a lot for your answer!

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

Well, if I need to use a 192 bit sized integer divisor with a MSL (most significant limb)
>0 I need a divisor of at least at least 129 bit. But this is phrased stupidly knowing
what you just told me.

>   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.

So you mean instead of passing the number of allocated limbs (3 in my case) I should pass
the allocated number of limbs minus the number of leading zero-value limbs (depending from
the individual divisor's value)? LOL, that didn't come to my mind...

BTW I had a look into the mpz source code. The function mpz_tdiv_q() uses a mpn function
named mpn_div_q() that is not part of the public low-level API. Why is that function non-
public? I guess mpn_div_q() has advantages over mpn_tdiv_qr()?
I'm asking because two separate functions for quotient and remainder would fit my
application well and I would prefer such functions if they provide a performance gain
(which is most important for me).

-- 
Best Regards,
Bernhard Lindner


More information about the gmp-discuss mailing list