sqrt and Buf question

Hi All,

1) how do I get 40 or more digits out of sqrt?

2) how to I assist those bytes to a 40 (or more)
byte long Buf?

This obviously does not work:

my Num $x = 3.sqrt; my Buf $y = Buf.new($x)

Type check failed in initializing element #0 to Buf; expected uint8 but 
got Num (1.7320508075688772e0)
   in block <unit> at <unknown file> line 1

Many thanks,
-T
0
perl6
5/14/2020 12:27:42 PM
perl.perl6.users 1389 articles. 0 followers. Follow

11 Replies
19 Views

Similar Articles

[PageSpeed] 9

On Thu, 14 May 2020, ToddAndMargo via perl6-users wrote:
> Hi All,
> 
> 1) how do I get 40 or more digits out of sqrt?
> 

Meaningful digits? Not possible as sqrt uses limited precision. I think
the IEEE 754 doubles that I would suspect to be used internally are capped
way below 40 significant decimal digits.

> 2) how to I assist those bytes to a 40 (or more)
> byte long Buf?
> 
> This obviously does not work:
> 
> my Num $x = 3.sqrt; my Buf $y = Buf.new($x)
> 
> Type check failed in initializing element #0 to Buf; expected uint8 but got
> Num (1.7320508075688772e0)
>   in block <unit> at <unknown file> line 1
> 

You can convert the Num to a string and put that string into a Buf:

  Buf.new(3.sqrt.Str.encode)

That's what I'd do without any clue at all about who is supposed to use
this Buf. At least the buffer is about as long as the number is decimal
digits, which seems to be what you wanted?

Regards,
Tobias
0
tobs
5/14/2020 12:51:22 PM
On 2020-05-14 05:51, Tobias Boege wrote:
> On Thu, 14 May 2020, ToddAndMargo via perl6-users wrote:
>> Hi All,
>>
>> 1) how do I get 40 or more digits out of sqrt?
>>
> 
> Meaningful digits? 

In this instance, I do not care about meaningful.  I only
care about the noise.  Just has to be repeatable.

I may have to look it up on a chart.

> Not possible as sqrt uses limited precision. I think
> the IEEE 754 doubles that I would suspect to be used internally are capped
> way below 40 significant decimal digits.
> 
>> 2) how to I assist those bytes to a 40 (or more)
>> byte long Buf?
>>
>> This obviously does not work:
>>
>> my Num $x = 3.sqrt; my Buf $y = Buf.new($x)
>>
>> Type check failed in initializing element #0 to Buf; expected uint8 but got
>> Num (1.7320508075688772e0)
>>    in block <unit> at <unknown file> line 1
>>
> 
> You can convert the Num to a string and put that string into a Buf:
> 
>    Buf.new(3.sqrt.Str.encode)
> 
> That's what I'd do without any clue 

I am not disclosing on purpose.  Sorry for keeping you
in the dark.

> at all about who is supposed to use
> this Buf. At least the buffer is about as long as the number is decimal
> digits, which seems to be what you wanted?
> 
> Regards,
> Tobias
> 

my Buf $x = Buf.new(3.sqrt.Str.encode)
Buf:0x<31 2E 37 33 32 30 35 30 38 30 37 35 36 38 38 37 37 32>


Thank you!
0
perl6
5/14/2020 1:11:30 PM

> On May 14, 2020, at 7:27 AM, ToddAndMargo via perl6-users =
<perl6-users@perl.org> wrote:
>=20
> Hi All,
>=20
> 1) how do I get 40 or more digits out of sqrt?

=E2=80=94snip=E2=80=94

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

=E2=80=94=20
Hope this helps,
Bruce Gray (=E2=80=9CUtil=E2=80=9D on RosettaCode, too)
0
robertbrucegray3
5/14/2020 3:13:32 PM
On 2020-05-14 08:13, Bruce Gray wrote:
>=20
>=20
>> On May 14, 2020, at 7:27 AM, ToddAndMargo via perl6-users <perl6-users=
@perl.org> wrote:
>>
>> Hi All,
>>
>> 1) how do I get 40 or more digits out of sqrt?
>=20
> =E2=80=94snip=E2=80=94
>=20
> 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.=

