note 119510 added to ref.bc

From: Date: Fri, 24 Jun 2016 22:05:27 +0000
Subject: note 119510 added to ref.bc
Groups: php.notes 
Request: Send a blank email to php-notes+get-205808@lists.php.net to get a copy of this message
/* * 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); } ---- Server IP: 72.52.91.14 Probable Submitter: 2003:5b:4d3d:5f00:a004:474d:3bf3:a54b ---- Manual Page -- http://php.net/manual/en/ref.bc.php Edit -- https://master.php.net/note/edit/119510 Del: integrated -- https://master.php.net/note/delete/119510/integrated Del: useless -- https://master.php.net/note/delete/119510/useless Del: bad code -- https://master.php.net/note/delete/119510/bad+code Del: spam -- https://master.php.net/note/delete/119510/spam Del: non-english -- https://master.php.net/note/delete/119510/non-english Del: in docs -- https://master.php.net/note/delete/119510/in+docs Del: other reasons-- https://master.php.net/note/delete/119510 Reject -- https://master.php.net/note/reject/119510 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#205808) next »