public int toBin(double x) {
            if (x < 0.0d) {
                throw new IllegalArgumentException("Values less than 0.0 not accepted.");
            } else if (x > this.max) {
                return this.bins - 1;
            } else {
                return (int) (-0.5 + 0.5 * Math.sqrt(1.0 + 8.0 * x / this.scale));
            }
        }
Create a linear bin scheme with the specified number of bins and the maximum value to be counted in the bins.

@param numBins the number of bins; must be at least 2
@param max the maximum value to be counted in the bins
clients/src/main/java/org/apache/kafka/common/metrics/stats/Histogram.java