>=20
> Exact code here:
> 	https://rosettacode.org/wiki/Integer_roots#Raku
>=20
> =E2=80=94
> Hope this helps,
> Bruce Gray (=E2=80=9CUtil=E2=80=9D on RosettaCode, too)


sub integer_root ( Int $p where * >=3D 2, Int $n --> Int ) {
     my Int $d =3D $p - 1;
     my $guess =3D 10**($n.chars div $p);
     my $iterator =3D { ( $d * $^x   +   $n div ($^x ** $d) ) div $p };
     my $endpoint =3D {      $^x      ** $p <=3D $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?

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

what is the second number (100)?

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

 > say integer_root( 2, 2 * 100 ** 4 );
14142

 > say 3.sqrt
1.7320508075688772

 > say integer_root( 2, 3 * 100 ** 16 );
17320508075688772


-T
0
perl6
5/14/2020 9:36:30 PM
On 2020-05-14 05:51, Tobias Boege wrote:
> On Thu, 14 May 2020, ToddAndMargo via perl6-users wrote:
>> Hi All,
>>
>> 1) how do I get 40 or more digits out of sqrt?
>>
> 
> Meaningful digits? Not possible as sqrt uses limited precision. I think
> the IEEE 754 doubles that I would suspect to be used internally are capped
> way below 40 significant decimal digits.
> 
>> 2) how to I assist those bytes to a 40 (or more)
>> byte long Buf?
>>
>> This obviously does not work:
>>
>> my Num $x = 3.sqrt; my Buf $y = Buf.new($x)
>>
>> Type check failed in initializing element #0 to Buf; expected uint8 but got
>> Num (1.7320508075688772e0)
>>    in block <unit> at <unknown file> line 1
>>
> 
> You can convert the Num to a string and put that string into a Buf:
> 
>    Buf.new(3.sqrt.Str.encode)
> 
> That's what I'd do without any clue at all about who is supposed to use
> this Buf. At least the buffer is about as long as the number is decimal
> digits, which seems to be what you wanted?
> 
> Regards,
> Tobias
> 

Using Peter's code:

Buf.new(integer_root( 2, 3 * 100 ** 39 ).Str.encode)
Buf:0x<31 37 33 32 30 35 30 38 30 37 35 36 38 38 37 37 32 39 33 35 32 37 
34 34 36 33 34 31 35 30 35 38 37 32 33 36 36 39 34 32>

LAT AND LOTS OF repeatable NOISE!


-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0
perl6
5/14/2020 9:59:35 PM
--v4cNTr+tRGSs1txX
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, May 14, 2020 at 02:36:30PM -0700, ToddAndMargo via perl6-users wrot=
e:
> On 2020-05-14 08:13, Bruce Gray wrote:
> >=20
> >=20
> > > On May 14, 2020, at 7:27 AM, ToddAndMargo via perl6-users <perl6-user=
s@perl.org> wrote:
> > >=20
> > > Hi All,
> > >=20
> > > 1) how do I get 40 or more digits out of sqrt?
> >=20
> > =E2=80=94snip=E2=80=94
> >=20
> > 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.
> >=20
> > Exact code here:
> > 	https://rosettacode.org/wiki/Integer_roots#Raku
> >=20
> > =E2=80=94
> > Hope this helps,
> > Bruce Gray (=E2=80=9CUtil=E2=80=9D on RosettaCode, too)
>=20
>=20
> sub integer_root ( Int $p where * >=3D 2, Int $n --> Int ) {
>     my Int $d =3D $p - 1;
>     my $guess =3D 10**($n.chars div $p);
>     my $iterator =3D { ( $d * $^x   +   $n div ($^x ** $d) ) div $p };
>     my $endpoint =3D {      $^x      ** $p <=3D $n
>                      and ($^x + 1) ** $p >  $n };
>     min (+$guess, $iterator ... $endpoint)[*-1, *-2];
> }
>=20
> say integer_root( 2, 2 * 100 ** 2000 );
>=20
>=20
>=20
> It does help!  I can reproduce noise to my heart's content!
>=20
> Questions:
>=20
> 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

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

