MathUtils { public static double clamp(double input, double min, double max) { return (input < min) ? min : (input > max) ? max : input; } private  MathUtils(); static long binomialCoeff(int n, int k); static double logSumExp(double[] scores); static double logWeightedGeometricMean(double[] weights, double[] logScores); static double weightedArithmeticMean(double[] weights, double[] scores); static double weightedGeometricMean(double[] weights, double[] scores); static double weightedLogSumExp(double[] weights, double[] scores); static double logprob(double input); static double clamp(double input, double min, double max); static double sigmoid(double t);  }
@Test public void testClamp() { assertEquals(2, MathUtils.clamp(7, 0, 2), 0.001); assertEquals(0, MathUtils.clamp(-5, 0, 2), 0.001); }