Here you can find the source of divideNonSingular(int[] array1, int[] array2)
Parameter | Description |
---|---|
array1 | Numerator |
array2 | Denominator |
public static double[] divideNonSingular(int[] array1, int[] array2)
//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 ava2 s .co 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 two arrays element-to-element, but when numerator and denominator = 0, returns 0 instead of a singularity (NaN) * * @param array1 Numerator * @param array2 Denominator * @return The element-wise division of the input arrays */ public static double[] divideNonSingular(int[] array1, int[] array2) { double[] out = new double[array1.length]; for (int i = 0; i < out.length; i++) out[i] = array1[i] == 0 && array2[i] == 0 ? 0 : (double) array1[i] / array2[i]; return out; } }