--v4cNTr+tRGSs1txX
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEELuenpRf8EkzxFcNUZR7vsCUn3xMFAl6+J/QACgkQZR7vsCUn
3xNBlg/+Lg09TwtoLcMk2Q+kKmMZVlDrzkM8IuaFVfI+TIpxD+cSf7SvqivfAe7s
u26GeKa5Ow3rJLxwx1vI65ufeAu5vE2nhhilCMPCDwMtaz99DnSVjADJKEkO0C45
zL2pTUCQrTKhLEs89vSJsBpuxtyzRNiA85RAhsPkFgkzhmCMJtorrcv+/PoKNqdZ
GMXPK5Rxf+MP1TMCRuegQNnNcOo5E+bLQVY/6+W3RyTTgEcWo7/P45gIoVtxWySD
XWAr9/VSQxTnKRvxsPjr3qwGHWIZ2tACjptwbpauTLtgStSg4U2LVCxuxllAZQRR
98Y3344YcKYDGC9p6VtWviFJPOlYTYuAuMdmO7PHQJdcTlNhO/pQo3EL4gEgFxHU
EnH95Oi/ElsAZjmjyCzPrXR4HzSH+p9qHYE+KHD8EicSc/YlBD6GVI3AKrfrMEn5
uU2FXXRp1LOBqLYT7DITzFjR+d/Foxe9wH+dLEIz5UYlvAYzlksUQ16E6wvTLVNv
5whjl6Fh80cYH64NADe9h2MHXAEzmp4JsIai6ynzeHwDXqO+gyFE2CGHGfSx/+cP
v7WMZ7doKgetXsmsqMez4IHcznP9rrXjM48l+BSce0sj95v7k3rUfomCx11k8ZNG
D1GVttbtdnKYhcUl1mquCVLtlaY87jnp9IHADoCyLyiLlEi7Gt8=
=SMWs
-----END PGP SIGNATURE-----

--v4cNTr+tRGSs1txX--
0
roam
5/15/2020 5:26:13 AM

> On May 14, 2020, at 4:36 PM, ToddAndMargo via perl6-users =
<perl6-users@perl.org> wrote:
>=20
> On 2020-05-14 08:13, Bruce Gray wrote:
>>> On May 14, 2020, at 7:27 AM, ToddAndMargo via perl6-users =
<perl6-users@perl.org> wrote:
>>>=20
>>> Hi All,
>>>=20
>>> 1) how do I get 40 or more digits out of sqrt?
>> =E2=80=94snip=E2=80=94
>> 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
>> =E2=80=94
>> Hope this helps,
>> Bruce Gray (=E2=80=9CUtil=E2=80=9D on RosettaCode, too)
>=20
>=20
> sub integer_root ( Int $p where * >=3D 2, Int $n --> Int ) {
>    my Int $d =3D $p - 1;
>    my $guess =3D 10**($n.chars div $p);
>    my $iterator =3D { ( $d * $^x   +   $n div ($^x ** $d) ) div $p };
>    my $endpoint =3D {      $^x      ** $p <=3D $n
>                     and ($^x + 1) ** $p >  $n };
>    min (+$guess, $iterator ... $endpoint)[*-1, *-2];
> }
>=20
> say integer_root( 2, 2 * 100 ** 2000 );
>=20
>=20
>=20
> It does help!  I can reproduce noise to my heart's content!

Hmmmm. See my `srand` note at the end.

>=20
> Questions:
>=20
> what is $p in the sub declaration? Is it always a 2?

$p is the =E2=80=9Cdegree=E2=80=9D of the root wanted; 2 for square =
root, 3 for cube root, etc.

