Here you can find the source of clipRange(double[] x, double minVal, double maxVal)
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 |
public static boolean clipRange(double[] x, double minVal, double maxVal)
//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; } }