Reputation: 135
I've been checking some topics around here about the same problem I'm getting but they don't seem to help.
My problem is when I try to execute the following code, I get the error found in the title. How do I go around this?
d=2
while(n != 1):
n = 2
d = (math.sqrt(2 + d))
n= (n/d)
f = (f * (n))
print (f)
Upvotes: 1
Views: 4682
Reputation: 4079
That's because math.sqrt, as a consequence of using the C sqrt function, works on floating point number which are not unlimited in size. Python is unable to convert the long integer into a floating point number because it is to big. See this question on ways to square root large integers.
Better, you could use the decimal module, which is an unlimited size number type stored in base-10. Use decimal.Decimal(number).sqrt()
to find the sqrt of a number.
Upvotes: 3