Here you can find the source of clamp(int i, int min, int max)
public static int clamp(int i, int min, int max)
//package com.java2s; //License from project: Apache License public class Main { public static int clamp(int i, int min, int max) { if (min >= max) throw new IllegalArgumentException("Min must be less than max. " + min + " >= " + max); if (i < min) return min; if (i > max) return max; return i; }//from w w w. j a v a2 s.c o m public static float clamp(float f, float min, float max) { if (min >= max) throw new IllegalArgumentException("Min must be less than max. " + min + " >= " + max); if (f < min) return min; if (f > max) return max; return f; } public static double clamp(double d, double min, double max) { if (min >= max) throw new IllegalArgumentException("Min must be less than max. " + min + " >= " + max); if (d < min) return min; if (d > max) return max; return d; } }