Java Double Number Clamp clamp(double f)

Here you can find the source of clamp(double f)

Description

Returns the given float clamped to 1/1000th precision.

License

Open Source License

Declaration

public static double clamp(double f) 

Method Source Code

//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);
    }
}

Related

  1. clamp(double a, double min, double max)
  2. clamp(double d, double min, double max)
  3. clamp(double d, double min, double max)
  4. clamp(double d, double min, double max)
  5. clamp(double d, double min, double max)
  6. clamp(double f, double f1, double f2)
  7. clamp(double min, double arg, double max)
  8. clamp(double min, double max, double val)
  9. clamp(double min, double max, double value)