MathUtils { public static double quantile(List<Double> values, double q) { double a = 1.0, b = -1.0, c = 0.0, d = 1.0; int n = values.size(); double x = a + (n + b) * q - 1.0; double xInt = (int) x; double xFrac = x - xInt; if (xInt < 0) { return values.get(0); } else if (xInt >= n) { return values.get(n - 1); } int i = (int) xInt; if (xFrac == 0) { return values.get(i); } return values.get(i) + (values.get(i + 1) - values.get(i))*(c + d*xFrac); } private  MathUtils(); static boolean almostEqual(double a, double b, double delta); static double round(double a, double precision); static double floor(double a, double precision); static double ceil(double a, double precision); static int binarySearch(double[] a, double key); static int binarySearchFloor(double[] a, double key); static int binarySearchCeil(double[] a, double key); static T limit(T value, T min, T max); static double limit(double value, double min, double max); static float limit(float value, float min, float max); static int limit(int value, int min, int max); static int randomizedSelect(List<T> a,
			int lower, int upper, int i); static double magnitude(double base, double n); static double quantile(List<Double> values, double q); static boolean isCalculatable(Number n); static boolean isCalculatable(double n); static double normalizeDegrees(double angle);  }
@Test public void testQuantile() { List<Double> values = Arrays.asList( 11.4, 17.3, 21.3, 25.9, 40.1, 50.5, 60.0, 70.0, 75.0); assertEquals(11.40, MathUtils.quantile(values, 0.0), DELTA); assertEquals(16.12, MathUtils.quantile(values, 0.1), DELTA); assertEquals(19.70, MathUtils.quantile(values, 0.2), DELTA); assertEquals(23.14, MathUtils.quantile(values, 0.3), DELTA); assertEquals(28.74, MathUtils.quantile(values, 0.4), DELTA); assertEquals(40.10, MathUtils.quantile(values, 0.5), DELTA); assertEquals(48.42, MathUtils.quantile(values, 0.6), DELTA); assertEquals(56.20, MathUtils.quantile(values, 0.7), DELTA); assertEquals(64.00, MathUtils.quantile(values, 0.8), DELTA); assertEquals(71.00, MathUtils.quantile(values, 0.9), DELTA); assertEquals(75.00, MathUtils.quantile(values, 1.0), DELTA); }