Performance mpz_divexact / mpz_divexact_ui

Simon Sobisch simonsobisch at
Mon Jan 17 21:57:42 CET 2022

Thank you guys for the thoughts about improing the code!

Am 16.01.2022 um 21:52 schrieb Marco Bodrato:
> Ciao,
> Il Dom, 16 Gennaio 2022 9:21 pm, Paul Zimmermann ha scritto:
>>> * Do you have any other suggestions on improving the code shown above?
>> I would first compute the 2-valuation using mpz_scan1 for example, and
>> then try to divide by 5^k, with k bounded by the 2-valuation.
> Even if there isn't an _ui variant, I'd consider using mpz_remove.
> Ĝis,
> m

mpz_remove worked like a charm and also allowed the code to be much 
simplified! The very specific benchmarks (depending on the environment) 
had their runtime decreased to 60-90% - with being much more simple, too.

I still wonder about my other part of the mail - are the "ui" methods 
considered to be generally faster? In this case the documentation should 
definitely point that out.

Thanks again,

More information about the gmp-discuss mailing list