blob: 0a529f833e2f6e9eae2e37fb49c977c27ffe55e3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#!/usr/bin/awk -f
### pi.awk, https://en.wikipedia.org/wiki/Pi
# In 1706 John Machin used the Gregory–Leibniz series to produce an algorithm
# that converged much faster. Machin reached 100 digits of π with this
# formula. Other mathematicians created variants, now known as Machin-like
# formulae, that were used to set several successive records for calculating
# digits of π. Machin-like formulae remained the best-known method for
# calculating π well into the age of computers, and were used to set records
# for 250 years, culminating in a 620-digit approximation in 1946 by Daniel
# Ferguson–the best approximation achieved without the aid of a calculating
# device.
function pi() {
return 4*(4*atan2(1,5) - atan2(1,239))
}
BEGIN {
ARGV[1] ? OFMT = "%." ARGV[1] "g" : OFMT = "%g"
printf(OFMT ORS, pi())
}
|