Here you can find the source of clamp(int n, int l, int u)
public static int clamp(int n, int l, int u)
//package com.java2s; //License from project: Open Source License public class Main { public static int clamp(int n, int l, int u) { return Math.max(Math.min(n, u), l); }/* www . j a v a 2 s .c om*/ public static float clamp(float n, float l, float u) { return Math.max(Math.min(n, u), l); } public static double clamp(double n, double l, double u) { return Math.max(Math.min(n, u), l); } }