Java Array Max Value max(double[] series)

Here you can find the source of max(double[] series)

Description

Finds the maximal value in timeseries.

License

Open Source License

Parameter

Parameter Description
series The timeseries.

Return

The max value.

Declaration

public static double max(double[] series) 

Method Source Code

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

public class Main {
    /**//  w w w.  j a va2s . co  m
     * Finds the maximal value in timeseries.
     *
     * @param series The timeseries.
     * @return The max value.
     */
    public static double max(double[] series) {
        if (countNaN(series) == series.length) {
            return Double.NaN;
        }
        double max = Double.MIN_VALUE;
        for (int i = 0; i < series.length; i++) {
            if (max < series[i]) {
                max = series[i];
            }
        }
        return max;
    }

    /**
     * Counts the number of NaNs' in the timeseries.
     *
     * @param series The timeseries.
     * @return The count of NaN values.
     */
    private static int countNaN(double[] series) {
        int res = 0;
        for (double d : series) {
            if (Double.isInfinite(d) || Double.isNaN(d)) {
                res += 1;
            }
        }
        return res;
    }
}

Related

  1. max(double[] array)
  2. max(double[] data)
  3. max(double[] data)
  4. max(double[] list)
  5. max(double[] matrix)
  6. max(double[] vals)
  7. max(double[] values)
  8. max(double[] values)
  9. max(double[] values)