MathUtils { public static <T extends Number> T limit(T value, T min, T max) { if (value.doubleValue() > max.doubleValue()) { return max; } if (value.doubleValue() < min.doubleValue()) { return min; } return value; } 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 testLimitDouble() { assertEquals(0.0, MathUtils.limit(-0.5, 0.0, 1.0), DELTA); assertEquals(0.0, MathUtils.limit( 0.0, 0.0, 1.0), DELTA); assertEquals(0.5, MathUtils.limit( 0.5, 0.0, 1.0), DELTA); assertEquals(1.0, MathUtils.limit( 1.0, 0.0, 1.0), DELTA); assertEquals(1.0, MathUtils.limit( 1.5, 0.0, 1.0), DELTA); }
@Test public void testLimitFloat() { assertEquals(0.0, MathUtils.limit(-0.5f, 0.0f, 1.0f), DELTA); assertEquals(0.0, MathUtils.limit( 0.0f, 0.0f, 1.0f), DELTA); assertEquals(0.5, MathUtils.limit( 0.5f, 0.0f, 1.0f), DELTA); assertEquals(1.0, MathUtils.limit( 1.0f, 0.0f, 1.0f), DELTA); assertEquals(1.0, MathUtils.limit( 1.5f, 0.0f, 1.0f), DELTA); }
@Test public void testLimitInt() { assertEquals( 0, MathUtils.limit(-5, 0, 10)); assertEquals( 0, MathUtils.limit( 0, 0, 10)); assertEquals( 5, MathUtils.limit( 5, 0, 10)); assertEquals(10, MathUtils.limit(10, 0, 10)); assertEquals(10, MathUtils.limit(15, 0, 10)); }