Java Array Divide divide(final double[] v1, final double[] v2)

Here you can find the source of divide(final double[] v1, final double[] v2)

Description

divide

License

Open Source License

Declaration

public static double[] divide(final double[] v1, final double[] v2) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2015 Vienna University of Technology.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://  w w  w  .  j  a  v  a  2s  .  co  m
 * Martin Fleck (Vienna University of Technology) - initial API and implementation
 *
 * Initially developed in the context of ARTIST EU project www.artist-project.eu
 *******************************************************************************/

public class Main {
    private static final String VECTORS_DIFFERENT_LENGTHS = "Vector v1 and v2 have different lengths";

    public static double[] divide(final double[] v1, final double[] v2) {
        if (v1.length != v2.length) {
            throw new RuntimeException(VECTORS_DIFFERENT_LENGTHS);
        }

        final double[] result = new double[v1.length];
        for (int i = 0; i < result.length; i++) {
            if (v2[i] != 0) {
                result[i] = v1[i] / v2[i];
            } else if (v1[i] < 0) {
                result[i] = Double.NEGATIVE_INFINITY;
            } else {
                result[i] = Double.POSITIVE_INFINITY;
            }
        }
        return result;
    }
}

Related

  1. divide(double[] numerator, double[] denominator)
  2. divide(double[] t1, double[] t2)
  3. divide(double[][] arr1, double[][] arr2)
  4. divide(double[][] numerator, double[][] denominator)
  5. divide(final double[] numerators, final double[] denominators)
  6. divide(float[] array, float divident)
  7. divide(float[][] a, float num)
  8. divide(float[][][][] img, float val)
  9. divide(long[] array, double value)