Here you can find the source of clamp(double f)
public static double clamp(double f)
//package com.java2s; public class Main { /**/*from w w w . ja va 2 s. co m*/ * Returns the given float clamped to 1/1000th precision. */ public static double clamp(double f) { return (f > -1e-3) && (f < 1e-3) ? 0 : (f > 1e5 ? 1e5f : (f < -1e5 ? -1e5f : f)); } /** * Returns the given in clamped between the two values. */ public static int clamp(int i, int min, int max) { return Math.min(Math.max(i, min), max); } /** * Returns the given double clamped between the two values. */ public static double clamp(double f, double min, double max) { return Math.min(Math.max(f, min), max); } }