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

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

Description

clamp

License

Apache License

Declaration

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

Method Source Code

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

public class Main {
    public static int clamp(int value, int min, int max) {
        if (max < min)
            return value;

        if (value < min)
            value = min;/* w  w w  . j a v  a 2  s. c o m*/
        else if (value > max)
            value = max;

        return value;
    }

    public static long clamp(long value, long min, long max) {
        if (max < min)
            return value;

        if (value < min)
            value = min;
        else if (value > max)
            value = max;

        return value;
    }

    public static float clamp(float value, float min, float max) {
        if (max < min)
            return value;

        if (value < min)
            value = min;
        else if (value > max)
            value = max;

        return value;
    }

    public static double clamp(double value, double min, double max) {
        if (max < min)
            return value;

        if (value < min)
            value = min;
        else if (value > max)
            value = max;

        return value;
    }
}

Related

  1. clamp(float value)
  2. Clamp(float value, float lowerLimit, float upperLimit)
  3. clamp(float value, float min, float max)
  4. clamp(float value, float min, float max)
  5. clamp(float value, float min, float max)
  6. clamp(float value, float min, float max)
  7. clamp(float value, float min, float max)
  8. clamp(float value, float minimum, float maximum)
  9. clamp(float value, float minimum, float maximum)