Here you can find the source of clamp(float num, float min, float max)
public static float clamp(float num, float min, float max)
//package com.java2s; //License from project: LGPL public class Main { /**//from w w w . ja v a 2s. c om * 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) { if (num < min) { return min; } else { return 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) { if (num < min) { return min; } else { return num > max ? max : num; } } public static double clamp(double num, double min, double max) { if (num < min) { return min; } else { return num > max ? max : num; } } }