Ruud H.G. van Tol on Fri, 24 Dec 2021 21:54:24 +0100
|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: Significant figures printing in GP.
|
- To: pari-users@pari.math.u-bordeaux.fr
- Subject: Re: Significant figures printing in GP.
- From: "Ruud H.G. van Tol" <rvtol@isolution.nl>
- Date: Fri, 24 Dec 2021 21:54:13 +0100
- Delivery-date: Fri, 24 Dec 2021 21:54:24 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=simple/simple; d=isolution.nl; s=soverin; t=1640379257; bh=yCl6pe45dkj2CLHjUceZk5ptAhilx3q6lLysPTQiPtE=; h=Date:Subject:To:References:From:In-Reply-To:From; b=I1HfQgkk0JcKjfgON4TBxdJKstNzJGOPywgy/QKRMZtZJjYHzgyRHHUG+H4o++Its 58wq+OZ+uUX2H0es9e9dLE0RAGjaVOJHFp+mmLIwEOH5Bf3br/Yq0Vkcw1SHXaFyq7 1rp3douFtNmo6cx6INQswmMAV1tnthwgiiBueuQfSEAmFo0IlYgS7XKymI/SaqcLVg IUNEMMW0kJRjTZYMB7dD8KiiGJgHYeznrrwxVGBrTZSEl9kBa8C4/B6FO1gHsdXZfK fjrRx1Err0XArn+Z3Tn3hA/pldOSUTTTlRNn55mNrgK/zOXJyOEAp4kMxf+L6lGaH0 wzdfMdhrCxuhw==
- In-reply-to: <YcYoAxeMuR+qsOGj@seventeen>
- References: <CAFSmZyxAm=o4bz5EE30EwFZHQayj2yznqY0TRFL3VPLcR6wrtg@mail.gmail.com> <YcYoAxeMuR+qsOGj@seventeen>
On 2021-12-24 21:05, Bill Allombert wrote:
On Fri, Dec 24, 2021 at 03:55:20PM -0400, R J Cano wrote:
[...]
For instance, let's assume certain calculation involving only real
numbers in the final result, yields
x=3.00002575
Then the expected result must be printed:
3.000026
Hello Remy,
What you can do is
sigfig2(x,n)=printf("%.*g\n",n,x);
? sigfig2(x,7)
3.000026
(you can also use Strprintf to the same effect).
Strprintf(fmt,{x}*): deprecated alias for strprintf
:)
A numeric variant:
dround(x, d=1)= {
my(f=floor(1+log(x)/log(10)));
1.*round(x*10^(d-f))/10^(d-f)
}
? x
%13 = 3.000025750000000000
? dround(x,7)
%14 = 3.0000260000000000000000000000000000000
-- Ruud