Java Float Number Clamp Clamp(float val, float minVal, float maxVal)

Here you can find the source of Clamp(float val, float minVal, float maxVal)

Description

Clamp

License

Apache License

Declaration

public static float Clamp(float val, float minVal, float maxVal) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static float Clamp(float val, float minVal, float maxVal) {
        return (Min(Max(minVal, val), maxVal));
    }//from   ww w .j a  v  a 2  s.c  o  m

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

    static public short clamp(short value, short min, short max) {
        if (value < min) {
            return min;
        }
        if (value > max) {
            return max;
        }
        return value;
    }

    static public float clamp(float value, float min, float max) {
        if (value < min) {
            return min;
        }
        if (value > max) {
            return max;
        }
        return value;
    }

    static public double clamp(double value, double min, double max) {
        if (value < min) {
            return min;
        }
        if (value > max) {
            return max;
        }
        return value;
    }

    public static float Min(float a, float b) {
        return ((a) > (b) ? (b) : (a));
    }

    public static int min(int a, int b) {
        if (a < b) {
            return a;
        }
        return b;
    }

    public static int min(int a, int b, int c) {
        if (min(a, b) < c) {
            return min(a, b);
        }
        return c;
    }

    public static float Max(float a, float b) {
        return ((a) < (b) ? (b) : (a));
    }

    public static int max(int a, int b) {
        if (a > b) {
            return a;
        }
        return b;
    }
}

Related

  1. clamp(float v, float min, float max)
  2. clamp(float val, float low, float high)
  3. clamp(float val, float max, float min)
  4. clamp(float val, float min, float max)
  5. clamp(float val, float min, float max)
  6. clamp(float value)
  7. Clamp(float value, float lowerLimit, float upperLimit)
  8. clamp(float value, float min, float max)
  9. clamp(float value, float min, float max)