Return the cached value if available.
Otherwise, we need to synchronize access to the underlying {@link Histogram}
@param percentile percentile of distribution
@return value at percentile (from cache if possible)
491219
public int getValueAtPercentile(double percentile) {
        int permyriad = (int) (percentile * 100);
        switch (permyriad) {
            case 0: return p0;
            case 500: return p5;
            case 1000: return p10;
            case 1500: return p15;
            case 2000: return p20;
            case 2500: return p25;
            case 3000: return p30;
            case 3500: return p35;
            case 4000: return p40;
            case 4500: return p45;
            case 5000: return p50;
            case 5500: return p55;
            case 6000: return p60;
            case 6500: return p65;
            case 7000: return p70;
            case 7500: return p75;
            case 8000: return p80;
            case 8500: return p85;
            case 9000: return p90;
            case 9500: return p95;
            case 9900: return p99;
            case 9950: return p99_5;
            case 9990: return p99_9;
            case 9995: return p99_95;
            case 9999: return p99_99;
            case 10000: return p100;
            default: throw new IllegalArgumentException("Percentile (" + percentile + ") is not currently cached");
        }
    }
186479
public final Latency withPercentile999th(double value) {
    double newValue = value;
    return new Latency(this.median, this.percentile98th, this.percentile99th, newValue, this.mean, this.min, this.max);
  }
350847
protected int getCenterChild(CacheDataSet cache) {
        if (cache.count() == 0)
            return -1;

        int id = cache.getId(0);
        switch (getGravityInternal()) {
            case TOP:
            case LEFT:
            case FRONT:
            case FILL:
                break;
            case BOTTOM:
            case RIGHT:
            case BACK:
                id = cache.getId(cache.count() - 1);
                break;
            case CENTER:
                int i = cache.count() / 2;
                while (i < cache.count() && i >= 0) {
                    id =  cache.getId(i);
                    if (cache.getStartDataOffset(id) <= 0) {
                        if (cache.getEndDataOffset(id) >= 0) {
                            break;
                        } else {
                            i++;
                        }
                    } else {
                        i--;
                    }
                }
                break;
            default:
                break;
        }

        Log.d(LAYOUT, TAG, "getCenterChild = %d ", id);
        return id;
    }
772370
def winsorize(row, min_percentile, max_percentile):
    
    a = row.copy()
    nan_count = isnan(row).sum()
    nonnan_count = a.size - nan_count

    # NOTE: argsort() sorts nans to the end of the array.
    idx = a.argsort()

    # Set values at indices below the min percentile to the value of the entry
    # at the cutoff.
    if min_percentile > 0:
        lower_cutoff = int(min_percentile * nonnan_count)
        a[idx[:lower_cutoff]] = a[idx[lower_cutoff]]

    # Set values at indices above the max percentile to the value of the entry
    # at the cutoff.
    if max_percentile < 1:
        upper_cutoff = int(ceil(nonnan_count * max_percentile))
        # if max_percentile is close to 1, then upper_cutoff might not
        # remove any values.
        if upper_cutoff < nonnan_count:
            start_of_nans = (-nan_count) if nan_count else None
            a[idx[upper_cutoff:start_of_nans]] = a[idx[upper_cutoff - 1]]

    return a
749592
public V getSilent(K key) {
        V value = cache.get(key);
        if (value != null) {
            cache.remove(key);
            cache.put(key, value);
        }
        return value;
    }
109953
def _at_percentile(tau, var_tau, percentile):
    
    assert (percentile >= 0.0) and (percentile <= 1.0)
    c_val = _scaling(tau, var_tau)
    k_val = _dof(tau, var_tau)
    return np.sqrt(c_val * chi2.ppf(percentile, df=k_val))
