summaryrefslogtreecommitdiff
path: root/pi.awk
diff options
context:
space:
mode:
Diffstat (limited to 'pi.awk')
-rw-r--r--pi.awk5
1 files changed, 4 insertions, 1 deletions
diff --git a/pi.awk b/pi.awk
index 69eb36e..0a529f8 100644
--- a/pi.awk
+++ b/pi.awk
@@ -1,4 +1,4 @@
-#! /usr/bin/awk -f
+#!/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
@@ -11,11 +11,14 @@
# 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())
}
+