Here you can find the source of clamp(int num, int min, int max)
public static int clamp(int num, int min, int max)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from ww w.ja v a 2 s .com*/ * Returns the value of the first parameter, clamped to be within the lower and upper limits given by the second and * third parameters. */ public static int clamp(int num, int min, int max) { return num < min ? min : (num > max ? max : num); } /** * Returns the value of the first parameter, clamped to be within the lower and upper limits given by the second and * third parameters */ public static float clamp(float num, float min, float max) { return num < min ? min : (num > max ? max : num); } public static double clamp(double num, double min, double max) { return num < min ? min : (num > max ? max : num); } }