awklib/eg/prog/pi.awk
raw| 1 | # pi.awk --- compute the digits of pi |
| 2 | # |
| 3 | # Katie Wasserman, [email protected] |
| 4 | # August 2014 |
| 5 | |
| 6 | BEGIN { |
| 7 | digits = 100000 |
| 8 | two = 2 * 10 ^ digits |
| 9 | pi = two |
| 10 | for (m = digits * 4; m > 0; --m) { |
| 11 | d = m * 2 + 1 |
| 12 | x = pi * m |
| 13 | intdiv0(x, d, result) |
| 14 | pi = result["quotient"] |
| 15 | pi = pi + two |
| 16 | } |
| 17 | print pi |
| 18 | } |