All pastes #191506 Raw Edit

Untitled

public python v1 · immutable
·published 2006-10-05 01:33 UTC
rendered paste body
#!/usr/bin/env python# Written by Jason Jung <jrjung@gmail.com># Last modified: 2006.10.04# This is a simple script that uses the formula# pi = 4 * (4 * arctan(5, unity) - arctan(239, unity))# to calculate the value of Pi to any number of digits# The formulas for Pi were supplied by works of# Carey Bloodworth and the users of Wikipediadef arctan(x, y):  sum = xpow = y // x  z = 3  sign = -1  while 1:    xpow = xpow // (x * x)    term = xpow // z    if not term:      break    sum += sign * term    sign = -sign    z += 2  return sumdef pi(n):  y = 10**(n + 10)  pi = 16 * arctan(5, y) - 4 * arctan(239, y)  return pi // 10**10if __name__ == '__main__':  from sys import argv  print pi(int(argv[1]))