Re: digits of a float

Loïc Grenié <[email protected]>
Newsgroups gmane.comp.mathematics.pari.user
Message-ID <CAMLkfFQyQd+vEqxYybLDiJv1wRN+gS1tmkB5K3PQAWiruwi1qQ@mail.gmail.com>
On Thu 26 Dec, 2024, at 17:21, Ruud H.G. van Tol wrote:

>
> On 2024-12-15 12:31, Bill Allombert wrote:
> > [...] One need to round toward 0 instead of rounding to nearest
> > as usual.
> >
> > In this instance the number end by 574699992... which is (correctly)
> rounded to nearest
> > by PARI to 5747.....
> >
> > I wrote this, which increase the accuracy until there is no more
> ambiguity.
> > {
> >    my(n=19437,z);
> >    for(m=n+1,oo,
> >      localprec(m+1);
> >      z = round(Pi *10^m)/10^m;
> >      if(abs(z-Pi)>10^-(m+1),break));
> >    z*10^(n-1)\1%10
> > }
> >
> > but this need to be checked more carefully
>
> For Pi-digits, I am now using:
>
> pi_digits(n, p=20)= {
>    my(u=10^(n+p-1), f(x, u)=my(n=1, q=u\x, r=q, s=1, t);
> while(t=(q\=(x*x))\(n+=2), r+=(s=-s)*t); r*4);
>    digits((4*f(5, u) - f(239, u))\10^p);
> } \\ Machin-like, with p > the maximal number of consecutive 9-digits to
> be expected (A048940)
>

     Wouldn't floor be more adapted than round?

            Loïc
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.