Task

Implement the algorithm to compute the principal   nth   root   





A

n





{\displaystyle {\sqrt[{n}]{A}}}

   of a positive real number   A,   as explained at the   Wikipedia page.



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);