Java Float Number Clip clip(float x)

Here you can find the source of clip(float x)

Description

Simple utility function that is used in a couple of places.

License

Open Source License

Parameter

Parameter Description
x a parameter

Return

x constrained to [0, 1]

Declaration

public static float clip(float x) 

Method Source Code

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

public class Main {
    /**/*from w w  w. j  a v a 2 s. c om*/
     * Simple utility function that is used in a couple of places.
     * 
     * @param x
     * @return x constrained to [0, 1]
     */
    public static float clip(float x) {
        return Math.min(Math.max(x, 0), 1);
    }

    /**
     * Simple utility function that is used in a couple of places.
     * 
     * @param x
     * @param min
     * @param max
     * @return x constrained to [min, max]
     */
    public static float clip(float x, float min, float max) {
        return Math.min(Math.max(x, min), max);
    }
}

Related

  1. clip(float f, float lo, float hi)
  2. clip(float value, float bottom, float top)
  3. clipf(float num, float mini, float maxi)
  4. clipFloat(float value, float min, float max)
  5. clipNormalized(final float a)
  6. clipToRange(float[][] in, float min, float max)