Here you can find the source of clamp(int val, int min, int max)
public static int clamp(int val, int min, int max)
//package com.java2s; //License from project: Open Source License public class Main { public static int clamp(int val, int min, int max) { val = Math.min(val, max); val = Math.max(val, min); return val; }//from w ww. j av a2 s .c o m public static float clamp(float val, float min, float max) { val = Math.min(val, max); val = Math.max(val, min); return val; } public static long clamp(long val, long min, long max) { val = Math.min(val, max); val = Math.max(val, min); return val; } public static double clamp(double val, double min, double max) { val = Math.min(val, max); val = Math.max(val, min); return val; } public static short clamp(short val, short min, short max) { val = (short) Math.min(val, max); val = (short) Math.max(val, min); return val; } }