Here you can find the source of min(double[] x)
Parameter | Description |
---|---|
NullPointerException | if `x` is null. |
public static double min(double[] x)
//package com.java2s; /*/* w w w . j av a 2s . c o m*/ * Copyright (C) 2013, Peter Decsi. * * This library 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, either * version 3 of the License, or (at your option) any later version. * * This library 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 General Public License * along with this library. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Returns the lowest element of `x`, NaN values are ignored. * * @throws NullPointerException if `x` is null. */ public static double min(double[] x) { return min(x, true); } /** * Returns the lowest element of `x`. If `ignoreNaN` is false, * and `x` contains a NaN value, then the result is NaN. * * @throws NullPointerException if `x` is null. */ public static double min(double[] x, boolean ignoreNaN) { int size = x.length; if (size == 0) return Double.NaN; double min = x[0]; for (int i = 1; i < size; i++) { double v = x[i]; if (Double.isNaN(v)) { if (!ignoreNaN) return Double.NaN; } else { if (v < min) min = v; } } return min; } }