RosettaCodeData/Task/Nth-root/Perl-6/nth-root.pl6
Ingy döt Net b83f433714 tasks a-s
2013-04-10 23:57:08 -07:00

11 lines
226 B
Raku

sub nth-root ($n, $A, $p=1e-9)
{
my $x0 = $A / $n;
loop {
my $x1 = (($n-1) * $x0 + $A / ($x0 ** ($n-1))) / $n;
return $x1 if abs($x1-$x0) < abs($x0 * $p);
$x0 = $x1;
}
}
say nth-root(3,8);