Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 32,536 of 33,346    |
|    MiB to All    |
|    Re: Probability Methods - Factorial    |
|    16 Sep 12 00:46:33    |
   
   From: Michael.Boehnisch@googlemail.com   
      
   { Please limit your text to fit within 80 columns, preferably around 70,   
    so that readers don't have to scroll horizontally to read each line.   
    This article has been reformatted manually by the moderator. -mod }   
      
   Am Sonntag, 16. September 2012 00:02:10 UTC+2 schrieb TheGunslinger:   
   > I want to implement the use of '!' for recognizing and calculating the   
   > factorial of a number, n.   
   >   
   > I am unable to find a reference to this as being a standard call   
   > within C++.   
   >   
   > Is it contained within a specific library? Or do I, instead, need to   
   > implement an my own algorithm for this?   
   >   
   > I cannot believe it is not included in an STL someplace?   
      
   With 64-bit integers you can handle 0! ... 20! only; how about storing   
   the 21 results in an array and retrieving them from there instead of   
   numeric calculation?   
      
   With real number arithmetic you'll lose the least significant digits.   
   But even then you'd need 100-odd storage places only to reach the sky.   
      
   Here is a 3-liner to do the task with numeric calculation, if you insist:   
      
   unsigned int factorial( unsigned int n ) {   
    return ( n < 2 ) ? 1 : n * factorial(n - 1);   
   }   
      
   just my €.02   
   MiB.   
      
      
   --   
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca