-
Notifications
You must be signed in to change notification settings - Fork 0
Scripts Fun
Quadstronaut edited this page Jun 7, 2026
·
1 revision
Scripts in Scripts/Fun/. Educational demonstrations and curiosities.
What it does: Approximates Pi using the Leibniz formula:
π/4 = 1 - 1/3 + 1/5 - 1/7 + 1/9 - ...
More iterations produce a closer approximation, at the cost of CPU time.
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
-Iterations |
int |
1,000,000 |
Number of terms to sum |
Usage:
# Default: 1,000,000 iterations
.\Scripts\Fun\Get-PiApproximation.ps1
# Higher accuracy (slower)
.\Scripts\Fun\Get-PiApproximation.ps1 -Iterations 10000000Example output:
Pi is approximately 3.14159165358979 (after 1,000,000 iterations)
True Pi: 3.14159265358979323846...
Error: 9.99999994515327E-07
Notes on convergence:
The Leibniz formula converges very slowly. Each additional correct decimal digit requires roughly 10× more terms:
| Iterations | Correct digits (approx.) |
|---|---|
| 1,000 | ~3 |
| 1,000,000 | ~6 |
| 1,000,000,000 | ~9 |
For faster convergence, see:
-
Machin's formula —
π/4 = 4·arctan(1/5) - arctan(1/239) - Bailey–Borwein–Plouffe (BBP) formula — can compute any hexadecimal digit of Pi without computing prior digits
Educational purpose: This script demonstrates iterative approximation, floating-point arithmetic, alternating series, and the relationship between series convergence rate and computational cost. It is not useful for computing Pi to high precision.