2013-07-19 09:35:58
1
python 2.5 on osx
I got the OverflowError: (34, 'Result too large') for the following code:
x = 1.04
for i in range(2, 101):
x += x**i
print x
So instead, I used the code below; no error was generated.
x = 0
for i in range(1, 101):
x += 1.04**i
print x
The result is 1287.12865279 and this seems miles away from the maximum float. If I need to use a different type to handle this floating point calculation, why does the latter code work while the former one doesn't? I'm puzzled..... Any help&explanation on resolving the error would be much appreciated.