public static double logGamma(final double x){
  if (Double.isNaN(x) || (x <= 0.0)) {
    return Double.NaN;
  }
  double g=607.0 / 128.0;
  double tmp=x + g + .5;
  tmp=(x + 0.5) * Math.log(tmp) - tmp;
  double ser=LANCZOS[0];
  for (int i=LANCZOS.length - 1; i > 0; --i) {
    ser+=LANCZOS[i] / (x + i);
  }
  return tmp + Math.log(MathUtil.SQRTTWOPI * ser / x);
}

public static double logGamma ( final double x ) { if ( Double . isNaN ( x ) || ( x <= 0.0 ) ) { return Double . NaN ; } double g = 607.0 / 128.0 ; double tmp = x + g + .5 ; tmp = ( x + 0.5 ) * Math . log ( tmp ) - tmp ; double ser = LANCZOS [ 0 ] ; for ( int i = LANCZOS . length - 1 ; i > 0 ; -- i ) { ser += LANCZOS [ i ] / ( x + i ) ; } return tmp + Math . log ( MathUtil . SQRTTWOPI * ser / x ) ; }
compute loggamma . based loosely on " numerical recpies " and the work of paul godfrey at http : / / my . fit . edu / ~ gabdo / gamma . txt todo : find out which approximation really is the best . . .