371644
func (h *Hist) PercentileVal(p float64) HistVal {
	p = math.Min(p, 100)
	desiredCount := int64((p/100)*float64(h.totalCount) + 0.5)
	if desiredCount < 1 {
		desiredCount = 1
	}
	var total int64
	for i, count := range h.b.counts {
		total += count
		if total >= desiredCount {
			v := h.b.valueFor(i)
			if p == 0 {
				v = h.b.lowestEquiv(v)
			} else {
				v = h.b.highestEquiv(v)
			}
			percentile := (100 * float64(total)) / float64(h.totalCount)
			if h.totalCount == 0 {
				percentile = 100
			}
			return HistVal{
				Value:      v,
				Count:      count,
				CumCount:   total,
				Percentile: percentile,
			}
		}
	}
	return HistVal{
		Value:      0,
		Count:      0,
		CumCount:   0,
		Percentile: 0,
	}
}
635518
public void setPercentiles( String percentiles )
    {
        if( percentiles == null ) percentiles = "";
        
        String[] percList = percentiles.split(",");
        double[] percs = new double[percList.length];
        
        for( int i = 0; i < percList.length; i++ )
            percs[i] = Double.parseDouble( percList[i] );
        
        m_percentiles = percs;
        
        rebuildJmx();
    }
1085251
func percentile(
	vals sort.IntSlice,
	n int) (x int) {
	// Special cases.
	switch {
	case n == 0:
		x = vals[0]
		return

	case n == 100:
		x = vals[len(vals)-1]
		return
	}

	// Find the nearest, truncating (why not).
	index := int((float64(n) / 100) * float64(len(vals)))
	x = vals[index]

	return
}
143973
@Monitor(name = "ResponseTimeMillis50Percentile", type = DataSourceType.INFORMATIONAL,
             description = "50th percentile in total time to handle a request, in milliseconds")
    public double getResponseTime50thPercentile() {
        return getResponseTimePercentile(Percent.FIFTY);
    }
458153
func (f Float64Data) Percentile(p float64) (float64, error) {
	return Percentile(f, p)
}
518551
def percentiles(self, percentiles):
    """"""
    try:
      scores = [0.0]*len(percentiles)

      if self.count > 0:
        values = self.samples()
        values.sort()

        for i in range(len(percentiles)):
          p = percentiles[i]
          pos = p * (len(values) + 1)
          if pos < 1:
            scores[i] = values[0]
          elif pos > len(values):
            scores[i] = values[-1]
          else:
            upper, lower = values[int(pos - 1)], values[int(pos)]
            scores[i] = lower + (pos - floor(pos)) * (upper - lower)

      return scores
    except IndexError:
      return [float('NaN')] * len(percentiles)
487662
def parse_histogram(metric, histogram):
    """"""
    for match in HISTOGRAM.finditer(histogram):
        percentile, value = match.groups()
        value = float(value)

        if not isnan(value):
            try:
                yield metric + PERCENTILE_SUFFIX[percentile], value

            # In case Envoy adds more
            except KeyError:
                yield '{}.{}percentile'.format(metric, percentile[1:].replace('.', '_')), value
110262
public static Number getPercentileValue(int targetPercentile,
            List<Number> unorderedNumberList) {
        return getPercentileValueWithSorted(targetPercentile,
                sortedDoubleList(unorderedNumberList));
    }
224863
def percentile(self, percentile):
        
        assert(percentile >= 0 and percentile <= 100)
        assert(self.kind in ["exponential", "linear", "enumerated", "boolean"])

        fraction = percentile / 100
        to_count = fraction * self.buckets.sum()
        percentile_bucket = 0

        for percentile_bucket in range(len(self.buckets)):
            freq = self.buckets.values[percentile_bucket]
            if to_count - freq <= 0:
                break
            to_count -= freq

        percentile_lower_boundary = self.buckets.index[percentile_bucket]
        percentile_frequency = self.buckets.values[percentile_bucket]

        if percentile_bucket == len(self.buckets) - 1 or percentile_frequency == 0:
            return percentile_lower_boundary

        width = self.buckets.index[percentile_bucket + 1] - self.buckets.index[percentile_bucket]
        return percentile_lower_boundary + width * to_count / percentile_frequency
123097
func (r *Timing) Percentile(p float64) uint32 {
	sortedDurations := r.SortedDurations()
	length := len(sortedDurations)
	if length <= 0 {
		return 0
	}

	pos := r.ordinal(len(sortedDurations), p) - 1
	return uint32(sortedDurations[pos].Nanoseconds() / 1000000)
}
534229
public static <T> Collector<T, ?, Optional<T>> percentile(double percentile, Comparator<? super T> comparator) {
        return percentile(percentile, t -> t, comparator);
    }