Here you can find the source of clamp(double d, double min, double max)
public static final double clamp(double d, double min, double max)
//package com.java2s; // {LICENSE}// ww w.j av a2 s . c o m public class Main { public static final double clamp(double d, double min, double max) { if (min > max) throw new IllegalArgumentException("min > max"); if (d >= max) return max; if (d <= min) return min; return d; } public static final int clamp(int i, int min, int max) { if (min > max) throw new IllegalArgumentException("min > max"); if (i >= max) return max; if (i <= min) return min; return i; } }