Here you can find the source of clamp(int v, int min, int max)
static public int clamp(int v, int min, int max)
//package com.java2s; public class Main { static public int clamp(int v, int min, int max) { if (v < min) v = min;//from www. j a v a 2 s . c o m if (v > max) v = max; return v; } static public double clamp(double v, double min, double max) { if (v < min) v = min; if (v > max) v = max; return v; } }