aboutsummaryrefslogtreecommitdiffstats
path: root/awklib
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2014-10-01 22:00:11 +0300
committerArnold D. Robbins <arnold@skeeve.com>2014-10-01 22:00:11 +0300
commit96490f609bec8ee0b1827faf893d0f6daecc9a53 (patch)
tree947232c074d379c67f02313ecefa5698dfb87ee1 /awklib
parent7773dc0b5d21792fb55bc52f992c7a5b7239140f (diff)
downloadegawk-96490f609bec8ee0b1827faf893d0f6daecc9a53.tar.gz
egawk-96490f609bec8ee0b1827faf893d0f6daecc9a53.tar.bz2
egawk-96490f609bec8ee0b1827faf893d0f6daecc9a53.zip
Add pi.awk program in MPFR chapter.
Diffstat (limited to 'awklib')
-rw-r--r--awklib/eg/prog/pi.awk18
1 files changed, 18 insertions, 0 deletions
diff --git a/awklib/eg/prog/pi.awk b/awklib/eg/prog/pi.awk
new file mode 100644
index 00000000..3297beff
--- /dev/null
+++ b/awklib/eg/prog/pi.awk
@@ -0,0 +1,18 @@
+# pi.awk --- compute the digits of pi
+#
+# Katie Wasserman, katie@wass.net
+# August 2014
+
+BEGIN {
+ digits = 100000
+ two = 2 * 10 ^ digits
+ pi = two
+ for (m = digits * 4; m > 0; --m) {
+ d = m * 2 + 1
+ x = pi * m
+ div(x, d, result)
+ pi = result["quotient"]
+ pi = pi + two
+ }
+ print pi
+}