note 52859 added to function.sqrt

From: Date: Sun, 15 May 2005 15:48:50 +0000
Subject: note 52859 added to function.sqrt
Groups: php.notes 
Request: Send a blank email to php-notes+get-89455@lists.php.net to get a copy of this message
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>"; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.sqrt.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+52859 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52859&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52859&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52859&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52859&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52859&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+52859&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#89455) next »