Java Array Divide divide(long[] array, double value)

Here you can find the source of divide(long[] array, double value)

Description

Divides all elements in an array by a scalar.

License

Open Source License

Parameter

Parameter Description
array Input array
value Scalar

Return

A new array containing the input elements divided by the scalar

Declaration

public static double[] divide(long[] array, double value) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2016 Pablo Pavon-Marino.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 *
 * Contributors://from ww  w.  j  a v  a  2 s . c  o m
 *     Pablo Pavon-Marino - Jose-Luis Izquierdo-Zaragoza, up to version 0.3.1
 *     Pablo Pavon-Marino - from version 0.4.0 onwards
 ******************************************************************************/

public class Main {
    /**
     * Divides all elements in an array by a scalar.
     *
     * @param array Input array
     * @param value Scalar
     * @return A new array containing the input elements divided by the scalar
     * 
     */
    public static double[] divide(long[] array, double value) {
        double[] out = new double[array.length];

        for (int i = 0; i < out.length; i++) {
            out[i] = array[i] / value;
        }

        return out;
    }

    /**
     * Divides two arrays element-to-element.
     *
     * @param array1 Numerator
     * @param array2 Denominator
     * @return The element-wise division of the input arrays
     * 
     */
    public static double[] divide(long[] array1, long[] array2) {
        double[] out = new double[array1.length];
        for (int i = 0; i < out.length; i++)
            out[i] = (double) array1[i] / array2[i];

        return out;
    }
}

Related

  1. divide(final double[] v1, final double[] v2)
  2. divide(float[] array, float divident)
  3. divide(float[][] a, float num)
  4. divide(float[][][][] img, float val)
  5. divide(int[] array1, int[] array2)
  6. divideAbsolute(double[] one, double[] two)
  7. divideAndConquer(int[] array, int num)
  8. divideArray(float[] array, float num)
  9. divideArray(T[] arr, Integer... cuts)