Java Integer Clamp clamp(int num, int min, int max)

Here you can find the source of clamp(int num, int min, int max)

Description

Returns the value of the first parameter, clamped to be within the lower and upper limits given by the second and third parameters.

License

Open Source License

Declaration

public static int clamp(int num, int min, int max) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from   ww w.ja  v a 2 s .com*/
     * Returns the value of the first parameter, clamped to be within the lower and upper limits given by the second and
     * third parameters.
     */
    public static int clamp(int num, int min, int max) {
        return num < min ? min : (num > max ? max : num);
    }

    /**
     * Returns the value of the first parameter, clamped to be within the lower and upper limits given by the second and
     * third parameters
     */
    public static float clamp(float num, float min, float max) {
        return num < min ? min : (num > max ? max : num);
    }

    public static double clamp(double num, double min, double max) {
        return num < min ? min : (num > max ? max : num);
    }
}

Related

  1. clamp(int min, int value, int max)
  2. clamp(int n, int l, int u)
  3. clamp(int n, int lower, int upper)
  4. clamp(int n, int min, int max)
  5. clamp(int n, int min, int max)
  6. clamp(int number, int low, int high)
  7. clamp(int ptr, int size)
  8. clamp(int v, int min, int max)
  9. clamp(int v, int min, int max)