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