Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Re: Calculating e by mdillon
in thread Calculating e by sifukurt

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others browsing the Monastery: (1)
    As of 2024-09-11 01:35 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      The PerlMonks site front end has:





      Results (10 votes). Check out past polls.

      Notices?
      erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.