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