note 92965 modified in function.sqrt by danbrown
| From: | danbrown@php.net | Date: | Mon, 17 Aug 2009 18:29:15 +0000 |
| Subject: | note 92965 modified in function.sqrt by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-159575@lists.php.net to get a copy of this message | ||
My little function to get the x'th square root of a value
<?php
/*
* Example: second square root of 256 = 8 [reverse: pow(2,8) = 256]
*/
function xsqrt($x, $value)
{
$count = 0;
do{
$value=$value/$x;
$count++;
}while($value>=$x);
return $count;
}
/* Example ip subnet: */
$net_size = 256;
$subnet = 32 - xsqrt(2, $net_size);
echo '/' . $subnet;
/* returns: /24
*/
?>
--was--
/* My little function to get the x'th square root of a value
* Example: second square root of 256 = 8 [reverse: pow(2,8) = 256]
*/
function xsqrt($x, $value)
{
$count = 0;
do{
$value=$value/$x;
$count++;
}while($value>=$x);
return $count;
}
/* Example ip subnet: */
$net_size = 256;
$subnet = 32 - xsqrt(2, $net_size);
echo '/' . $subnet;
/* returns: /24
*/
http://php.net/manual/en/function.sqrt.php