MathUtils { public static int binarySearch(double[] a, double key) { int l = 0; int h = a.length - 1; int i; do { i = (int)(((long)l + (long)h) / 2L); if (key > a[i]) { l = i + 1; } else if (key < a[i]) { h = i - 1; } else { return i; } } while (l <= h); return i; } 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 testBinarySearch() { double[] a = {0.0, 1.0}; assertEquals(0, MathUtils.binarySearch(a, 0.0)); assertEquals(1, MathUtils.binarySearch(a, 0.5)); assertEquals(1, MathUtils.binarySearch(a, 1.0)); assertEquals(0, MathUtils.binarySearchFloor(a, 0.0)); assertEquals(0, MathUtils.binarySearchFloor(a, 0.5)); assertEquals(1, MathUtils.binarySearchFloor(a, 1.0)); assertEquals(0, MathUtils.binarySearchCeil(a, 0.0)); assertEquals(1, MathUtils.binarySearchCeil(a, 0.5)); assertEquals(1, MathUtils.binarySearchCeil(a, 1.0)); }