title: When I calculate a large factorial, why do I get a negative number?
body: <p>So, simple procedure, calculate a factorial number. Code is as follows.</p>
  
  <pre><code>int calcFactorial(int num)
  {
      int total = 1;
  
      if (num == 0)
      {
          return 0;
      }
  
      for (num; num &gt; 0; num--)
      {
          total *= num;
      }
  
      return total;
  }
  </code></pre>
  
  <p>Now, this works fine and dandy (There are certainly quicker and more elegant solutions, but this works for me) for most numbers. However when inputting larger numbers such as 250 it, to put it bluntly, craps out. Now, the first couple factorial "bits" for 250 are { 250, 62250, 15126750, 15438000, 3813186000 } for reference.</p>
  
  <p>My code spits out { 250, 62250, 15126750, 15438000, <strong>-481781296</strong> } which is obviously off. My first suspicion was perhaps that I had breached the limit of a 32 bit integer, but given that 2^32 is 4294967296 I don't think so. The only thing I can think of is perhaps that it breaches a <strong>signed</strong> 32-bit limit, but shouldn't it be able to think about this sort of thing? If being signed is the problem I can solve this by making the integer unsigned but this would only be a temporary solution, as the next iteration yields 938043756000 which is far above the 4294967296 limit.</p>
  
  <p>So, is my problem the signed limit? If so, what can I do to calculate large numbers (Though I've a "LargeInteger" class I made a while ago that may be suited!) without coming across this problem again?</p>