>=20
> what is `$n` in the sub declaration?

$n is the number that you want the root of.

> Looks like
> the third set of numbers is the digits I want.
>=20
> what is the second number (100)?

100 is (10 ** $degree), and the degree is `2` for square root.

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

As Peter Pentchev pointed out, A * B ** C is always interpreted as A * =
(B ** C).

>=20
> > say integer_root( 2, 2 * 100 ** 4 );
> 14142
>=20
> > say 3.sqrt
> 1.7320508075688772
>=20
> > say integer_root( 2, 3 * 100 ** 16 );
> 17320508075688772
>=20
>=20
> -T


I see from your question that while the RosettaCode solution is =
generally clear for the task itself, the use of `100` in the calling =
code is less clear. (I will fix that on RC)

An "integer root" algorithm, taken by itself, only gives you a =
fast/direct method to find `($number ** (1/$root_wanted)).floor` without =
ever using floating point.
To use such an algorithm to produce more digits, we have to *scale* the =
number such that the root of the scaling factor is a power of 10, so the =
scaling factor must be a power of (10 ** $root_wanted).
For square roots, we need (10 ** 2), which is why the RC code says =
`100`; the square root of 100 is 10, and `10` slides the decimal point =
while preserving the digits.
	$ perl6 -e 'say .sqrt.floor for 2, 200, 20000, 2000000, =
200000000'
	1
	14
	141
	1414
	14142


So, the "root wanted" (like 2 for square root, 3 for cube root, etc) =
occurs twice in the integer_root() call; once as the first argument `p`, =
and again in the exponent of 10 in the multiplier for the second =
argument.
e.g. to get the first 42 digits of the cube root of 88:
	say integer_root( 3, 88 * ((10 ** 3) ** 42) );
	4447960181138631042330726753444314393037398

Or:
	sub lots_of_digits_of_root ( $radicand, $degree, =
$extra_digit_count ) {
		return integer_root( $degree, $radicand * ((10 ** =
$degree) ** $extra_digit_count) );
	}
	say lots_of_digits_of_root( 88, 3, 42 );
	4447960181138631042330726753444314393037398

Finally, you said "reproduce noise", which makes me think that you might =
be going down this sqrt(2)-road from having tried Raku's rand() for =
noise, but hitting the problem of its non-reproducibility.
If so, a much simpler method would be to use the built-in solution: Call =
`srand` to force `rand` to use a some fixed starting-point.
	# All different:
	$ perl6 -e '           say (^10).roll(*).head(15);' # (5 5 7 9 8 =
7 6 9 1 2 1 3 3 0 6)
	$ perl6 -e '           say (^10).roll(*).head(15);' # (2 7 3 4 3 =
9 9 3 2 2 4 6 5 9 9)
	$ perl6 -e '           say (^10).roll(*).head(15);' # (2 2 1 7 1 =
7 6 3 1 2 4 1 3 1 4)
	$ perl6 -e '           say (^10).roll(*).head(15);' # (4 7 1 0 8 =
5 6 6 0 1 8 2 3 3 6)
	# All identical
	$ perl6 -e 'srand(42); say (^10).roll(*).head(15);' # (4 3 9 3 6 =
1 1 0 0 5 8 3 6 7 0)
	$ perl6 -e 'srand(42); say (^10).roll(*).head(15);' # (4 3 9 3 6 =
1 1 0 0 5 8 3 6 7 0)
	$ perl6 -e 'srand(42); say (^10).roll(*).head(15);' # (4 3 9 3 6 =
1 1 0 0 5 8 3 6 7 0)
	$ perl6 -e 'srand(42); say (^10).roll(*).head(15);' # (4 3 9 3 6 =
1 1 0 0 5 8 3 6 7 0)

