@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") public static double pmf(double x,int n,double p){
  if (x < 0 || x > n) {
    return 0.;
  }
  if (p <= 0.) {
    return x == 0 ? 1. : 0.;
  }
  if (p >= 1.) {
    return x == n ? 1. : 0.;
  }
  final double q=1 - p;
  if (x == 0) {
    if (p < .1) {
      return Math.exp(-devianceTerm(n,n * q) - n * p);
    }
 else {
      return Math.exp(n * Math.log(q));
    }
  }
  if (x == n) {
    if (p > .9) {
      return Math.exp(-devianceTerm(n,n * p) - n * q);
    }
 else {
      return Math.exp(n * Math.log(p));
    }
  }
  final double lc=stirlingError(n) - stirlingError(x) - stirlingError(n - x)- devianceTerm(x,n * p)- devianceTerm(n - x,n * q);
  final double f=(MathUtil.TWOPI * x * (n - x)) / n;
  return Math.exp(lc) / Math.sqrt(f);
}

@ 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" ) public static double pmf ( double x , int n , double p ) { if ( x < 0 || x > n ) { return 0. ; } if ( p <= 0. ) { return x == 0 ? 1. : 0. ; } if ( p >= 1. ) { return x == n ? 1. : 0. ; } final double q = 1 - p ; if ( x == 0 ) { if ( p < .1 ) { return Math . exp ( - devianceTerm ( n , n * q ) - n * p ) ; } else { return Math . exp ( n * Math . log ( q ) ) ; } } if ( x == n ) { if ( p > .9 ) { return Math . exp ( - devianceTerm ( n , n * p ) - n * q ) ; } else { return Math . exp ( n * Math . log ( p ) ) ; } } final double lc = stirlingError ( n ) - stirlingError ( x ) - stirlingError ( n - x ) - devianceTerm ( x , n * p ) - devianceTerm ( n - x , n * q ) ; final double f = ( MathUtil . TWOPI * x * ( n - x ) ) / n ; return Math . exp ( lc ) / Math . sqrt ( f ) ; }
poisson probability mass function ( pmf ) for integer values .
