quantile method
Returns the value at quantile p (0.0–1.0).
Uses nearest-rank selection on the sorted data. Values of p outside the
range are clamped to the min (p <= 0) or max (p >= 1). Returns
double.nan when there are no values.
Example:
QuantileSummaryUtils([1, 2, 3, 4]).quantile(0.5); // 2.0
Implementation
double quantile(double p) {
if (_sorted.isEmpty) return double.nan;
if (p <= 0) return _sorted.firstOrNull ?? double.nan;
if (p >= 1) return _sorted.lastOrNull ?? double.nan;
final double idx = (_sorted.length - 1) * p;
final int i = idx.floor().clamp(0, _sorted.length - 1);
return _sorted[i];
}