Java Double Number Clip clipRecklessly(double val, double bounds)

Here you can find the source of clipRecklessly(double val, double bounds)

Description

Clips the given value within the given bounds.

License

Open Source License

Declaration

public static double clipRecklessly(double val, double bounds) 

Method Source Code

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

public class Main {
    /**/*from  www.  j a  v  a2s .  co m*/
     * Clips the given value within the given bounds.  If {@code -bounds <=  val <= bounds}, {@code
     * val} is returned unchanged. Otherwise, {@code -bounds} is returned if {@code val<bounds} and
     * {@code bounds} is returned if {@code val>bounds}. {@code bounds} must be non-negative, but this
     * is not enforced, so prefer using {@link #clip(double, double)} except in inner-loops.
     *
     * {@code NaN} values will be left unchanged, but positive and negative infinity will be clipped.
     */
    public static double clipRecklessly(double val, double bounds) {
        if (val > bounds) {
            return bounds;
        } else if (val < -bounds) {
            return -bounds;
        } else {
            return val;
        }
    }
}

Related

  1. clipDecimals(double num, int n)
  2. clipDouble(double value, double max)
  3. clipnorm(double d, double min, double max)
  4. clipNormalized(double a)
  5. clipRange(double[] x, double minVal, double maxVal)