Here you can find the source of clamp(double v, double lower, double upper)
public static double clamp(double v, double lower, double upper)
//package com.java2s; //License from project: Apache License public class Main { /**// ww w .j a v a 2 s. c o m * Clamps a value to the range [lower, upper]. */ public static double clamp(double v, double lower, double upper) { if (v < lower) return lower; else if (v > upper) return upper; else return v; } }