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

Restricts a value to be within a specified range.

License

Open Source License

Parameter

Parameter Description
value a parameter
min The minimum desired value
max The maximum desired value

Return

Return a value between min and max

Declaration

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

Method Source Code

//package com.java2s;
// file 'LICENSE', which is part of this source code package.

public class Main {
    /**//from  w ww.  j  a  v  a2 s.  c  o  m
     * Restricts a value to be within a specified range.
     * @param value
     * @param min The minimum desired value
     * @param max The maximum desired value
     * @return Return a value between min and max
     */
    public static float clamp(float value, float min, float max) {
        value = (value > max) ? max : value;
        value = (value < min) ? min : value;
        return value;
    }

    /**
     * Restricts a value to be within a specified range.
     * @param value
     * @param min The minimum desired value
     * @param max The maximum desired value
     * @return Return a value between min and max
     */
    public static int clamp(int value, int min, int max) {
        return (int) clamp((float) value, (float) min, (float) max);
    }
}

Related

  1. clamp(float value, float min, float max)
  2. clamp(float value, float min, float max)
  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 minimum, float maximum)
  7. clamp(float value, float minimum, float maximum)
  8. clamp(float x, float a, float b)
  9. clamp(float x, float y, float z)