summaryrefslogtreecommitdiff
path: root/pi.awk
diff options
context:
space:
mode:
authorwukong <wukong@longaeva>2018-06-05 22:34:51 -0700
committerwukong <wukong@longaeva>2018-06-05 22:34:51 -0700
commit8f263e859e0970ce87b77addc80dec28e8fc7e82 (patch)
treeb0bdc392230c9960f5e5f5b3dea979405334628f /pi.awk
re-init
Diffstat (limited to 'pi.awk')
-rw-r--r--pi.awk24
1 files changed, 24 insertions, 0 deletions
diff --git a/pi.awk b/pi.awk
new file mode 100644
index 0000000..7ecc4ab
--- /dev/null
+++ b/pi.awk
@@ -0,0 +1,24 @@
+
+### 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 {
+ if (ARGV[1] > 0)
+ fig = ARGV[1]
+ else
+ fig = 6
+ str = "%." fig "g\n"
+ printf(str, pi())
+}