Here you can find the source of clamp(int x, int min, int max)
public static final int clamp(int x, int min, int max)
//package com.java2s; //License from project: Open Source License public class Main { public static final int clamp(int x, int min, int max) { if (x > max) return max; if (x > min) return x; return min; }//from w w w . j a v a 2s . c om public static final float clamp(float x, float min, float max) { if (x > max) return max; if (x > min) return x; return min; } public static final double clamp(double x, double min, double max) { if (x > max) return max; if (x > min) return x; return min; } }