update page now

Voting

: max(six, four)?
(Example: nine)

The Note You're Voting On

kmeissen at gmx dot de
9 years ago
/*
 * Computes ln(x) very fast even with high resolution
 * uses standard log()-function to optimise convergence of
 * ln(1+x) = x - x*x/2 + x*x*x/3 - ...
 * 
 * example:
 * bcscale(1000);
 * $x = bcln("1000000");
 *
 * result:
 * $x = 13.81551055796427410410794872810618524560660893...
 * within 0.9 sec, that are 80 iterations
 * 
 * @author Klaus Meissen, Germany
 * @license Public domain
*/
function bcln($value) // value > 0
{
    $m = (string)log($value);
    $x = bcsub(bcdiv($value,bcexp($m)),"1");
    $res = "0";
    $xpow = "1";
    $i=0;
    do
    {
        $i++;
        $xpow = bcmul($xpow,$x);
        $sum = bcdiv($xpow, $i);
        if ($i%2==1)
        {
            $res = bcadd($res, $sum);
        }else{
            $res = bcsub($res, $sum);
        }
    }
    while (bccomp($sum, '0'));
    return bcadd($res,$m);
}

<< Back to user notes page

To Top