The goal of this project is to enumerate (and implement) all known ways to calculate an approximated value of PI.
Despite the name, there are only 14 algorithms currently implemented. Here they are in alphabetical order.
| Name | Type |
|---|---|
| Bayley | Iteration-based |
| Chebyshev | Iteration-based |
| Continuos fraction | Iteration-based |
| Gauss | EPS-based |
| Grid | EPS-based |
| Leibniz | Iteration-based |
| Montecarlo circle | Point-based |
| Montecarlo sphere | Point-based |
| Newton | Iteration-based |
| Polygon | Point-based |
| Recursive 4-splitting | EPS-based |
| Recursive binary-search | EPS-based |
| Row-wise binary-search | EPS-based |
| Viete | Iteration-based |
montecarlo_circleperforms the classic Montecarlo method of calculating the ratio between the area of the unit circle and the area of its circumscribed square.gridperforms a "deterministic" version of the Montecarlo method: instead of generating some random points, considers all points at fixed locations.montecarlo_sphereperforms the same algorithm ofmontecarlo_circle, but with a sphere inside a cube.recursive_4_splittingperforms a recursive call (each time splitting the area 4 times) to find the area of the quarter-circle in the first quadrant.row_binary_searchworks on the first quadrant section of the unit circle, for each row it binary-searches for the border of the circle and then adds together all those little slices to compute the area of the unit circle.recursive_binary_search_2dis an improvement ofrecursive_4_splittingby using binary search to find the border of the circle.gauss_integralcomputes the integral ofexp(-x*x), which tends towardssqrt(pi).continuous_fractioncomputes the value of a continuous fraction with a depth limit.vietecomputes the infinite product of Viete's formula.leibnizcomputes the infinite sum of Leibniz's formula.baileycomputes the infinite sum of Bailey-Borwein-Plouffe's formula.newtoncomputes the infinite sum of Newton's factorial's formula.chebyshevcomputes the infinite sum of Chebyshev's formula.polygoncomputes the area of the unit circle approximating it as a polygon.
All the following methods have been executed using EPS=1e-8. The relative error is calculated using the macro M_PI defined in math.h.
| Method | Correct digits | Relative Error | WCT |
|---|---|---|---|
| Deterministic Montecarlo | |||
| Gauss | |||
| Recursive 4-splitting | |||
| Recursive binary-search | |||
| Row-wise binary-search |
All the following methods have been executed using steps=20. The relative error is calculated using the macro M_PI defined in math.h.
| Method | Correct digits | Relative Error | WCT |
|---|---|---|---|
| Bayley | |||
| Chebyshev | |||
| Continuous fraction | |||
| Leibniz | |||
| Newton | |||
| Viete |
All the following methods have been executed using points=1000. The relative error is calculated using the macro M_PI defined in math.h.
| Method | Correct digits | Relative Error | WCT |
|---|---|---|---|
| Montecarlo circle | |||
| Montecarlo sphere | |||
| Polygon |
Each one of these programs is really simple and requires at most two hours of work. In that little time, some bugs can appear unnoticed so if you happen to find one, please let me know. If you want to contribute, feel free to do so.