/*
This function computes the Nth root of real number (x) to
the specified number of decimals (default = 16).
*/
function BC_Nth_Root_of_x ($N, $x, $Decimals=16)
{
$Q = trim($Decimals); // Decimals output
$x = trim($x);
$a = sPrintF('%1.16f', pow($x, 1/$N)); // 1st approximation
$n = $N - 1;
$D = $Q + 24; // Internal working decimals.
for ($i=1; $i <= 50; $i++)
{
$b = bcDiv(bcAdd(bcMul($n,$a,$D),
bcDiv($x,bcPow($a,$n,$D),$D),$D),$N,$D);
if (bcComp($a,$b,$D) == 0) {break;} else {$a = $b;}
}
return RTrim(RTrim(bcAdd($b, '0.'.Str_Repeat(0,$Q).'5',$Q), '0'),'.');
}