in commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/HypergeometricDistribution.java [384:402]
private int inverseUpper(double p, double q, boolean complement) {
// Sum from the upper bound (computing the sf)
int x = upperBound;
final DoublePredicate test = complement ?
i -> i < q :
i -> 1 - i > p;
double sf = 0;
while (test.test(sf)) {
sf += Math.exp(computeLogProbability(x));
x--;
}
// Here either sf(x) >= q, or cdf(x) <= p
// Ensure sf(x) <= q, or cdf(x) >= p
if (complement && sf > q ||
!complement && 1 - sf < p) {
x++;
}
return x;
}