in commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/GeometricDistribution.java [147:174]
public int inverseCumulativeProbability(double p) {
ArgumentUtils.checkProbability(p);
if (p == 1) {
return getSupportUpperBound();
}
if (p <= probabilityOfSuccess) {
return 0;
}
// p > probabilityOfSuccess
// => log(1-p) < log(1-probabilityOfSuccess);
// Both terms are negative as probabilityOfSuccess > 0.
// This should be lower bounded to (2 - 1) = 1
int x = (int) (Math.ceil(Math.log1p(-p) / log1mProbabilityOfSuccess) - 1);
// Correct rounding errors.
// This ensures x == icdf(cdf(x))
if (cumulativeProbability(x - 1) >= p) {
// No checks for x=0.
// If x=0; cdf(-1) = 0 and the condition is false as p>0 at this point.
x--;
} else if (cumulativeProbability(x) < p && x < Integer.MAX_VALUE) {
// The supported upper bound is max_value here as probabilityOfSuccess != 1
x++;
}
return x;
}