Here you can find the source of CLAMP(byte x, byte min, byte max)
public static byte CLAMP(byte x, byte min, byte max)
//package com.java2s; /*// www.ja va 2 s. c om * @(#)gl_util.java 0.3 06/11/20 * * jGL 3-D graphics library for Java * Copyright (c) 1999-2006 Robin Bing-Yu Chen (robin@ntu.edu.tw) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or any later version. the GNU Lesser * General Public License should be included with this distribution * in the file LICENSE. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ public class Main { public static byte CLAMP(byte x, byte min, byte max) { if (x < min) return min; if (x > max) return max; return x; } public static short CLAMP(short x, short min, short max) { if (x < min) return min; if (x > max) return max; return x; } public static int CLAMP(int x, int min, int max) { if (x < min) return min; if (x > max) return max; return x; } public static float CLAMP(float x, float min, float max) { if (x < min) return min; if (x > max) return max; return x; } public static float CLAMP(float x, double min, double max) { if (x < min) return (float) min; if (x > max) return (float) max; return x; } public static float CLAMP(double x, double min, double max) { // the CLAMP for double will return by float if (x < min) return (float) min; if (x > max) return (float) max; return (float) x; } }