Bill Allombert on Sun, 15 Dec 2024 12:31:56 +0100
|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
- To: pari-users@pari.math.u-bordeaux.fr
- Subject: Re: digits of a float
- From: Bill Allombert <Bill.Allombert@math.u-bordeaux.fr>
- Date: Sun, 15 Dec 2024 12:31:52 +0100
- Delivery-date: Sun, 15 Dec 2024 12:31:56 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/simple; d=math.u-bordeaux.fr; s=2022; t=1734262314; bh=oJqC36Mw+S3uN5mnHc6SycnnyL4mWDre+jRC2Px3LbY=; h=Date:From:To:Subject:References:In-Reply-To:From; b=FB6xDBeY2hPPAw6dT7X+n/YyR8Gi5Yiev10oE3ZMpdbLRVf5v2xd15sDFV9Aeph8u 7I3itLSFLrK36d0NhG1faZtoBqUBOAMO0Pw5qXWLhNnVKKHCtoAB73/IOlsuy/vho7 fZlcq7vt8O0avQoHOn/s+/u0o5mMzubXUdVRVaNzPGSDZXNj1EeA2nbyKo60DsAk/m GyG7uspus4TETV2dYXeLKxRunNiM3FzOXiwml/uA2IIJDAMKfpM5dGkScZMyFWRbZZ 7+6YLWOcVjeZhSWIKvTJkcsdXrnKCylY6sKS9uBxkQmdLsavJQxX4M7LG1CmS6cDyK ZX8DXLS+lP9spPT4WOWNYTxBZZX8p+gOcwmHTQ+F6GAHyOUZJh+sHs/m+oh0nMLukO V0zte373ufncshZ7sWP80xd0RY39FV/ZdpQQ3fOGGWXqc7U5iGIz0r+IKWCEKMEcFZ BpsSne0VYzh0t5g1PhmS2WyzYdD5CU9iUAg3BJiD2g0kfKAeRE2Hm6PZcPMfNuIQUP +MIkzqJm+9JbYyRQOTfIX6IxLuENGVj6drOGF49wEkTmIgWno9vFB/HIzD0bO4EpZZ BC0USLItpibTWoCQc1tyNpq4li7tMz42koKaxM60W2kRoC1TO2gTP/JeOq1uL1yd5G K7jmQfW77Zgec2IO76ILjKbs=
- In-reply-to: <673e2ad5-26b9-421c-bb53-1837b48e3e83@isolution.nl>
- Mail-followup-to: pari-users@pari.math.u-bordeaux.fr
- References: <673e2ad5-26b9-421c-bb53-1837b48e3e83@isolution.nl>
On Sat, Dec 14, 2024 at 12:07:29PM +0100, Ruud H.G. van Tol wrote:
>
> How to properly isolate a digit of a float?
>
>
> Example:
>
> ? my(n=19437); localprec(n+2); Pi *10^(n-1) \1 %10
> %4 = 7
>
> ? my(n=19437); localprec(n+3); Pi *10^(n-1) \1 %10
> %5 = 6
>
> That type of code depends on the number of 9-digits in the decimal expansion
> of the value.
>
> See also https://oeis.org/A000796, which uses localprec(n*6\5+29).
>
> What clean ways are there?
This is difficult. 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
Cheers,
Bill