@Reference(title="Fast and accurate computation of binomial probabilities",authors="C. Loader",booktitle="",url="http://projects.scipy.org/scipy/raw-attachment/ticket/620/loader2000Fast.pdf") private static double stirlingError(double n){
  if (n < 16.0) {
    final double n2=2.0 * n;
    if (Math.floor(n2) == n2) {
      return STIRLING_EXACT_ERROR[(int)n2];
    }
 else {
      return GammaDistribution.logGamma(n + 1.0) - (n + 0.5) * Math.log(n) + n - MathUtil.LOGSQRTTWOPI;
    }
  }
  final double nn=n * n;
  if (n > 500.0) {
    return (S0 - S1 / nn) / n;
  }
  if (n > 80.0) {
    return ((S0 - (S1 - S2 / nn)) / nn) / n;
  }
  if (n > 35.0) {
    return ((S0 - (S1 - (S2 - S3 / nn) / nn) / nn) / n);
  }
  return ((S0 - (S1 - (S2 - (S3 - S4 / nn) / nn) / nn) / nn) / n);
}

@ Reference ( title = "Fast and accurate computation of binomial probabilities" , authors = "C. Loader" , booktitle = "" , url = "http://projects.scipy.org/scipy/raw-attachment/ticket/620/loader2000Fast.pdf" ) private static double stirlingError ( double n ) { if ( n < 16.0 ) { final double n2 = 2.0 * n ; if ( Math . floor ( n2 ) == n2 ) { return STIRLING_EXACT_ERROR [ ( int ) n2 ] ; } else { return GammaDistribution . logGamma ( n + 1.0 ) - ( n + 0.5 ) * Math . log ( n ) + n - MathUtil . LOGSQRTTWOPI ; } } final double nn = n * n ; if ( n > 500.0 ) { return ( S0 - S1 / nn ) / n ; } if ( n > 80.0 ) { return ( ( S0 - ( S1 - S2 / nn ) ) / nn ) / n ; } if ( n > 35.0 ) { return ( ( S0 - ( S1 - ( S2 - S3 / nn ) / nn ) / nn ) / n ) ; } return ( ( S0 - ( S1 - ( S2 - ( S3 - S4 / nn ) / nn ) / nn ) / nn ) / n ) ; }
calculates the striling error stirlerr ( n ) = ln ( n ! ) - ln ( sqrt ( 2 * pi * n ) * ( n / e ) ^ n )
