R J Cano on Fri, 24 Dec 2021 20:55:24 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Significant figures printing in GP. |
Dear PARI users. Please. Is this code a neat way of displaying real numbers rounded up to certain quantity of significant figures?, sigfig(a,{b=%})={if(type(b)==type(3.141592),my(x=digits(truncate(b*10^default(realprecision)))[1..a+1]);x[a]+=(x[a+1]>4);return(x[1..a]))} Admittedly i never tried that before in automated way. it seems to display correct results, but im not clear if there is an easier way of achieving the same. For instance, let's assume certain calculation involving only real numbers in the final result, yields x=3.00002575 And we are asked to represent it with only 7 significant figures. So, before anything else, we call: xr=sigfig(7) Then the expected result must be printed: 3.000026 Again, the thing im questioning here, is the code shown above... after reviewing that topic on significant figures, it simply was written such routine just as to mimic the precise way a human does it by hand. Thanks in advance. Best wishes, --Remy