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

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

Description

Constrains the value between the given borders (inclusive).

License

Apache License

Parameter

Parameter Description
min The minimum value.
max The maximum value.
value The value to constrain within <code>min</code> and <code>max</code>

Return

The value if within min and max, otherwise one of min and max.

Declaration

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

Method Source Code

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

public class Main {
    /**/*from  w  w  w  .  ja  v  a  2s. co  m*/
     * Constrains the value between the given borders (inclusive).
     * @param min The minimum value.
     * @param max The maximum value.
     * @param value The value to constrain within <code>min</code> and <code>max</code>
     * @return The <code>value</code> if within <code>min</code> and <code>max</code>, otherwise one of <code>min</code> and <code>max</code>.
     */
    public static double clamp(double min, double max, double value) {
        return Math.min(Math.max(min, value), max);
    }
}

Related

  1. clamp(double d, double min, double max)
  2. clamp(double f)
  3. clamp(double f, double f1, double f2)
  4. clamp(double min, double arg, double max)
  5. clamp(double min, double max, double val)
  6. clamp(double min, double value, double max)
  7. clamp(double number)
  8. clamp(double v, double l, double h)
  9. clamp(double v, double lower, double upper)