ubuntu-buildroot/output/build/host-gawk-5.2.0/awklib/eg/prog/pi.awk

19 lines
341 B
Awk
Raw Normal View History

2024-04-01 15:19:46 +00:00
# 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
intdiv0(x, d, result)
pi = result["quotient"]
pi = pi + two
}
print pi
}