Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { /** * Clamps a value between lower and upper bounds. Formally, given value v, * and an interval [lower, upper], lower <= clamp(v, lower, upper) <= upper holds true * * @param v the value to clamp * @param lower the lower bound of the interval * @param upper the upper bound of the interval * @return the clamped value of v in the [lower, upper] interval */ public static float clamp(float v, float lower, float upper) { return Math.max(lower, Math.min(upper, v)); } }