Double-Click Within Text Area to Select ALL Code
function bcNth_Root_of_X ($N, $x, $Decimals) { $Q = trim($Decimals); // Returned decimals $x = trim($x); $a = sprintf('%1.16f', pow($x, 1/$N)); // 1st approximation $n = $N - 1; $D = $Q + 8; // 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'),'.'); }