Skip to content

Instantly share code, notes, and snippets.

@mo271
Last active November 5, 2022 20:33
Show Gist options
  • Save mo271/5224cd4e514a1b76ca6eeea5d7ca2b3d to your computer and use it in GitHub Desktop.
Save mo271/5224cd4e514a1b76ca6eeea5d7ca2b3d to your computer and use it in GitHub Desktop.
from codetiming import Timer
from decimal import Decimal, getcontext
@Timer()
def BBPzeta2(n: int) -> Decimal:
s = Decimal(0)
f = Decimal(1)
# TODO: figure out exactly how fast this converges,
# but I think math.log(10, 64) should be the right factor here
for k in range(int(n*0.5536546824812272) + 1):
sixk = Decimal(6)*Decimal(k)
s += f*( Decimal(16)/ (sixk + 1)**2
- Decimal(24)/ (sixk + 2)**2
- Decimal(8) / (sixk + 3)**2
- Decimal(6) / (sixk + 4)**2
+ Decimal(1) / (sixk + 5)**2)
f *= Decimal(1)/Decimal(64)
return Decimal(3)/Decimal(16)*s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment