Java Array Min Value min(double[] vals)

Here you can find the source of min(double[] vals)

Description

min

License

Open Source License

Declaration

public static double min(double[] vals) 

Method Source Code

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

public class Main {
    public static double min(double[] vals) {
        if (vals.length == 0) {
            return Double.NaN;
        }/* www  .j a v a  2 s .  c o m*/

        double[] range = range(vals);
        return range[0];
    }

    /**
     * Get the range of an array.
     * will return null if the array is empty.
     * Will return a double[2] (min at 0, max at 1).
     */
    public static double[] range(double[] vals) {
        if (vals.length == 0) {
            return null;
        }

        double[] rtn = { vals[0], vals[0] };

        for (int i = 1; i < vals.length; i++) {
            if (rtn[0] > vals[i]) {
                rtn[0] = vals[i];
            } else if (rtn[1] < vals[i]) {
                rtn[1] = vals[i];
            }
        }

        return rtn;
    }
}

Related

  1. min(double[] da)
  2. min(double[] data)
  3. min(double[] matrix)
  4. min(double[] numbers)
  5. min(double[] series)
  6. min(double[] values)
  7. min(double[] values)
  8. min(double[] values)
  9. min(double[] x)