Java Float Number Clamp clamp(final float v, final float min, final float max)

Here you can find the source of clamp(final float v, final float min, final float max)

Description

clamp

License

Open Source License

Declaration

public static float clamp(final float v, final float min, final float max) 

Method Source Code

//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;
    }
}

Related

  1. clamp(final float min, final float x, final float max)
  2. clamp(final float num, final float bound1, final float bound2)
  3. clamp(final float val, final float min, final float max)
  4. clamp(final float value, final float min, final float max)
  5. clamp(final float x, final float a, final float b)
  6. clamp(float a, float min, float max)