Here you can find the source of clamp(int min, int val, int max)
public static int clamp(int min, int val, int max)
//package com.java2s; //License from project: Apache License public class Main { public static int clamp(int min, int val, int max) { return Math.min(Math.max(val, min), max); }/*from w w w .j a v a 2 s . co m*/ public static double clamp(double min, double val, double max) { return Math.min(Math.max(val, min), max); } public static double min(double... values) { double min = Double.MAX_VALUE; for (double v : values) { min = Math.min(v, min); } return min; } public static double max(double... values) { double max = Double.MIN_VALUE; for (double v : values) { max = Math.max(v, max); } return max; } }