title: How can I efficiently calculate the binomial cumulative distribution function?
body: <p>Let's say that I know the probability of a "success" is P.  I run the test N times, and I see S successes.  The test is akin to tossing an unevenly weighted coin (perhaps heads is a success, tails is a failure).</p>
  
  <p>I want to know the approximate probability of seeing either S successes, or a number of successes less likely than S successes.</p>
  
  <p>So for example, if P is 0.3, N is 100, and I get 20 successes, I'm looking for the probability of getting 20 <strong>or fewer</strong> successes.</p>
  
  <p>If, on the other hadn, P is 0.3, N is 100, and I get 40 successes, I'm looking for the probability of getting 40 our more successes.</p>
  
  <p>I'm aware that this problem relates to finding the area under a binomial curve, however:</p>
  
  <ol>
  <li>My math-fu is not up to the task of translating this knowledge into efficient code</li>
  <li>While I understand a binomial curve would give an exact result, I get the impression that it would be inherently inefficient.  A fast method to calculate an approximate result would suffice.</li>
  </ol>
  
  <p>I should stress that this computation has to be fast, and should ideally be determinable with standard 64 or 128 bit floating point computation.</p>
  
  <p>I'm looking for a function that takes P, S, and N - and returns a probability.  As I'm more familiar with code than mathematical notation, I'd prefer that any answers employ pseudo-code or code.</p>