Java Array Normalize normalForm(int[] a)

Here you can find the source of normalForm(int[] a)

Description

normal Form

License

LGPL

Declaration

private static int[] normalForm(int[] a) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.util.Arrays;

public class Main {
    private static int[] normalForm(int[] a) {
        int d = computeDegree(a);

        // if a is the zero polynomial
        if (d == -1) {
            // return new zero polynomial
            return new int[1];
        }/* w ww .  j  a v  a2  s  .c om*/

        // if a already is in normal form
        if (a.length == d + 1) {
            // return a clone of a
            return Arrays.copyOf(a, a.length);
        }

        // else, reduce a
        int[] result = new int[d + 1];
        System.arraycopy(a, 0, result, 0, d + 1);
        return result;
    }

    @SuppressWarnings("empty-statement")
    private static int computeDegree(int[] a) {
        int degree;
        for (degree = a.length - 1; degree >= 0 && a[degree] == 0; degree--) {
            //empty
        }
        return degree;
    }
}

Related

  1. norm_variance(double[] array)
  2. norm_vec(double[] vec)
  3. normal0(double[] p1, double[] p2, double[] p3)
  4. normalCentralMoment(boolean[][] img, int p, int q)
  5. normalDist(double[] features, double[] avg, double[][] cov)
  6. normalHashCode(char[] val)
  7. normalise(double[] a)
  8. normalise(double[] A)
  9. normalise(float[] array)