Here you can find the source of clamp(final float v, final float min, final float max)
public static float clamp(final float v, final float min, final float max)
//package com.java2s; /*//from w w w . jav a 2 s. c om * PJOGLES - Copyright (C) 2008 Guillaume Legris, Mathieu Legris * * OGLJava - Copyright (C) 2004 Tom Dinneen * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program 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 * General Public License version 2 for more details. * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA */ public class Main { public static int clamp(final int v, final int min, final int max) { if (v < min) return min; else if (v > max) return max; else return v; } public static float clamp(final float v, final float min, final float max) { if (v < min) return min; else if (v > max) return max; else return v; } }