Here you can find the source of clamp(double v, double l, double h)
public static double clamp(double v, double l, double h)
//package com.java2s; /*//from ww w . ja va 2 s . co m * Copyright (c) 2011, Paul Hertz This library is free software; you can * redistribute it and/or modify it under the terms of the GNU Lesser General * Public License as published by the Free Software Foundation; either version * 3.0 of the License, or (at your option) any later version. * http://www.gnu.org/licenses/lgpl.html This library is distributed in * the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See * the GNU Lesser General Public License for more details. You should have * received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, * Fifth Floor, Boston, MA 02110-1301, USA * * @author ##author## * @modified ##date## * @version ##version## * */ public class Main { /** * clamps input v to the specified range from l to h */ public static double clamp(double v, double l, double h) { return (v < l) ? l : (v > h) ? h : v; } /** * clamps input v to the specified range from l to h */ public static float clamp(float v, float l, float h) { return (v < l) ? l : (v > h) ? h : v; } }