in commons-numbers-gamma/src/main/java/org/apache/commons/numbers/gamma/BoostGamma.java [1136:1167]
static double gammaPDerivative(double a, double x) {
//
// Usual error checks first:
//
if (Double.isNaN(a) || Double.isNaN(x) || a <= 0 || x < 0) {
return Double.NaN;
}
//
// Now special cases:
//
if (x == 0) {
if (a > 1) {
return 0;
}
return (a == 1) ? 1 : Double.POSITIVE_INFINITY;
}
//
// Normal case:
//
double f1 = regularisedGammaPrefix(a, x);
if (f1 == 0) {
// Underflow in calculation, use logs instead:
f1 = a * Math.log(x) - x - lgamma(a) - Math.log(x);
f1 = Math.exp(f1);
} else {
// Will overflow when (x < 1) && (Double.MAX_VALUE * x < f1).
// There is no exception for this case so just return the result.
f1 /= x;
}
return f1;
}