mynumber = $mynumber;
$this->rootExponent = $rootExponent;
$this->fifthRootMultiplyer = 1;
$this->powerDivisor = 1;
}
function __destruct()
{
echo "";
} //
Object Destroyed.
// 5th root approximation
private function getNextPerfect5th($Num = 0)
{
if ($Num == 0)
$Number = $this->mynumber;
else
$Number = $Num;
//$Number = $Number * $this->fifthRootMultiplyer;
$next5th = 1;
$nextRoot = 1;
$hit5th = 0;
$hitroot = 1;
while ($next5th < $Number) {
//loop
$hit5th = $next5th;
$hitroot = $nextRoot;
$nextRoot++;
$next5th = pow($nextRoot, 5);
}
return $hitroot;
}
private function getApprox5thRoot($IntRoot, $offset)
{
$a5thrt = $IntRoot;
$a = $IntRoot;
$b = $offset;
$error = 0;
if ($IntRoot > 0) {
$a = $IntRoot;
$fifthPow = $a * $a * $a * $a * $a + $b; // mynumber
$b = $fifthPow - pow($a, 5);
$a1 = $a + 1;
$mid = ($a1 * $a1 * $a1 * $a1 * $a1 - $a * $a * $a * $a * $a) / 2;
$q = $b / (5 * $a * $a * $a * $a);
if ($q < 0.5 || $b < $mid) { //$b < $mid && $q < 0.5 && $error < 0.1
$q = $b / (5 * $a * $a * $a * $a);
if ($q > 0) {
$N = $a + (1 / ((1 / $q) + (1 / (($a + $q) / 2))));
} else {
$N = $a + $q;
}
$R = $a + ($q * $N) / ($q + $N);
$S = ($fifthPow + pow($R, 5)) / (2 * pow($R, 4));
$T = ($R + $S) / 2;
$U = ($fifthPow + pow($T, 5)) / (2 * pow($T, 4));
$V = ((4 * $U) + ($fifthPow / pow($U, 4))) / $this->powerDivisor;
$W = $V / 5;
if ($b != 0 && $fifthPow > 0) {
//$Y = ($a + ($q + (2 / $U)));
$Y = $a + (1 / ((1 / $q) + (1 / (($U) / 2))));
} else
$Y = $a;
$Z = $Y / $this->powerDivisor;
$a5thrt = ($W + $Z) / 2;
$pow5thrt = $a5thrt * $this->powerDivisor;
} else {
$a = $a + 1;
/**/
$b = $offset - (5 * pow($IntRoot, 4) + 10 * pow($IntRoot, 3) + 10 * pow($IntRoot,
2) + 5 * $IntRoot + 1);
$fifthPow = $a * $a * $a * $a * $a + $b; // mynumber
$q = $b / (5 * $a * $a * $a * $a);
if ($q != 0 && ($a + $q) > 0) {
$N = $a + (1 / ((1 / $q) + (1 / (($a + $q) / 2))));
} else {
$N = $a + $q;
}
$R = $a + ($q * $N) / ($q + $N);
$S = ($fifthPow + pow($R, 5)) / (2 * pow($R, 4));
$T = ($R + $S) / 2;
$U = ($fifthPow + pow($T, 5)) / (2 * pow($T, 4));
$V = ((4 * $U) + ($fifthPow / pow($U, 4))) / $this->powerDivisor;
$W = $V / 5;
if ($b != 0 && $fifthPow > 0) {
//$Y = ($a + ($q + (2 / $U)));
$Y = $a + (1 / ((1 / $q) + (1 / (($U) / 2))));
} else
$Y = $a;
$Z = $Y / $this->powerDivisor;
$a5thrt = ($W + $Z) / 2;
$pow5thrt = $a5thrt * $this->powerDivisor;
}
}
$error = abs($fifthPow - pow($pow5thrt, 5));
if ($error > 0.000001) {
$errorfix = ($fifthPow - pow($pow5thrt, 5)) / (5 * pow($pow5thrt, 4));
$a5thrt += $errorfix / $this->powerDivisor;
}
return $a5thrt;
}
private function get5thRootArray($startingNum)
{
//$csvStr = "Test Number | Approx Root | Approximate 5th5 | error x10000 |
";
$this->fifthRootMultiplyer = 1;
$this->powerDivisor = 1;
$strArray = array(
"Test Number" => $startingNum,
"Approx Root" => 0,
"Approximate 5th" => 0,
"error x10000" => 0);
$powerDivisor = 1;
$Inverted = false;
if ($startingNum == 0) {
$strArray["Test Number"] = " Too Small ";
return $strArray;
}
if ($startingNum < 1) {
$startingNum = 1.0 / $startingNum;
$Inverted = true;
}
if ($startingNum < 3125) {
$this->fifthRootMultiplyer = 3125;
$this->powerDivisor = 5;
$powerDivisor = 5;
$startingNum = $startingNum * $this->fifthRootMultiplyer;
// $this->mynumber = $fifthPow;
} //for small roots less than 5
if ($startingNum > 999999999999) {
if ($Inverted != true) {
$strArray["Test Number"] = " Too Big ";
return $strArray;
} else {
$strArray["Test Number"] = " Too Small ";
return $strArray;
}
}
$fifthPow = $startingNum;
$realIntRoot = $this->getNextPerfect5th($fifthPow); // returns realintRoot before multiplyer applied
$realnextintroot = $realIntRoot + 1;
if ($startingNum >= 3) { // get root of starting number
$IntRoot = $this->getNextPerfect5th($startingNum); // returns intRoot after multiplyer applied
$Int5thPow = pow($IntRoot, 5);
$b = $fifthPow - $Int5thPow;
$ApproxRoot = $this->getApprox5thRoot($IntRoot, $b);
$Approx5thPow = pow($ApproxRoot, 5);
$Tru5thPow = (($Int5thPow + $b)) / pow($powerDivisor, 5);
$delta = $Approx5thPow - $Tru5thPow;
//echo "
Test Number: " . $IntSqr . " True Root: " . $truSqrt . " Approx Root " . $ApproxRoot . " errorx100: " . round($delta*100, 6);
// unset($strArray);
if ($Inverted != true) {
$strArray = array(
"Test Number" => $Tru5thPow,
"Approx Root" => $ApproxRoot,
"Approximate 5th" => round($Approx5thPow, 10),
"error x10000" => (number_format(round($delta * 10000, 7), 7)));
} else {
$strArray = array(
"Test Number" => 1 / ($Tru5thPow),
"Approx Root" => 1 / $ApproxRoot,
"Approximate 5th" => round(1 / $Approx5thPow, 10),
"error x10000" => (number_format(round($delta * 10000, 7), 7)));
}
} else {
$strArray["Test Number"] = " Too Small ";
}
return $strArray;
}
private function display5thRootList($startingNum, $justone = true)
{
$csvStr = "Test Number | Approx Root | Approximate 5th5 | error x10000 |
";
$powerDivisor = 1;
$Inverted = false;
$this->fifthRootMultiplyer = 1;
$this->powerDivisor = 1;
if ($startingNum == 0)
return " Too Small |
";
if ($startingNum < 1) {
$startingNum = 1.0 / $startingNum;
$Inverted = true;
}
if ($startingNum < 3125) { // debug
$this->fifthRootMultiplyer = 3125;
$this->powerDivisor = 5;
$powerDivisor = 5;
$startingNum = $startingNum * $this->fifthRootMultiplyer;
// $this->mynumber = $fifthPow;
} //for small roots less than 5
if ($startingNum > 999999999999) {
if ($Inverted != true)
return " Too Big |
";
else
return " Too Small |
";
}
$fifthPow = $startingNum;
$realIntRoot = $this->getNextPerfect5th($fifthPow); // returns realintRoot before multiplyer applied
$realnextintroot = $realIntRoot + 1;
if ($startingNum >= 3) { // get root of starting number
$IntRoot = $this->getNextPerfect5th($startingNum); // returns intRoot after multiplyer applied
$Int5thPow = pow($IntRoot, 5);
if ($justone == false) {
$is = 0;
$iend = 32; //$realnextintroot - $realIntRoot;
$fifthPow = 16 * $this->fifthRootMultiplyer; //*round(($realnextintroot - $realIntRoot));
if (($fifthPow / $this->fifthRootMultiplyer) <= 2) {
$fifthPow = 2 * $this->fifthRootMultiplyer;
}
for ($i = $is; $i <= $iend; $i++) {
$b = $fifthPow - $Int5thPow;
$ApproxRoot = $this->getApprox5thRoot($IntRoot, $b);
$Approx5thPow = pow($ApproxRoot, 5);
$Tru5thPow = (($Int5thPow + $b)) / pow($powerDivisor, 5);
$delta = $Approx5thPow - $Tru5thPow;
//echo "
Test Number: " . $IntSqr . " True Root: " . $truSqrt . " Approx Root " . $ApproxRoot . " errorx100: " . round($delta*100, 6);
if ($Inverted != true) {
$csvStr .= "" . $Tru5thPow . " | " . $ApproxRoot . " | " .
round($Approx5thPow, 10) . " | " . number_format(round($delta * 10000, 7),
7) . " |
"; //round($delta * 100, 9) . "
"; // echo number_format(round($delta * 100, 9) ,9);
} else {
$csvStr .= "" . 1 / ($Tru5thPow) . " | " . 1 / $ApproxRoot .
" | " . round(1 / $Approx5thPow, 10) . " | " . number_format(round(($delta) *
10000, 7), 7) . " |
"; //round($delta * 100, 9) . "
"; // echo number_format(round($delta * 100, 9) ,9);
}
$fifthPow += $this->fifthRootMultiplyer;
}
} else {
$b = $fifthPow - $Int5thPow;
$ApproxRoot = $this->getApprox5thRoot($IntRoot, $b);
$Approx5thPow = pow($ApproxRoot, 5);
$Tru5thPow = (($Int5thPow + $b)) / pow($powerDivisor, 5);
$delta = $Approx5thPow - $Tru5thPow;
//echo "
Test Number: " . $IntSqr . " True Root: " . $truSqrt . " Approx Root " . $ApproxRoot . " errorx100: " . round($delta*100, 6);
if ($Inverted != true) {
$csvStr .= "" . $Tru5thPow . " | " . $ApproxRoot . " | " .
round($Approx5thPow, 10) . " | " . number_format(round($delta * 10000, 7),
7) . " |
"; //round($delta * 100, 9) . "
"; // echo number_format(round($delta * 100, 9) ,9);
} else {
$csvStr .= "" . 1 / ($Tru5thPow) . " | " . 1 / $ApproxRoot .
" | " . round(1 / $Approx5thPow, 10) . " | " . number_format(round(($delta) *
10000, 7), 7) . " |
"; //round($delta * 100, 9) . "
"; // echo number_format(round($delta * 100, 9) ,9);
}
}
} else
return " Too Small |
";
return $csvStr;
}
// cube root approximation
private function getNextPerfectCube($Num = 0)
{
if ($Num == 0)
$Number = $this->mynumber;
else
$Number = $Num;
$nextCube = 1;
$nextRoot = 1;
$hitCube = 0;
$hitroot = 1;
while ($nextCube < $Number) {
//loop
$hitCube = $nextCube;
$hitroot = $nextRoot;
$nextCube = $nextCube + 3 * $nextRoot * $nextRoot + 3 * $nextRoot + 1;
$nextRoot++;
}
return $hitroot;
}
private function getApproxCubeRoot($IntRoot, $offset)
{
$aCbrt = $IntRoot;
$Cubex = $IntRoot * $IntRoot * $IntRoot + $offset;
if ($IntRoot > 0 && $offset > 0) {
$a = $IntRoot;
$b = $offset;
$Cube = $a * $a * $a + $b;
$a1 = $a + 1;
$mid = ($a1 * $a1 * $a1 - $a * $a * $a) / 2;
if ($b < $mid) {
$q = $b / (3 * $a * $a);
$F = $a + $q;
$G = $a + ($F * $q / ($F + $q));
$H = ($Cube + pow($G, 3)) / (2 * pow($G, 2));
$I = ($G + $H) / 2;
$J = pow($I, 3);
$K = ($Cube + $J) / (2 * pow($I, 2));
$K2 = $K * $K;
$aCbrt = (2 * $K + ($Cube / $K2)) / 3;
} else {
$a = $a + 1;
$b = $offset - (3 * $IntRoot * $IntRoot + 3 * $IntRoot + 1);
$Cube = $a * $a * $a + $b;
$q = $b / (3 * $a * $a);
$F = $a + $q;
$G = $a + ($F * $q / ($F + $q));
$H = ($Cube + pow($G, 3)) / (2 * pow($G, 2));
$I = ($G + $H) / 2;
$J = pow($I, 3);
$K = ($Cube + $J) / (2 * pow($I, 2));
$K2 = $K * $K;
$aCbrt = (2 * $K + ($Cube / $K2)) / 3;
}
}
$error = abs($Cubex - pow($aCbrt, 3));
if ($error > 0.0001) {
$coeff = 1;
if (abs($Cubex) < pow($aCbrt, 3)) {
$coeff = -1;
}
$errorfix = $coeff * $error / abs(3 * $aCbrt * $aCbrt);
$aCbrt += $errorfix;
}
return $aCbrt;
}
private function getCubeRootArray($startingNum)
{
$this->fifthRootMultiplyer = 1;
$this->powerDivisor = 1;
$strArray = array(
"Test Number" => $startingNum,
"Approx Root" => 0,
"Approximate Cube" => 0,
"error x10000" => 0);
$rootDiv = 1;
$cbDiv = 1;
$Inverted = false;
if ($startingNum == 0) {
$strArray["Test Number"] = " Too Small ";
return $strArray;
}
if ($startingNum < 0.009) {
$startingNum = 1.0 / $startingNum;
$Inverted = true;
}
if ($startingNum < 10) {
$startingNum = 1000 * $startingNum;
$rootDiv = 10;
$cbDiv = 1000;
} elseif ($startingNum > 999999999999) {
if ($Inverted != true) {
$strArray["Test Number"] = " Too Big ";
return $strArray;
} else {
$strArray["Test Number"] = " Too Small ";
return $strArray;
}
}
if ($startingNum >= 3) { // get root of starting number
$IntRoot = $this->getNextPerfectCube($startingNum);
$nextintroot = (3 * $IntRoot * $IntRoot + 3 * $IntRoot + 1);
$IntCube = pow($IntRoot, 3);
$offset = $startingNum - $IntCube;
$i = $startingNum - $IntCube;
$ApproxRoot = $this->getApproxCubeRoot($IntRoot, $i) / $rootDiv;
$ApproxCb = pow($ApproxRoot, 3);
$TruCube = ($IntCube + $i) / $cbDiv;
$delta = $ApproxCb - $TruCube;
//unset($strArray);
if ($Inverted != true) {
$strArray = array(
"Test Number" => ($IntCube + $i) / $cbDiv,
"Approx Root" => $ApproxRoot,
"Approximate Cube" => round($ApproxCb, 10),
"error x10000" => number_format(round($delta * 10000, 7), 7));
} else {
$strArray = array(
"Test Number" => 1 / (($IntCube + $i) / $cbDiv),
"Approx Root" => 1 / $ApproxRoot,
"Approximate Cube" => round(1 / $ApproxCb, 10),
"error x10000" => number_format(round(($delta) * 10000, 7), 7));
}
} else {
$strArray["Test Number"] = " Too Small ";
}
return $strArray;
}
private function displayCubeRootList($startingNum, $justone = true)
{
$csvStr = "Test Number | Approx Root | Approximate Cube | Cube³ error x10000 |
";
$rootDiv = 1;
$cbDiv = 1;
$Inverted = false;
if ($startingNum == 0) {
return " Too Small |
";
}
if ($startingNum < 0.009) {
$startingNum = 1.0 / $startingNum;
$Inverted = true;
}
if ($startingNum < 10) {
$startingNum = 1000 * $startingNum;
$rootDiv = 10;
$cbDiv = 1000;
} elseif ($startingNum > 999999999999) {
if ($Inverted != true)
return " Too Big |
";
else
return " Too Small |
";
}
if ($startingNum >= 3) { // get root of starting number
$IntRoot = $this->getNextPerfectCube($startingNum);
$nextintroot = (3 * $IntRoot * $IntRoot + 3 * $IntRoot + 1);
$IntCube = pow($IntRoot, 3);
$offset = $this->mynumber - $IntCube;
if ($justone == false) {
for ($i = $offset - 16; $i <= $offset + 32; $i++) {
$ApproxRoot = $this->getApproxCubeRoot($IntRoot, $i) / $rootDiv;
$ApproxCb = pow($ApproxRoot, 3);
$TruCube = $IntCube / $cbDiv;
$delta = $ApproxCb - ($TruCube + $i);
//echo "
Test Number: " . $IntSqr . " True Root: " . $truSqrt . " Approx Root " . $ApproxRoot . " errorx100: " . round($delta*100, 6);
if ($Inverted != true) {
$csvStr .= "" . ($IntCube + $i) / $cbDiv . " | " . $ApproxRoot .
" | " . round($ApproxCb, 10) . " | " . number_format(round($delta *
10000, 7), 7) . " "; //round($delta * 100, 9) . " "; // echo number_format(round($delta * 100, 9) ,9);
} else {
$csvStr .= 1 / (($IntCube + $i) / $cbDiv) . " | " . 1 / $ApproxRoot .
" | " . round(1 / $ApproxCb, 10) . " | " . number_format(round(($delta) *
10000, 7), 7) . " |
"; //round($delta * 100, 9) . "
"; // echo number_format(round($delta * 100, 9) ,9);
}
//$IntCube++;
}
} else {
$i = $startingNum - $IntCube;
$ApproxRoot = $this->getApproxCubeRoot($IntRoot, $i) / $rootDiv;
$ApproxCb = pow($ApproxRoot, 3);
$TruCube = ($IntCube + $i) / $cbDiv;
$delta = $ApproxCb - $TruCube;
//echo "
Test Number: " . $IntSqr . " True Root: " . $truSqrt . " Approx Root " . $ApproxRoot . " errorx100: " . round($delta*100, 6);
if ($Inverted != true) {
$csvStr .= "" . ($IntCube + $i) / $cbDiv . " | " . $ApproxRoot .
" | " . round($ApproxCb, 10) . " | " . number_format(round($delta *
10000, 7), 7) . " |
"; //round($delta * 100, 9) . "
"; // echo number_format(round($delta * 100, 9) ,9);
} else {
$csvStr .= "" . 1 / (($IntCube + $i) / $cbDiv) . " | " . 1 / $ApproxRoot .
" | " . round(1 / $ApproxCb, 10) . " | " . number_format(round(($delta) *
10000, 7), 7) . " |
"; //round($delta * 100, 9) . "
"; // echo number_format(round($delta * 100, 9) ,9);
}
}
} else
return " Too Small |
";
return $csvStr;
}
//Square Root Approximation
private function getNextPerfectSquare($myNumber)
{
$nextSqr = 4;
$nextRoot = 2;
$hitSqr = 0;
$hitroot = 2;
while ($nextSqr < $myNumber) {
//loop
$hitSqr = $nextSqr;
$hitroot = $nextRoot;
$nextSqr = $nextSqr + 2 * $nextRoot + 1;
$nextRoot++;
}
return $hitroot;
}
private function getApproxSquareRoot($IntRoot, $offset)
{
$asqrt = $IntRoot;
//$Square = $IntRoot * $IntRoot + $offset;
if ($IntRoot > 0 && $offset > 0) {
$a = $IntRoot;
$b = $offset;
$Square = $a * $a + $b;
if ($b < $a) {
$q = $b / (2 * $a);
$divisor = (4 * $a * $a) + (2 * $b) - $b / (2 * $a + 1);
$asqrt = $a + $q * (1 - ($b / $divisor)); // add fix1 or 2
$ApproxSquare = $asqrt * $asqrt;
$ApproxSquareError = $Square - $ApproxSquare;
$asqrterror = $ApproxSquareError / (2 * $asqrt);
$asqrt = $asqrt + $asqrterror;
} else {
$a = $a + 1;
$b = $offset - (2 * $IntRoot + 1);
$Square = $a * $a + $b;
$q = $b / (2 * $a);
$divisor = (4 * $a * $a) + (2 * $b) - $b / (2 * $a + 1);
$asqrt = $a + $q * (1 - ($b / $divisor)); // add fix1 or 2
$ApproxSquare = $asqrt * $asqrt;
$ApproxSquareError = $Square - $ApproxSquare;
$asqrterror = $ApproxSquareError / (2 * $asqrt);
$asqrt = $asqrt + $asqrterror;
}
}
return $asqrt;
}
private function getSquareRootArray($startingNum, $justApproxRoot = false)
{
$strArray = "";
if ($justApproxRoot != true) {
$strArray = array(
"Test Number" => $startingNum,
"Approx Root" => 0,
"Approx Square" => 0,
"error x10000" => 0);
}
$rootDiv = 1;
$sqrDiv = 1;
if ($startingNum == 0) {
$strArray["Test Number"] = " Too Small ";
return $strArray;
}
if ($startingNum < 10) {
$startingNum = 10000 * $startingNum;
$rootDiv = 100;
$sqrDiv = 10000;
} elseif ($startingNum > 999999999999) {
$strArray["Test Number"] = " Too Big ";
return $strArray;
}
if ($startingNum >= 3) { // get root of starting number
$IntRoot = $this->getNextPerfectSquare($startingNum);
$nextintroot = (2 * $IntRoot + 1);
$IntSqr = $IntRoot * $IntRoot;
$i = $startingNum - $IntSqr;
$ApproxRoot = $this->getApproxSquareRoot($IntRoot, $i) / $rootDiv;
$ApproxSqr = $ApproxRoot * $ApproxRoot;
$TruSqr = ($IntSqr + $i) / $sqrDiv;
$delta = $ApproxSqr - $TruSqr;
if ($justApproxRoot == true)
$strArray["Approx Root"] = $ApproxRoot;
else {
//unset($strArray);
$strArray = array(
"Test Number" => ($IntSqr + $i) / $sqrDiv,
"Approx Root" => $ApproxRoot,
"Approx Square" => round($ApproxSqr, 10),
"error x10000" => number_format(round($delta * 10000, 7), 7));
}
} else
$strArray["Test Number"] = " Too Small ";
return $strArray;
}
// loop thru all the numbers between 900 and 961 2n+1
private function displaySquareRootList($startingNum, $justone = true)
{ // starting num should be an integer square e.g. 900 root 30
$csvStr = "Test Number | Approx Root | Approx Square | ❏ error x10000 |
";
$rootDiv = 1;
$sqrDiv = 1;
if ($startingNum == 0) {
return " Too Small |
";
}
if ($startingNum < 10) {
$startingNum = 10000 * $startingNum;
$rootDiv = 100;
$sqrDiv = 10000;
} elseif ($startingNum > 999999999999) {
return " Too Big |
";
}
if ($startingNum >= 3) { // get root of starting number
$IntRoot = $this->getNextPerfectSquare($startingNum);
$nextintroot = (2 * $IntRoot + 1);
$IntSqr = $IntRoot * $IntRoot;
if ($justone == false) {
for ($i = 0; $i <= $nextintroot; $i++) {
$ApproxRoot = $this->getApproxSquareRoot($IntRoot, $i) / $rootDiv;
$ApproxSqr = $ApproxRoot * $ApproxRoot;
$TruSqr = $IntSqr / $sqrDiv;
$delta = $ApproxSqr - $TruSqr;
//echo "
Test Number: " . $IntSqr . " True Root: " . $truSqrt . " Approx Root " . $ApproxRoot . " errorx100: " . round($delta*100, 6);
$csvStr .= "" . $IntSqr / $sqrDiv . " | " . $ApproxRoot .
" | " . round($ApproxSqr, 10) . " | " . number_format(round($delta *
10000, 7), 7) . " |
"; //round($delta * 100, 9) . "
"; // echo number_format(round($delta * 100, 9) ,9);
$IntSqr++;
}
} else {
$i = $startingNum - $IntSqr;
$ApproxRoot = $this->getApproxSquareRoot($IntRoot, $i) / $rootDiv;
$ApproxSqr = $ApproxRoot * $ApproxRoot;
$TruSqr = ($IntSqr + $i) / $sqrDiv;
$delta = $ApproxSqr - $TruSqr;
//echo "
Test Number: " . $IntSqr . " True Root: " . $truSqrt . " Approx Root " . $ApproxRoot . " errorx100: " . round($delta*100, 6);
$csvStr .= "" . ($IntSqr + $i) / $sqrDiv . " | " . $ApproxRoot .
" | " . round($ApproxSqr, 10) . " | " . number_format(round($delta *
10000, 7), 7) . " |
"; //round($delta * 100, 9) . "
"; // echo number_format(round($delta * 100, 9) ,9);
}
} else
return " Too Small |
";
return $csvStr;
}
public function getRoot($justOne = true)
{
$strDisplay = "";
if ($this->rootExponent == 5) {
$strDisplay = $this->display5thRootList($this->mynumber, $justOne);
} elseif ($this->rootExponent == 3) {
$strDisplay = $this->displayCubeRootList($this->mynumber, $justOne);
} else { // 2
$strDisplay = $this->displaySquareRootList($this->mynumber, $justOne);
}
echo '';
echo '
';
echo $strDisplay;
echo "
";
echo '
';
}
public function getRootArray($startingNum = "")
{
$Number = $startingNum;
$strArray = array();
if (strlen($Number) <= 0)
$Number = $this->mynumber;
//switch case
$i = $this->rootExponent;
switch ($i) {
case 2:
echo " Square Root ";
$strArray = $this->getSquareRootArray($Number);
break;
case 3:
echo " Cube Root ";
$strArray = $this->getCubeRootArray($Number);
break;
case 5:
echo " 5th Root ";
$strArray = $this->get5thRootArray($Number);
break;
default:
$strArray["Unknown"] = "???";
break;
}
return $strArray;
}
}
/* Demo: */
//echo "";
/* $testroot = new Root66(0.9, 5);
$testroot->getRoot(true);
print_r($testroot->get5thRootArray(8888));
echo "
";
//$testroot->getRoot(false);
$testroot1 = new Root66(0.0009, 5);
$testroot1->getRoot(true);
echo "
";
$testroot2 = new Root66(4444, 2);
$ans = $testroot2->getSquareRootArray(4444);
print_r($ans);
$testroot3 = new Root66(8888, 3);
$answer = $testroot3->getCubeRootArray(8888);
print_r($answer);
echo "
";
echo ($testroot3->displayCubeRootList(8888, true));
echo ($testroot3->displayCubeRootList(8888, false));
echo "
";
echo "";
$testroot = new Root66(1.4142135623731, 2);
$testroot->getRoot();
$x = array();
$x = $testroot->getRootArray();
echo "";
print_r($x);
echo "
";
*/
?>