Re: [Tutor] value of 'e'

2009-11-24 Thread Lie Ryan
Wayne Werner wrote: You might try writing your own factorial function that works with the decimal type and compare with the result you get from using the math library. There is no need for that, math.factorial will use python int/long object instead of the platform's integer as necessary.

Re: [Tutor] value of 'e'

2009-11-24 Thread Kent Johnson
On Tue, Nov 24, 2009 at 7:01 AM, Wayne Werner wrote: > Well, upon inspection it seems that "The math module consists mostly of thin > wrappers around the platform C math library functions" - one would presume > those are accurate, but I don't know to how many places. You might try > writing your

Re: [Tutor] value of 'e'

2009-11-24 Thread Kent Johnson
On Tue, Nov 24, 2009 at 7:19 AM, Lie Ryan wrote: > Shashwat Anand wrote: >> >> How can it be done ? > import decimal, math D = decimal.Decimal decimal.getcontext().prec = 100 sum(D(1) / D(math.factorial(i)) for i in range(1000)) > Decimal('2.718281828459045235360287471352662497

Re: [Tutor] value of 'e'

2009-11-24 Thread Kent Johnson
On Tue, Nov 24, 2009 at 6:47 AM, Shashwat Anand wrote: > Followed by this discussion on Hacker News I checked this link and was > wondering how to calculate value of 'e' 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 ra

Re: [Tutor] value of 'e'

2009-11-24 Thread Lie Ryan
Shashwat Anand wrote: How can it be done ? >>> import decimal, math >>> D = decimal.Decimal >>> decimal.getcontext().prec = 100 >>> sum(D(1) / D(math.factorial(i)) for i in range(1000)) Decimal('2.718281828459045235360287471352662497757247093699959574966967627724076 6303535475945713821785251664

Re: [Tutor] value of 'e'

2009-11-24 Thread Wayne Werner
On Tue, Nov 24, 2009 at 5:47 AM, Shashwat Anand wrote: > > And then i went clueless !! > How can it be done ? > Well, upon inspection it seems that "The math module consists mostly of thin wrappers around the platform C math library functions" - one would presume those are accurate, but I don't k

[Tutor] value of 'e'

2009-11-24 Thread Shashwat Anand
Followed by this discussion on Hacker NewsI checked this link and was wondering how to calculate value of 'e' to a large extent as e = 1/0! + 1/1! +1/2! and so on... so i