Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Calculating e

by mdillon (Priest)
on Jul 18, 2001 at 06:01 UTC ( #97517=note: print w/replies, xml ) Need Help??

in reply to Calculating e

i just used this with N=400 and got a 1638 decimal place e, then with N=500 and got a 2145 decimal place e:

use Math::BigFloat; $N = shift || 100; $e = Math::BigFloat->new(1); $fac = Math::BigFloat->new(1); for $i (1 .. $N) { $fac *= $i; $e += 1 / $fac; } print $e, $/;

my computer is too slow to wait for it to go any higher. i don't know how far you can take it out.

the number of digits seems to increase with the size of N but i don't know why, nor at what rate this happens.

p.s. the result of this code looks to me like e, but i have no idea how accurate it is (beyond being basically accurate, i.e. about 2.71828). i compared it to a 10000 digit calculation of e i found on the Net, and it was only the same up to about 40 decimal places. if you're doing this to get an accurate value of e for later use, i would recommend just finding a calculated and verified version of it on the web (or use the version posted by IO in another response to this parent thread, which, as far as i can tell, reliably generates the actual digits of e). if you're just doing this for fun, then have a blast.

Replies are listed 'Best First'.
Re: Re: Calculating e
by I0 (Priest) on Jul 18, 2001 at 11:19 UTC
    Unfortunately, 1/3! was only accurate to about 40 decimal places

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://97517]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2022-01-28 00:10 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (72 votes). Check out past polls.