Java Double Number Clip clipRange(double[] x, double minVal, double maxVal)

Here you can find the source of clipRange(double[] x, double minVal, double maxVal)

Description

Adjust values in x so that all values smaller than minVal are set to minVal, and all values greater than maxVal are set to maxVal

License

Open Source License

Parameter

Parameter Description
x array of doubles to adjust; if x is null, nothing happens
minVal minimum of all values in x after adjustment
maxVal maximum of all values in x after adjustment

Return

true if one or more values in x were modified, false if x is unchanged

Declaration

public static boolean clipRange(double[] x, double minVal, double maxVal) 

Method Source Code

//package com.java2s;
/**/*from  www.j  a v a 2  s.c o m*/
 * Copyright 2004-2006 DFKI GmbH.
 * All Rights Reserved.  Use is subject to license terms.
 *
 * This file is part of MARY TTS.
 *
 * MARY TTS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

public class Main {
    /**
     * Adjust values in x so that all values smaller than minVal are set to minVal, and all values greater than maxVal are set to
     * maxVal
     * 
     * @param x
     *            array of doubles to adjust; if x is null, nothing happens
     * @param minVal
     *            minimum of all values in x after adjustment
     * @param maxVal
     *            maximum of all values in x after adjustment
     * @return true if one or more values in x were modified, false if x is unchanged
     */
    public static boolean clipRange(double[] x, double minVal, double maxVal) {
        boolean modified = false;
        if (x == null) {
            return modified;
        }
        for (int i = 0; i < x.length; i++) {
            if (x[i] < minVal) {
                x[i] = minVal;
                modified = true;
            } else if (x[i] > maxVal) {
                x[i] = maxVal;
                modified = true;
            }
        }
        return modified;
    }
}

Related

  1. clip2(double n, double d, double[] t)
  2. clipDecimals(double num, int n)
  3. clipDouble(double value, double max)
  4. clipnorm(double d, double min, double max)
  5. clipNormalized(double a)
  6. clipRecklessly(double val, double bounds)