Here you can find the source of clamp(float min, float max, float val)
public static float clamp(float min, float max, float val)
//package com.java2s; //License from project: LGPL public class Main { public static float clamp(float min, float max, float val) { float _min = Math.min(min, max); float _max = Math.max(min, max); return Math.max(Math.min(val, _max), _min); }//from ww w. j av a 2 s . c o m }