Java Integer Clamp clamp(int amt, int low, int high)

Here you can find the source of clamp(int amt, int low, int high)

Description

Constrains a value to not exceed a maximum and minimum value.

License

Open Source License

Parameter

Parameter Description
amt the value to constrain
low minimum limit
high maximum limit

Declaration


static public final int clamp(int amt, int low, int high) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from  w  ww.  j av a2  s  . c  om
     * 
     * Constrains a value to not exceed a maximum and minimum value.
     * 
     * @param amt
     *            the value to constrain
     * @param low
     *            minimum limit
     * @param high
     *            maximum limit
     */

    static public final int clamp(int amt, int low, int high) {
        return (amt < low) ? low : ((amt > high) ? high : amt);
    }

    /**
     * 
     * Constrains a value to not exceed a maximum and minimum value.
     * 
     * @param amt
     *            the value to constrain
     * @param low
     *            minimum limit
     * @param high
     *            maximum limit
     */

    static public final float clamp(float amt, float low, float high) {
        return (amt < low) ? low : ((amt > high) ? high : amt);
    }

    /**
     * 
     * Constrains a value to not exceed a maximum and minimum value.
     * 
     * @param amt
     *            the value to constrain
     * @param low
     *            minimum limit
     * @param high
     *            maximum limit
     */

    static public final double clamp(double amt, double low, double high) {
        return (amt < low) ? low : ((amt > high) ? high : amt);
    }
}

Related

  1. clamp(final int value, final int min, final int max)
  2. clamp(final int value, final int min, final int max)
  3. clamp(int a)
  4. clamp(int a, int x, int b)
  5. clamp(int a, int x, int y)
  6. clamp(int c)
  7. clamp(int c)
  8. clamp(int floor, int ceiling, int value)
  9. clamp(int i, int low, int high)