Followed by this discussion on Hacker News<http://news.ycombinator.com/item?id=958323>I checked this link <http://www.isotf.org/?page_value=13223> and was wondering how to calculate value of 'e' <http://mathworld.wolfram.com/e.html> to a large extent
as e = 1/0! + 1/1! +1/2! .... and so on... so i wrote this: >>> sum(1.0 / math.factorial(i) for i in range(100)) 2.7182818284590455 It was not giving the precision that I wanted so I tried decimal module of which I was not much aware of. >>> decimal.getcontext().prec = 100 >>> sum(decimal.Decimal(str(1./math.factorial(decimal.Decimal(i)))) for i in range(100)) Decimal('2.718281828459409995603699925637255290043107782360218523330012825771122202286299367023903783933889309') Until now no problem I matched the value of 'e' from here<http://dl.dropbox.com/u/59605/ten_million_e.txt> which claims it have 10 million digits of e the first few digits of 'e' from there which doesn't match with the result I got: 2.71828182845904523536028747135266249775724709369995957496696762772407 so i tried, >>> sum(decimal.Decimal(str(1./math.factorial(decimal.Decimal(i)))) for i in range(1000)) Traceback (most recent call last): File "<input>", line 1, in <module> File "<input>", line 2, in <genexpr> OverflowError: long int too large to convert to float And then i went clueless !! How can it be done ?
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor