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