Java Float Number Clamp clamp(float num, float min, float max)

Here you can find the source of clamp(float num, float min, float 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

LGPL

Declaration

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

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    /**//from   w w  w . ja  v a 2s. c om
     * 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) {
        if (num < min) {
            return min;
        } else {
            return 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) {
        if (num < min) {
            return min;
        } else {
            return num > max ? max : num;
        }
    }

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

Related

  1. clamp(float input, float min, float max)
  2. clamp(float min, float max, float val)
  3. clamp(float min, float max, float value)
  4. clamp(float min, float x, float max)
  5. clamp(float n, float minValue, float maxValue)
  6. clamp(float v)
  7. clamp(float v, float min, float max)
  8. clamp(float val, float low, float high)
  9. clamp(float val, float max, float min)