=E2=80=94=20
HTH, Util
Harry knew pi to 3.141592 because accuracy to one part in a million was =
enough for most practical purposes.=20
Hermione knew one hundred digits of pi because that was how many digits =
had been printed in the back of her maths textbook.
https://www.hpmor.com/chapter/9
0
robertbrucegray3
5/15/2020 7:09:03 PM
On 2020-05-15 12:09, Bruce Gray wrote:
>=20
>=20
>> On May 14, 2020, at 4:36 PM, ToddAndMargo via perl6-users <perl6-users=
@perl.org> wrote:
>>
>> On 2020-05-14 08:13, Bruce Gray wrote:
>>>> On May 14, 2020, at 7:27 AM, ToddAndMargo via perl6-users <perl6-use=
rs@perl.org> wrote:
>>>>
>>>> Hi All,
>>>>
>>>> 1) how do I get 40 or more digits out of sqrt?
>>> =E2=80=94snip=E2=80=94
>>> 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 resul=
t.
>>> Exact code here:
>>> 	https://rosettacode.org/wiki/Integer_roots#Raku
>>> =E2=80=94
>>> Hope this helps,
>>> Bruce Gray (=E2=80=9CUtil=E2=80=9D on RosettaCode, too)
>>
>>
>> sub integer_root ( Int $p where * >=3D 2, Int $n --> Int ) {
>>     my Int $d =3D $p - 1;
>>     my $guess =3D 10**($n.chars div $p);
>>     my $iterator =3D { ( $d * $^x   +   $n div ($^x ** $d) ) div $p };=

>>     my $endpoint =3D {      $^x      ** $p <=3D $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!
>=20
> Hmmmm. See my `srand` note at the end.
>=20
>>
>> Questions:
>>
>> what is $p in the sub declaration? Is it always a 2?
>=20
> $p is the =E2=80=9Cdegree=E2=80=9D of the root wanted; 2 for square roo=
t, 3 for cube root, etc.
>=20
>>
>> what is `$n` in the sub declaration?
>=20
> $n is the number that you want the root of.
>=20
>> Looks like
>> the third set of numbers is the digits I want.
>>
>> what is the second number (100)?
>=20
> 100 is (10 ** $degree), and the degree is `2` for square root.
>=20
>>
>> And what is `2 * 100 ** 2000 `?  Is that `(2 x 100)^ 2000`
>> ((2 times 100) to the 2000 power?
>=20
> As Peter Pentchev pointed out, A * B ** C is always interpreted as A * =
(B ** C).
>=20
>>
>>> say integer_root( 2, 2 * 100 ** 4 );
>> 14142
>>
>>> say 3.sqrt
>> 1.7320508075688772
>>
>>> say integer_root( 2, 3 * 100 ** 16 );
>> 17320508075688772
>>
>>
>> -T
>=20
>=20
> I see from your question that while the RosettaCode solution is general=
ly clear for the task itself, the use of `100` in the calling code is les=
s clear. (I will fix that on RC)
>=20
> An "integer root" algorithm, taken by itself, only gives you a fast/dir=
ect method to find `($number ** (1/$root_wanted)).floor` without ever usi=
ng floating point.
> To use such an algorithm to produce more digits, we have to *scale* the=
 number such that the root of the scaling factor is a power of 10, so the=
 scaling factor must be a power of (10 ** $root_wanted).
> For square roots, we need (10 ** 2), which is why the RC code says `100=
`; the square root of 100 is 10, and `10` slides the decimal point while =
preserving the digits.
> 	$ perl6 -e 'say .sqrt.floor for 2, 200, 20000, 2000000, 200000000'
> 	1
> 	14
> 	141
> 	1414
> 	14142
>=20
>=20
> So, the "root wanted" (like 2 for square root, 3 for cube root, etc) oc=
curs twice in the integer_root() call; once as the first argument `p`, an=
d again in the exponent of 10 in the multiplier for the second argument.
> e.g. to get the first 42 digits of the cube root of 88:
> 	say integer_root( 3, 88 * ((10 ** 3) ** 42) );
> 	4447960181138631042330726753444314393037398
>=20
> Or:
> 	sub lots_of_digits_of_root ( $radicand, $degree, $extra_digit_count ) =
{
> 		return integer_root( $degree, $radicand * ((10 ** $degree) ** $extra_=
digit_count) );
> 	}
> 	say lots_of_digits_of_root( 88, 3, 42 );
> 	4447960181138631042330726753444314393037398
>=20
> Finally, you said "reproduce noise", which makes me think that you migh=
t be going down this sqrt(2)-road from having tried Raku's rand() for noi=
se, but hitting the problem of its non-reproducibility.
> If so, a much simpler method would be to use the built-in solution: Cal=
l `srand` to force `rand` to use a some fixed starting-point.
> 	# All different:
> 	$ perl6 -e '           say (^10).roll(*).head(15);' # (5 5 7 9 8 7 6 9=
 1 2 1 3 3 0 6)
> 	$ perl6 -e '           say (^10).roll(*).head(15);' # (2 7 3 4 3 9 9 3=
 2 2 4 6 5 9 9)
> 	$ perl6 -e '           say (^10).roll(*).head(15);' # (2 2 1 7 1 7 6 3=
 1 2 4 1 3 1 4)
