Advertisement
DeaD_EyE

pi

Mar 19th, 2020
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. from decimal import localcontext, Decimal
  2.  
  3.  
  4. def pi(K, prec=100):
  5.     """
  6.    https://www.davidhbailey.com//
  7.    """
  8.     with localcontext() as ctx:
  9.         ctx.prec = prec
  10.         return sum(
  11.             (Decimal(1) / Decimal(16 ** k)) * (
  12.                 +(Decimal(4) / (Decimal(8 * k) + Decimal(1)))
  13.                 -(Decimal(2) / (Decimal(8 * k) + Decimal(4)))
  14.                 -(Decimal(1) / (Decimal(8 * k) + Decimal(5)))
  15.                 -(Decimal(1) / (Decimal(8 * k) + Decimal(6)))
  16.             )
  17.             for k in range(K)
  18.         )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement