Here you can find the source of clamp(int value, int min, int max)
Parameter | Description |
---|---|
value | the value to clamp |
min | the minimum value |
max | the maximum value |
public static int clamp(int value, int min, int max)
//package com.java2s; //License from project: Open Source License public class Main { /**// ww w . j av a 2s. c o m * Clamp Integer values to a given range * * @param value the value to clamp * @param min the minimum value * @param max the maximum value * @return the clamped value */ public static int clamp(int value, int min, int max) { return Math.max(min, Math.min(max, value)); } /** * Clamp Float values to a given range * * @param value the value to clamp * @param min the minimum value * @param max the maximum value * @return the clamped value */ public static float clamp(float value, float min, float max) { return Math.max(min, Math.min(max, value)); } /** * Clamp Long values to a given range * * @param value the value to clamp * @param min the minimum value * @param max the maximum value * @return the clamped value */ public static long clamp(long value, long min, long max) { return Math.max(min, Math.min(max, value)); } /** * Clamp Double values to a given range * * @param value the value to clamp * @param min the minimum value * @param max the maximum value * @return the clamped value */ public static double clamp(double value, double min, double max) { return Math.max(min, Math.min(max, value)); } }