> 	$ perl6 -e '           say (^10).roll(*).head(15);' # (4 7 1 0 8 5 6 6=
 0 1 8 2 3 3 6)
> 	# All identical
> 	$ perl6 -e 'srand(42); say (^10).roll(*).head(15);' # (4 3 9 3 6 1 1 0=
 0 5 8 3 6 7 0)
> 	$ perl6 -e 'srand(42); say (^10).roll(*).head(15);' # (4 3 9 3 6 1 1 0=
 0 5 8 3 6 7 0)
> 	$ perl6 -e 'srand(42); say (^10).roll(*).head(15);' # (4 3 9 3 6 1 1 0=
 0 5 8 3 6 7 0)
> 	$ perl6 -e 'srand(42); say (^10).roll(*).head(15);' # (4 3 9 3 6 1 1 0=
 0 5 8 3 6 7 0)
>=20
> =E2=80=94
> HTH, Util
> Harry knew pi to 3.141592 because accuracy to one part in a million was=
 enough for most practical purposes.
> Hermione knew one hundred digits of pi because that was how many digits=
 had been printed in the back of her maths textbook.
> https://www.hpmor.com/chapter/9
>=20


Thank you!!!
0
perl6
5/15/2020 7:24:11 PM
On 2020-05-14 22:26, Peter Pentchev wrote:
>> 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

Any chance of you answering the question directly?

Is it (2 x 100)^ 2000

Or 2 x ( 100^ 2000 )    2 times (100 to the 2000 power)?

Your point 1 only applies if it is an exponent.  Is the
2000 an exponent?  Does ** stand for exponent?
0
perl6
5/16/2020 9:33:33 PM
Hi Todd,

Yes, ** stands for exponentiation. And exponentiation has higher
precedence than multiplication. See below (I dropped a few zeros to
help clarify):

> put 2 * 10 ** 20
200000000000000000000
> put (2 * 10) ** 20
104857600000000000000000000
> put 2 * (10 ** 20)
200000000000000000000
> 20 ** 20
104857600000000000000000000
>

https://docs.raku.org/language/operators

HTH, Bill.


On Sat, May 16, 2020 at 2:33 PM ToddAndMargo via perl6-users
<perl6-users@perl.org> wrote:
>
> On 2020-05-14 22:26, Peter Pentchev wrote:
> >> 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
>
> Any chance of you answering the question directly?
>
> Is it (2 x 100)^ 2000
>
> Or 2 x ( 100^ 2000 )    2 times (100 to the 2000 power)?
>
> Your point 1 only applies if it is an exponent.  Is the
> 2000 an exponent?  Does ** stand for exponent?
0
perl6
5/16/2020 9:48:59 PM
On 2020-05-16 14:48, William Michels via perl6-users wrote:
> Yes, ** stands for exponentiation

Thank you!
0
perl6
5/16/2020 10:11:09 PM
Reply: