Java Integer Clamp clamp(int v, int min, int max)

Here you can find the source of clamp(int v, int min, int max)

Description

Clamps the specified value into the given range.

License

BSD License

Parameter

Parameter Description
v The value to be clamped
min The minimum value to clamp to
max The maximum value to clamp to

Return

The clamped value

Declaration

public static int clamp(int v, int min, int max) 

Method Source Code

//package com.java2s;
/*//from w w  w  .j a v a  2s. com
 * Copyright (c) 2015, GoMint, BlackyPaw and geNAZt
 *
 * This code is licensed under the BSD license found in the
 * LICENSE file in the root directory of this source tree.
 */

public class Main {
    /**
     * Clamps the specified value into the given range.
     *
     * @param v The value to be clamped
     * @param min The minimum value to clamp to
     * @param max The maximum value to clamp to
     * @return The clamped value
     */
    public static int clamp(int v, int min, int max) {
        return (v < min ? min : (v > max ? max : v));
    }

    /**
     * Clamps the specified value into the given range.
     *
     * @param v The value to be clamped
     * @param min The minimum value to clamp to
     * @param max The maximum value to clamp to
     * @return The clamped value
     */
    public static float clamp(float v, float min, float max) {
        return (v < min ? min : (v > max ? max : v));
    }

    /**
     * Clamps the specified value into the given range.
     *
     * @param v The value to be clamped
     * @param min The minimum value to clamp to
     * @param max The maximum value to clamp to
     * @return The clamped value
     */
    public static double clamp(double v, double min, double max) {
        return (v < min ? min : (v > max ? max : v));
    }
}

Related

  1. clamp(int num, int min, int max)
  2. clamp(int number, int low, int high)
  3. clamp(int ptr, int size)
  4. clamp(int v, int min, int max)
  5. clamp(int v, int min, int max)
  6. clamp(int val, int min, int max)
  7. clamp(int value, final int minimum, final int maximum)
  8. clamp(int value, int a, int b)
  9. clamp(int value, int low, int high)