diff options
| author | ArcaneDev <alive6863@gmail.com> | 2025-09-13 18:22:56 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-13 18:22:56 +0300 |
| commit | a4b503fd2860039da30bb454262efbd3763fac6f (patch) | |
| tree | 073795a2cee682e98664a58f0a8e56781772d45f | |
| parent | 76b182b60c1a9043f3a6ad8abbf7ea5ea570ca16 (diff) | |
Update README.md
| -rw-r--r-- | README.md | 38 |
1 files changed, 37 insertions, 1 deletions
@@ -1,2 +1,38 @@ # CLI-pi -tpi -- C-written, MPFR-based CLI program for calculating pi +**tpi - C-written, MPFR-based CLI program for calculating pi** + +> [!WARNING] +> For the accuracy of calculations, a large MPFR library is used, there may be delays and high processor loads on weak systems. + +The program calculates the pi number with high accuracy. + +In infinite mode, something like AOT compilation is used, first ~10 million decimal places are calculated, and then they are converted to `char[]` through the same MPFR. + +$$100,000,000 \text{ ms} = 100,000 \text{ s} = \frac{100,000}{3600} \text{ hours} \approx 27.78 \text{ h}$$ + +But if you need more, you can change the len variable and recompile the project with `build.sh` for yourself by setting a different limit. Be careful, the CPU load will be higher. + +# How does the calculation work? +Calculations are performed using the Gauss method, which is based on the use of integrals and properties of elliptic integrals. This method, also known as the Gauss-Legandre method, makes it possible to calculate pi with high accuracy using an iterative process. + +$$\pi \approx \frac{(a_n + b_n)^2}{4 t_n}$$ + +In python it looks like: +```python +def gauss_pi(iterations): + a = 1.0 + b = 1.0 / math.sqrt(2) + t = 1.0 / 4.0 + p = 1.0 + + for _ in range(iterations): + a_next = (a + b) / 2 + b = math.sqrt(a * b) + t -= p * (a - a_next) ** 2 + a = a_next + p *= 2 + + return (a + b) ** 2 / (4 * t) +``` + +I'm not giving an example from my code because the gnu MPFR syntax is unreadable without an armed eye. |
