note 92175 modified in function.bcpow by danbrown
| From: | danbrown@php.net | Date: | Mon, 13 Jul 2009 15:12:41 +0000 |
| Subject: | note 92175 modified in function.bcpow by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-158229@lists.php.net to get a copy of this message | ||
<?php
bcscale(100);
/*
* Computes the natural logarithm using a series.
* @author Thomas Oldbury.
* @license Public domain.
*/
function bcln($a, $iter = 10)
{
$result = "0.0";
for($i = 0; $i < $iter; $i++)
{
$pow = (1 + (2 * $i));
$mul = bcdiv("1.0", $pow);
$fraction = bcmul($mul, bcpow(bcsub($a, "1.0") / bcadd($a, "1.0"), $pow));
$result = bcadd($fraction, $result);
}
return bcmul("2.0", $result);
}
/*
* Computes the base2 log using baseN log.
* @note Requires above functions.
* @author Thomas Oldbury.
* @license Public domain.
*/
function bclog2($a, $iter = 10)
{
return bcdiv(bcln($a, $iter), bcln("2", $iter));
}
/*
* Computes the base10 log using baseN log.
* @note Requires above functions.
* @author Thomas Oldbury.
* @license Public domain.
*/
function bclog10($a, $iter = 10)
{
return bcdiv(bcln($a, $iter), bcln("10", $iter));
}
?>
--was--
<?php
bcscale(100);
/*
* Computes the natural logarithm using a series.
* @author Thomas Oldbury.
* @license Public domain.
*/
function bcln($a, $iter = 10)
{
$result = "0.0";
for($i = 0; $i < $iter; $i++)
{
$pow = (1 + (2 * $i));
$mul = bcdiv("1.0", $pow);
$fraction = bcmul($mul, bcpow(bcsub($a, "1.0") / bcadd($a, "1.0"), $pow));
$result = bcadd($fraction, $result);
}
return bcmul("2.0", $result);
}
/*
* Computes the base2 log using baseN log.
* @note Requires below functions.
* @author Thomas Oldbury.
* @license Public domain.
*/
function bclog2($a, $iter = 10)
{
return bcdiv(bcln($a, $iter) / bcln("2", $iter));
}
/*
* Computes the base10 log using baseN log.
* @note Requires below functions.
* @author Thomas Oldbury.
* @license Public domain.
*/
function bclog10($a, $iter = 10)
{
return bcdiv(bcln($a, $iter) / bcln("10", $iter));
}
?>
http://php.net/manual/en/function.bcpow.php