note 52859 deleted from function.sqrt by hholzgra

From: Date: Thu, 02 Aug 2012 15:37:00 +0000
Subject: note 52859 deleted from function.sqrt by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189881@lists.php.net to get a copy of this message
Note Submitter: btharper1221 at gmail dot com ---- this is something you can use if you need an exact answer to a root problem, this includes an echo outside of the function to show how it works, it will return it such as $ret[0] is the number still part of the root (this is the exactness part of it) $ret[1] is the number of roots and $ret[2] is 1 or 0, 1 being that there should be an i following the number of roots (imaginary) <?php function newrt($val,$rt){ $i = 0; if(($rt % 2 == 0) && ($val < 1)){ $i = 1; $val = (-$val); } $c = 1; if(($rt % 2 != 0) && ($val < 0)){ $c = -$c; $val = -$val; } for($d = 2; pow($d,$rt) <= abs($val); $d++){ if($val % (pow($d,$rt)) == 0){ $val = ($val/(pow($d,$rt))); $c = ($c*$d); $d--; } } $ret[0] = $val; $ret[1] = $c; $ret[2] = $i; return $ret; }//end function newrt $ret = newrt($num,$num2); if($ret[0] != 1){ if($ret[2] == 0) echo $ret[1]." roots of ".$ret[0]; if($ret[2] == 1) echo $ret[1]."<b><i>i</i></b> roots of ".$ret[0]; }elseif($ret[0] == 1){ if($ret[2] == 0) echo $ret[1]; if($ret[2] == 1) echo "$ret[1]<b><i>i</i></b>"; } ?>

« previous php.notes (#189881) next »