private double compute()

in commons-statistics-descriptive/src/main/java/org/apache/commons/statistics/descriptive/Quantile.java [441:474]


    private double compute(int[] values, int from, int to, double p) {
        checkProbability(p);
        final int n = to - from;
        // Special cases
        if (n <= 1) {
            return n == 0 ? Double.NaN : values[from];
        }

        // Create the range
        final int[] x;
        final int start;
        final int end;
        if (copy) {
            x = Statistics.copy(values, from, to);
            start = 0;
            end = n;
        } else {
            x = values;
            start = from;
            end = to;
        }

        final double pos = estimationType.index(p, n);
        final int ip = (int) pos;
        final int i = start + ip;

        // Partition and compute
        if (pos > ip) {
            Selection.select(x, start, end, new int[] {i, i + 1});
            return Interpolation.interpolate(x[i], x[i + 1], pos - ip);
        }
        Selection.select(x, start, end, i);
        return x[i];
    }