note 72691 added to ref.bc

From: Date: Tue, 30 Jan 2007 02:52:47 +0000
Subject: note 72691 added to ref.bc
Groups: php.notes 
Request: Send a blank email to php-notes+get-122340@lists.php.net to get a copy of this message
I wrote this function with many BCMath functions. It should be the fastest function in PHP to find the number pi into any precision, my test is it generate 2000 digits after the dot in 8 seconds. I don't think you need anything more than that. <?php //bcpi function with Gauss-Legendre algorithm //by Chao Xu (Mgccl) function bcpi($precision){ $limit = ceil(log($precision)/log(2))-1; bcscale($precision+6); $a = 1; $b = bcdiv(1,bcsqrt(2)); $t = 1/4; $p = 1; while($n < $limit){ $x = bcdiv(bcadd($a,$b),2); $y = bcsqrt(bcmul($a, $b)); $t = bcsub($t, bcmul($p,bcpow(bcsub($a,$x),2))); $a = $x; $b = $y; $p = bcmul(2,$p); ++$n; } return bcdiv(bcpow(bcadd($a, $b),2),bcmul(4,$t),$precision); } ?> ---- Server IP: 64.71.164.2 Probable Submitter: 141.155.11.236 ---- Manual Page -- http://www.php.net/manual/en/ref.bc.php Edit -- https://master.php.net/note/edit/72691 Del: integrated -- https://master.php.net/note/delete/72691/integrated Del: useless -- https://master.php.net/note/delete/72691/useless Del: bad code -- https://master.php.net/note/delete/72691/bad+code Del: spam -- https://master.php.net/note/delete/72691/spam Del: non-english -- https://master.php.net/note/delete/72691/non-english Del: in docs -- https://master.php.net/note/delete/72691/in+docs Del: other reasons-- https://master.php.net/note/delete/72691 Reject -- https://master.php.net/note/reject/72691 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#122340) next »