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