11 lines
250 B
PHP
11 lines
250 B
PHP
function nthroot($number, $root, $p = P)
|
|
{
|
|
$x[0] = $number;
|
|
$x[1] = $number/$root;
|
|
while(abs($x[1]-$x[0]) > $p)
|
|
{
|
|
$x[0] = $x[1];
|
|
$x[1] = (($root-1)*$x[1] + $number/pow($x[1], $root-1))/$root;
|
|
}
|
|
return $x[1];
|
|
}
|