Here you can find the source of clamp(int i, int low, int high)
Parameter | Description |
---|---|
i | input number |
low | minimum range |
high | maximum range |
public static int clamp(int i, int low, int high)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w.j a v a2s . c o m * Converts input number to a number within the specified range. * @param i input number * @param low minimum range * @param high maximum range * @return clamped number */ public static int clamp(int i, int low, int high) { return Math.max(Math.min(i, high), low); } /** * Converts input number to a number within the specified range. * @param i input number * @param low minimum range * @param high maximum range * @return clamped number */ public static long clamp(long i, long low, long high) { return Math.max(Math.min(i, high), low); } /** * Converts input number to a number within the specified range. * @param i input number * @param low minimum range * @param high maximum range * @return clamped number */ public static double clamp(double i, double low, double high) { return Math.max(Math.min(i, high), low); } /** * Converts input number to a number within the specified range. * @param i input number * @param low minimum range * @param high maximum range * @return clamped number */ public static float clamp(float i, float low, float high) { return Math.max(Math.min(i, high), low); } }