Loïc Grenié on Thu, 26 Dec 2024 19:21:26 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: digits of a float |
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)