question on fixing the mpz_sizeinbase() command to work correctly

Paul Zimmermann Paul.Zimmermann at inria.fr
Wed Mar 20 07:35:58 CET 2024


       Hi Randall,

> Paul:
> 
> This presumes that I know all the thousands of numbers in advance, which 
> I do not know. So I have to do the check just as written in the C++ code.

no, you only have to know in advance the range of possible values of k.

Paul

> But thank you for pointing out that if there was someway to prestore the 
> numbers, then a threshold value could kept statically and checked 
> against that.
> 
> I don't have that option here, sorry.
> 
> Randall
> 
> On 3/19/24 00:19, Paul Zimmermann wrote:
> >>> 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