Charles Greathouse on Wed, 24 Jan 2024 15:39:54 +0100


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

Re: log_int_rat


You can make it faster by storing only the exponent.

first(n)=my(a=-1,b=1,r=-1); vector(n, i, a+=2; b*=3; if(b>>a, , a++; b*=3; r++); 2*i+r)

On my system this is about twice as fast.

On Tue, Jan 23, 2024 at 7:56 PM Ruud H.G. van Tol <rvtol@isolution.nl> wrote:

On 2024-01-22 04:26, Ruud H.G. van Tol wrote:
> [...]
>
> Now proposed it as:
>
> alist(N) = { \\ A054414
>   my(a=1/2, b=1, r=-1);
>   vector(N, i, a*=4; b*=3; r+=2; if(a>b, a*=2; b*=3; r++); r);
> }

And 2% faster:

alist(N) = { \\ A054414
   my(a=1/2, b=1, r=-1);
   vector(N, i, a*=4; b*=3; if(a>b, a*=2; b*=3; r++); 2*i+r);
}

-- Ruud