fdigits() implementation
"Ruud H.G. van Tol" <[email protected]>
| Newsgroups | gmane.comp.mathematics.pari.user |
|---|---|
| Message-ID | <[email protected]> |
First try:
fdigits( v, c=precision(.), s=1 )= {
localprec( max( c+s+8, precision(.)+1 ) );
while( type(v) == "t_CLOSURE", v=v() );
localprec( max( precision(v+.)+1, precision(.) ) );
v+=.;
my( r=digits( v * 10^(c+s-2) \ 1 ) );
if( #r < c+s-1, r= concat( vector(c+s-1-#r), r ) );
if( s > #r, s= 0 );
r= r[ s .. -1 ];
if( c < #r, r= r[ 1 .. c ] );
r;
}
Some example runs:
? precision(.)
% 38
? fdigits( 1 - 10^-20, 24 )
% [0, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 0, 0, 0]
? #fdigits( Pi )
% 38
? fdigits( Pi, 10, 761 )
ERROR
? fdigits( ()->Pi, 10, 761 )
% [3, 4, 9, 9, 9, 9, 9, 9, 8, 3]
? fdigits( ()->Pi, 10, 19991 )
% [4, 0, 4, 9, 0, 7, 5, 5, 1, 7]
-- Ruud