in commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/AbstractContinuousDistribution.java [307:331]
private double createFiniteUpperBound(final double p, final double q, boolean complement,
double lowerBound, final double mu, final double sig, final boolean chebyshevApplies) {
double upperBound;
if (chebyshevApplies) {
upperBound = mu + sig * Math.sqrt(p / q);
} else {
upperBound = Double.POSITIVE_INFINITY;
}
// Bound may have been set as infinite
if (upperBound == Double.POSITIVE_INFINITY) {
upperBound = Math.max(1, lowerBound);
if (complement) {
while (survivalProbability(upperBound) >= q) {
upperBound *= 2;
}
} else {
while (cumulativeProbability(upperBound) < p) {
upperBound *= 2;
}
}
// Ensure finite
upperBound = Math.min(upperBound, Double.MAX_VALUE);
}
return upperBound;
}