Skip to main content

percentile

Function percentile 

Source
pub fn percentile(sorted_values: &[f64], pct: f64) -> f64
Expand description

Return the value at the (n * pct) as usize index of sorted_values, or 0.0 if out of bounds. Inputs must be pre-sorted ascending.

ยงExamples

use codetether_agent::telemetry::provider::stats::percentile;

let xs = [1.0, 2.0, 3.0, 4.0, 5.0];
assert_eq!(percentile(&xs, 0.50), 3.0);
assert_eq!(percentile(&xs, 0.95), 5.0);
assert_eq!(percentile(&[], 0.50), 0.0);