I want to calculate pi with the chudnowsky algorithm and I want it to be precise so
I tried using Decimal module but I couldnt understand how I can use it.
The code is
import decimal as dc
import math
dc.getcontext().prec = 54
sum1 = 0
for k in range(0, 100):
a = (-1)**k*(math.factorial(6*k))*(13591409+545140134*k)
b = (math.factorial(3*k))*(math.factorial(k))**(3)*(640320**(3*k))
sum1 += a/b
sum1 = sum1/(426880*dc.Decimal("10005")**(1/2))
sum1= sum1**(-1)
print(sum1)
but it gives
Exception "unhandled TypeError"
unsupported operand type(s) for ** or pow(): 'decimal.Decimal' and 'float'
I look the internet but couldnt find a good source that covers the things and gives examples. How can I square root decimals and if I want a Decimal type result and the operations to be mostly lossless how can I implement it to the code above? Its python 3.6 I am new here so I thank you for being tolerant to me.