Java Double Number Clamp clamp(double v, double l, double h)

Here you can find the source of clamp(double v, double l, double h)

Description

clamps input v to the specified range from l to h

License

Open Source License

Declaration

public static double clamp(double v, double l, double h) 

Method Source Code

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

Related

  1. clamp(double min, double arg, double max)
  2. clamp(double min, double max, double val)
  3. clamp(double min, double max, double value)
  4. clamp(double min, double value, double max)
  5. clamp(double number)
  6. clamp(double v, double lower, double upper)
  7. clamp(double v, double lower, double upper)
  8. clamp(double val)
  9. clamp(double val)