note 47682 added to ref.bc
| From: | stonehewutgmaildetcom at osu1 dot php dot net | Date: | Thu, 25 Nov 2004 05:31:58 +0000 |
| Subject: | note 47682 added to ref.bc | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-81001@lists.php.net to get a copy of this message | ||
Like any other bc function, you can't trust the last couple of digits, but everything else
seems to check out. If you want to use this for anything important, you may want to verify this
against other sources of pi before use. This function calculates 100 decimal places of pi in 329
iterations -- not exactly fast (each iteration calls the factorial function, from below, twice), so
I try to avoid calling it more than once.
<?
//arbitrary precision pi approximator
//author tom boothby
//free for any use
function bcpi() {
$r=2;
$i=0;
$or=0;
while(bccomp($or,$r)) {
$i++;
$or=$r;
$r = bcadd($r,bcdiv(bcmul(bcpow(bcfact($i),2),
bcpow(2,$i+1)),bcfact(2*$i+1)));
}
return $r;
}
?>
----
Manual Page -- http://www.php.net/manual/en/ref.bc.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47682
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47682&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47682&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47682&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47682&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47682&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47682&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47682&report=yes
Search -- http://master.php.net/manage/user-notes.php