Here you can find the source of clamp(double d, double min, double max)
public static double clamp(double d, double min, double max)
//package com.java2s; //License from project: Open Source License public class Main { public static double clamp(double d, double min, double max) { if (d < min) d = min;/*from w w w .j a va 2 s . c o m*/ if (d > max) d = max; return d; } public static double[] clamp(double[] d, double min, double max) { for (int i = 0; i < d.length; i++) d[i] = clamp(d[i], min, max); return d; } }