WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Fast PI calculator. Can easily find the 1000th decimal place of pi in 5 seconds.
Categories : PHP, BC math, Algorithms Click here to Update Your Picture
Chao Xu
Date : Jan 23rd 2007
Grade : 5 of 5 (graded 1 times)
Viewed : 6841
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Chao Xu
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
Like this code?
Show the author your appreciation.
 

The VERY fast pi calculator compare to any other ones ever made in PHP. On my machine, this can easily find the 1000th decimal place of pi in 5 seconds

Read though and see an example of how it works
<?
//Pi calculation code
//From Chao Xu
//At http://www.webdevlogs.com
function bcpi($precision){
   
$num = 0;$k = 0;
   
bcscale($precision+3);
   
$limit = ($precision+3)/14;
    while(
$k < $limit){
       
$num = bcadd($num,bcdiv(bcmul(bcadd('13591409',bcmul('545140134', $k)),bcmul(bcpow(-1, $k), bcfact(6*$k))),bcmul(bcmul(bcpow('640320',3*$k+1),bcsqrt('640320')), bcmul(bcfact(3*$k), bcpow(bcfact($k),3)))));
    ++
$k;
}
return
bcdiv(1,(bcmul(12,($num))),$precision);
}

function
bcfact($n){
  return (
$n == 0 || $n== 1) ? 1 : bcmul($n,bcfact($n-1));
}
?>


Usage Example
echo bcpi(30);
//out put 30 places of pi



BCrand, a function returns large random numbers
Categories : PHP, BC math, Algorithms
textwrap fill-paragraph (justification)
Categories : Strings, PHP, Algorithms
Diffusion-Limited Aggregation visualization
Categories : PHP, Graphics, Algorithms, Math.
Calculate the great circle distance between two latitude/longitudes
Categories : Algorithms, PHP
Object() = Custom __autoload + Singleton. "automagically" instantiates a class and always retuns the same instance of the same class. It's pretty useful when you want to have persistence in objects.
Categories : PHP, PHP Classes, Algorithms
Password Creator: This PHP code exmaple shows how to use bitwise operations on a single variable and using it as a flagged variable. The class generates passwords of a given length using specified characters and the flags.
Categories : PHP, PHP Classes, Algorithms, Security
A very simple way to build and do a hierarchical html categories browser without javascript , just using html php and mySql
Categories : HTML and PHP, Databases, Algorithms, PHP, MySQL
Reverse a given number
Categories : PHP, Beginner Guides, Algorithms, Math.
SHA: Implementation of the Secure Hash Algorithm in pure PHP. This is a secure one-way function that can be used to perform challenge response login algorithms over an insecure connection.
Categories : Algorithms, PHP, Security
Function that returns an IP Address if it's correct. IMPROVED!!!
Categories : PHP, Algorithms, Network
A class to put get and post variables in hidden form elements. Works on scalars, normal arrays, associative arrays.
Categories : Algorithms, Variables, Arrays, PHP, PHP Classes
A very simple and efficient split bar the B-Z bar , for mysql and php ... Tired of obfuscated code try this one ...
Categories : PHP, Databases, MySQL, Algorithms
bcadd -- Add two arbitrary precision numbers
Categories : PHP, PHP Functions, BC math
Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel
Timer - a class that uses microtime() to provide easy calculation of elapsed times
Categories : Algorithms, PHP, PHP Classes