You can use "memoize" to improve that, or make a new calculation build on the highest one it already knows

Your code will give inaccurate results once the number of non-zero leading digits exceeds that of the floating point precision. Try using BigInt in your code and see if the results near the top of your range are any different, and notice that you can keep going!

170! = 7.25741561530799e+306

170! = 7257415615 3079989673 9672821112 9263114716 9916812964 5137654357 7798900561 8434017061 5785235074 9242617459 5114909912 3783852077 666602256544 275302532890 0773207510 9024004302 8005829560 3966612599 6582571043 9855829425 7568966313 439612262571094946806711205568880457193340212661452800000000000000000000000000000000000000000

So, I guess 170! is indeed accurate to 15 decimal digits when using floating point.

But 200! = 7886578673647905035523632139321850622951359 7768717326329474253324435944996340334292030428 4011984623904177212138919638830257642790242637 105061926624952829931113462857270763 317237396988943922445621451 66424025403329186413122742829485327 752424240757390324032125740557956 866022603190417032406235170085879 6178922222789623703897374720000000000000000000000000000000000000000000000000

Years ago, I got around the overflow by using logs. It's interesting to play with.


In reply to Re^2: Floating point factorials by John M. Dlugosz
in thread Floating point factorials by Microcebus

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, details, 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, summary, 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.