Java Double Number Clamp clamp(double value, final double min, final double max)

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

Description

Make sure a value is in between the specified bounds.

License

Open Source License

Parameter

Parameter Description
value the value
min the minimal possible value (inclusive)
max the maximal possible value (inclusive)

Return

the clamped value

Declaration

public static double clamp(double value, final double min, final double max) 

Method Source Code

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

public class Main {
    /**/*from w ww .ja  va2 s . c om*/
     * Make sure a value is in between the specified bounds.
     *
     * @param value
     *            the value
     * @param min
     *            the minimal possible value (inclusive)
     * @param max
     *            the maximal possible value (inclusive)
     * @return the clamped value
     */
    public static double clamp(double value, final double min, final double max) {
        if (value < min) {
            value = min;
        } else if (value > max) {
            value = max;
        }
        return value;
    }

    /**
     * @see Helpers#clamp(double, double, double)
     */
    public static int clamp(int value, final int min, final int max) {
        if (value < min) {
            value = min;
        } else if (value > max) {
            value = max;
        }
        return value;
    }
}

Related

  1. clamp(double value, double low, double high)
  2. clamp(double value, double min, double max)
  3. clamp(double value, double min, double max)
  4. clamp(double value, double min, double max)
  5. clamp(double value, double min, double max)
  6. clamp(double var1, double var2, double var3)
  7. clamp(double weight, double lowerBound, double upperBound)
  8. clamp(double x, double low, double high)
  9. clamp(double x, double min, double max)