Java Array Invert invert(float[] a)

Here you can find the source of invert(float[] a)

Description

invert

License

Open Source License

Parameter

Parameter Description
a a

Return

c

Declaration

public static float[] invert(float[] a) 

Method Source Code

//package com.java2s;
/**// ww  w. ja  v a 2 s. c  o  m
 * Copyright 2004-2006 DFKI GmbH.
 * All Rights Reserved.  Use is subject to license terms.
 *
 * This file is part of MARY TTS.
 *
 * MARY TTS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

public class Main {
    /**
     * Returns the multiplicative inverse (element-wise 1/x) of an array
     * 
     * @param a
     *            array to invert
     * @return a new array of the same size as <b>a</b>, in which each element is equal to the multiplicative inverse of the
     *         corresponding element in <b>a</b>
     * @throws IllegalArgumentException
     *             if the array is null
     */
    public static double[] invert(double[] a) throws IllegalArgumentException {
        if (a == null) {
            throw new IllegalArgumentException("Argument cannot be null");
        }
        double[] c = new double[a.length];
        for (int i = 0; i < a.length; i++) {
            c[i] = 1.0 / a[i];
        }
        return c;
    }

    /**
     * @param a
     *            a
     * @return c
     * @see #invert(double[])
     */
    public static float[] invert(float[] a) {
        if (a == null) {
            throw new IllegalArgumentException("Argument cannot be null");
        }
        float[] c = new float[a.length];
        for (int i = 0; i < a.length; i++) {
            c[i] = 1.0f / a[i];
        }
        return c;
    }
}

Related

  1. invert(byte abyte0[])
  2. invert(byte[] array)
  3. invert(byte[] bytes)
  4. invert(byte[] v)
  5. invert(double[] ary)
  6. invert(float[] m, float[] invOut)
  7. invert(int[] bits)
  8. invert(int[] v)
  9. invert(Object[] array)