Here you can find the source of clamp(double min, double max, double val)
public static double clamp(double min, double max, double val)
//package com.java2s; //License from project: Open Source License public class Main { public static double clamp(double min, double max, double val) { if (val > max) return max; else if (val < min) return min; else/*w w w .java 2s. c o m*/ return val; } public static long clamp(long min, long max, long val) { if (val > max) return max; else if (val < min) return min; else return val; } public static float clamp(float min, float max, float val) { if (val > max) return max; else if (val < min) return min; else return val; } public static int clamp(int min, int max, int val) { if (val > max) return max; else if (val < min) return min; else return val; } }