Java Double Number Clamp clamp(double d, double min, double max)

Here you can find the source of clamp(double d, double min, double max)

Description

clamp

License

Open Source License

Declaration

public static final double clamp(double d, double min, double max) 

Method Source Code

//package com.java2s;
// {LICENSE}// ww w.j av a2  s .  c  o m

public class Main {
    public static final double clamp(double d, double min, double max) {
        if (min > max)
            throw new IllegalArgumentException("min > max");
        if (d >= max)
            return max;
        if (d <= min)
            return min;
        return d;
    }

    public static final int clamp(int i, int min, int max) {
        if (min > max)
            throw new IllegalArgumentException("min > max");
        if (i >= max)
            return max;
        if (i <= min)
            return min;
        return i;
    }
}

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 f)
  6. clamp(double f, double f1, double f2)
  7. clamp(double min, double arg, double max)
  8. clamp(double min, double max, double val)