Bill Allombert on Mon, 22 Jan 2024 21:05:40 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: log_int_rat


On Mon, Jan 22, 2024 at 02:30:13PM +0100, Ruud H.G. van Tol wrote:
> > safedigits(f)=
> > {
> >    my(z=f(),e=exponent(z),k=3,r);
> >    while(1,
> >      my(K=10^k,y=round(K*z,&r));
> >      if (r<0 && (y+1)%K>1, return(y\K));
> >      k*=2;
> >      localbitprec(e+4*k);z=f());
> > }
> > a(n) = localbitprec(logint(n+2,2)); 1+n+safedigits(()->(n*log(2)/log(3/2)));
> 
> To me this is just another example of why to avoid floats and floor() and
> such,
> when the goal is integers.
> 
> So I'm back at my original quest. :)
> > ? a054414(n) = 1 + n + floor( n * log(2) / log(3/2) );
> > Is there a cleaner way, similar to logint, to do that floor-expression?
> 
> The table() function (from Bill) made me think that a discrete a(n),
> ideally without any slow while-loop, is doable,
> so I will keep looking and trying in that direction.

Well, you can take a middle ground: compute an approximation of the result
using floating point and check and ajust it using exact arithmetic.

Cheers,
Bill.