android/guava/src/com/google/common/primitives/Floats.java
@Beta
  public static float constrainToRange(float value, float min, float max) {
    checkArgument(min <= max, "min (%s) must be less than or equal to max (%s)", min, max);
    return Math.min(Math.max(value, min), max);
  }
@Beta
  public static float constrainToRange(float value, float min, float max) {
    checkArgument(min <= max, "min (%s) must be less than or equal to max (%s)", min, max);
    return Math.min(Math.max(value, min), max);
  }
@ Beta public static float constrainToRange ( float value , float min , float max ) { checkArgument ( min <= max , "min (%s) must be less than or equal to max (%s)" , min , max ) ; return Math . min ( Math . max ( value , min ) , max ) ; }
Returns the value nearest to {@code value} which is within the closed range {@code [min..max]}.

<p>If {@code value} is within the range {@code [min..max]}, {@code value} is returned
unchanged. If {@code value} is less than {@code min}, {@code min} is returned, and if {@code
value} is greater than {@code max}, {@code max} is returned.

@param value the {@code float} value to constrain
@param min the lower bound (inclusive) of the range to constrain {@code value} to
@param max the upper bound (inclusive) of the range to constrain {@code value} to
@throws IllegalArgumentException if {@code min > max}
@since 21.0
Returns the value nearest to { @code value } which is within the closed range { @code [ min .. max ] } .