Java Array Min Value minOf(double[] da, double val)

Here you can find the source of minOf(double[] da, double val)

Description

min Of

License

Open Source License

Parameter

Parameter Description
da - the array of input values.
val - the minimum comparison value.

Return

an array containing the minimum of the array value or the given value.

Declaration


public static double[] minOf(double[] da, double val) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from   w w w. ja v  a 2  s .  c  om
     * @param da - the array of input values.
     * @param val - the minimum comparison value.
     * @return an array containing the minimum of the array value or the given value.
     */

    public static double[] minOf(double[] da, double val) {
        double[] out = new double[da.length];
        for (int i = 0; i < out.length; i++) {
            out[i] = Math.min(da[i], val);
        }
        return out;
    }

    /**
     * @param a - the first array of input values.
     * @param b - the second array of input values.
     * @return an array containing the pair-wise minimum among two arrays.
     */

    public static double[] minOf(double[] a, double[] b) {
        double[] out = new double[a.length];
        for (int i = 0; i < out.length; i++) {
            out[i] = Math.min(a[i], b[i]);
        }
        return out;
    }

    /**
     * Returns the minimum value in vector of doubles.
     * @param da - input vector of doubles.
     * @return - the minimum value within the vector.
     */

    public static double min(double[] da) {
        if (da.length == 0) {
            return Double.NaN;
        }
        double out = Double.POSITIVE_INFINITY;
        for (int i = 0; i < da.length; i++) {
            out = Math.min(out, da[i]);
        }
        return out;
    }

    /**
     * @param da - a vector of double values.
     * @param val - the comparison value.
     * @return the minimum value between an array of doubles and a given value.
     */

    public static double min(double[] da, double val) {
        double out = val;
        for (int i = 0; i < da.length; i++) {
            out = Math.min(out, da[i]);
        }
        return out;
    }
}

Related

  1. minmax(String args[], boolean minimum)
  2. minMaxAvg(int[] arr)
  3. minMaxOverArraySubset(double[] array, Iterable subset, boolean min)
  4. minNonNeg(int... vals)
  5. minNum(Number iArr[])
  6. minOfArr(int[] arrInput)
  7. minOfArray(float[] array)
  8. minOfCol(int[][] matrixTable, int colBound)
  9. minOfSortedValues(double[] sortedValues)