Here you can find the source of max(double[] x)
Parameter | Description |
---|---|
NullPointerException | if `x` is null. |
public static double max(double[] x)
//package com.java2s; /*//from ww w . ja va2 s . com * 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 highest element of `x`, NaN values are ignored. * * @throws NullPointerException if `x` is null. */ public static double max(double[] x) { return max(x, true); } /** * Returns the highest 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 max(double[] x, boolean ignoreNaN) { int size = x.length; if (size == 0) return Double.NaN; double max = 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 > max) max = v; } } return max; } }