public double quantile(double q) {
    assert(bins != null && nusedbins > 0 && nbins > 0);
    double sum = 0, csum = 0;
    int b;
    for(b = 0; b < nusedbins; b++)  {
      sum += bins.get(b).y;
    }
    for(b = 0; b < nusedbins; b++) {
      csum += bins.get(b).y;
      if(csum / sum >= q) {
        if(b == 0) {
          return bins.get(b).x;
        }

        csum -= bins.get(b).y;
        double r = bins.get(b-1).x +
          (q*sum - csum) * (bins.get(b).x - bins.get(b-1).x)/(bins.get(b).y);
        return r;
      }
    }
    return -1; // for Xlint, code will never reach here
  }
Gets an approximate quantile value from the current histogram. Some popular
quantiles are 0.5 (median), 0.95, and 0.98.

@param q The requested quantile, must be strictly within the range (0,1).
@return The quantile value.
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/NumericHistogram.java