python 2.5 on osx
i got overflowerror: (34, 'result large') following code:
x = 1.04 in range(2, 101): x += x**i print x so instead, used code below; no error generated.
x = 0 in range(1, 101): x += 1.04**i print x the result 1287.12865279 , seems miles away maximum float. if need use different type handle floating point calculation, why latter code work while former 1 doesn't? i'm puzzled..... help&explanation on resolving error appreciated.
in first example, setting x result of calculation. use x base next loop, instead of 1.04. thus, values become large soon.
before result becomes large, x has following values:
2.1216 11.6713174057 18567.4643593 2.2068000989e+21 1.15498932026e+128
Comments
Post a Comment