question: public static double regularizedGammaP ( final double a , final double x ) { if ( Double . isInfinite ( a ) || Double . isInfinite ( x ) || ! ( a > 0.0 ) || ! ( x >= 0.0 ) ) { return Double . NaN ; } if ( x == 0.0 ) { return 0.0 ; } if ( x >= a + 1 ) { return 1.0 - regularizedGammaQ ( a , x ) ; } double term = 1.0 / a ; double sum = term ; for ( int n = 1 ; n < MAX_ITERATIONS ; n ++ ) { term = x / ( a + n ) * term ; sum = sum + term ; if ( sum == Double . POSITIVE_INFINITY ) { return 1.0 ; } if ( Math . abs ( term / sum ) < NUM_PRECISION ) { break ; } } return Math . exp ( - x + ( a * Math . log ( x ) ) - logGamma ( a ) ) * sum ; }
target:  Returns the regularized gamma function P(a, x). Includes the quadrature way of computing. TODO: find "the" most accurate version of this. We seem to agree with others for the first 10+ digits, but diverge a bit later than that.