Java Double Number Clamp clamp(final double value, final double min, final double max)

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

Description

clamp

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static double clamp(final double value, final double min, final double max) {
        return Math.max(min, Math.min(max, value));
    }//ww  w.  j a  v  a  2 s.c  o  m

    public static float clamp(final float value, final float min, final float max) {
        return Math.max(min, Math.min(max, value));
    }

    public static int clamp(final int value, final int min, final int max) {
        if (value < min) {
            return min;
        }

        if (value > max) {
            return max;
        }

        return value;
    }

    public static long clamp(final long value, final long min, final long max) {
        if (value < min) {
            return min;
        }

        if (value > max) {
            return max;
        }

        return value;
    }
}

Related

  1. clamp(double x, double low, double high)
  2. clamp(double x, double min, double max)
  3. clamp(double x, double min, double max)
  4. clamp(double x, double xMin, double xMax)
  5. clamp(final double value, final double min, final double max)
  6. clamp01(double d)
  7. clamp01(double value)
  8. clamp255d(double d)
  9. clamp_double(double num, double min, double max)