code: public static int clamp(int x, int a, int b) {
  		return (x < a) ? a : (x > b) ? b : x;
  	}
docs: Clamp a value to an interval.
  
  @param a the lower clamp threshold
  @param b the upper clamp threshold
  @param x the input parameter
  @return the clamped value