question on fixing the mpz_sizeinbase() command to work correctly
Paul Zimmermann
Paul.Zimmermann at inria.fr
Tue Mar 19 08:19:48 CET 2024
> > I am examining thousands of different numbers, maybe more.
> >
> Then it's more efficient to implement the final check on your side, keeping the already computed powers and reusing them.
indeed it will be much more efficient:
0) for each value k returned by mpz_sizeinbase in your application range,
store the threshold value BASE^(k-1)
1) for each input n, let k = mpz_sizeinbase (n, BASE)
2) if n >= BASE^(k-1), return k, else return k-1
Step 0 is a precomputation and has only to be done once.
Paul Zimmermann
More information about the gmp-discuss
mailing list