On Thu, May 14, 2020 at 02:36:30PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-14 08:13, Bruce Gray wrote:
> > 
> > 
> > > On May 14, 2020, at 7:27 AM, ToddAndMargo via perl6-users 
> > > <perl6-us...@perl.org> wrote:
> > > 
> > > Hi All,
> > > 
> > > 1) how do I get 40 or more digits out of sqrt?
> > 
> > —snip—
> > 
> > Use an Integer Root algorithm on ($number-you-want-the-root-of * 100 ** 
> > $number-of-digits-you-want), then shift the decimal point of the result.
> > 
> > Exact code here:
> >     https://rosettacode.org/wiki/Integer_roots#Raku
> > 
> > —
> > Hope this helps,
> > Bruce Gray (“Util” on RosettaCode, too)
> 
> 
> sub integer_root ( Int $p where * >= 2, Int $n --> Int ) {
>     my Int $d = $p - 1;
>     my $guess = 10**($n.chars div $p);
>     my $iterator = { ( $d * $^x   +   $n div ($^x ** $d) ) div $p };
>     my $endpoint = {      $^x      ** $p <= $n
>                      and ($^x + 1) ** $p >  $n };
>     min (+$guess, $iterator ... $endpoint)[*-1, *-2];
> }
> 
> say integer_root( 2, 2 * 100 ** 2000 );
> 
> 
> 
> It does help!  I can reproduce noise to my heart's content!
> 
> Questions:
> 
> what is $p in the sub declaration? Is it always a 2?

https://rosettacode.org/wiki/Integer_roots

> what is `$n` in the sub declaration?  Looks like
> the third set of numbers is the digits I want.

https://rosettacode.org/wiki/Integer_roots

> what is the second number (100)?

https://rosettacode.org/wiki/Integer_roots

> And what is `2 * 100 ** 2000 `?  Is that `(2 x 100)^ 2000`
> ((2 times 100) to the 2000 power?

Point 1: exponentiation has a higher priority than multiplication.

Point 2: https://rosettacode.org/wiki/Integer_roots

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:        http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13

Attachment: signature.asc
Description: PGP signature

Reply via email to