Java Code Examples for org.apache.commons.math3.exception.util.LocalizedFormats#CANNOT_COMPUTE_0TH_ROOT_OF_UNITY

The following examples show how to use org.apache.commons.math3.exception.util.LocalizedFormats#CANNOT_COMPUTE_0TH_ROOT_OF_UNITY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RootsOfUnity.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Computes the {@code n}-th roots of unity. The roots are stored in
 * {@code omega[]}, such that {@code omega[k] = w ^ k}, where
 * {@code k = 0, ..., n - 1}, {@code w = exp(2 * pi * i / n)} and
 * {@code i = sqrt(-1)}.
 * </p>
 * <p>
 * Note that {@code n} can be positive of negative
 * </p>
 * <ul>
 * <li>{@code abs(n)} is always the number of roots of unity.</li>
 * <li>If {@code n > 0}, then the roots are stored in counter-clockwise order.</li>
 * <li>If {@code n < 0}, then the roots are stored in clockwise order.</p>
 * </ul>
 *
 * @param n the (signed) number of roots of unity to be computed
 * @throws ZeroException if {@code n = 0}
 */
public synchronized void computeRoots(int n) throws ZeroException {

    if (n == 0) {
        throw new ZeroException(
                LocalizedFormats.CANNOT_COMPUTE_0TH_ROOT_OF_UNITY);
    }

    isCounterClockWise = n > 0;

    // avoid repetitive calculations
    final int absN = FastMath.abs(n);

    if (absN == omegaCount) {
        return;
    }

    // calculate everything from scratch
    final double t = 2.0 * FastMath.PI / absN;
    final double cosT = FastMath.cos(t);
    final double sinT = FastMath.sin(t);
    omegaReal = new double[absN];
    omegaImaginaryCounterClockwise = new double[absN];
    omegaImaginaryClockwise = new double[absN];
    omegaReal[0] = 1.0;
    omegaImaginaryCounterClockwise[0] = 0.0;
    omegaImaginaryClockwise[0] = 0.0;
    for (int i = 1; i < absN; i++) {
        omegaReal[i] = omegaReal[i - 1] * cosT -
                omegaImaginaryCounterClockwise[i - 1] * sinT;
        omegaImaginaryCounterClockwise[i] = omegaReal[i - 1] * sinT +
                omegaImaginaryCounterClockwise[i - 1] * cosT;
        omegaImaginaryClockwise[i] = -omegaImaginaryCounterClockwise[i];
    }
    omegaCount = absN;
}
 
Example 2
Source File: RootsOfUnity.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Computes the {@code n}-th roots of unity. The roots are stored in
 * {@code omega[]}, such that {@code omega[k] = w ^ k}, where
 * {@code k = 0, ..., n - 1}, {@code w = exp(2 * pi * i / n)} and
 * {@code i = sqrt(-1)}.
 * </p>
 * <p>
 * Note that {@code n} can be positive of negative
 * </p>
 * <ul>
 * <li>{@code abs(n)} is always the number of roots of unity.</li>
 * <li>If {@code n > 0}, then the roots are stored in counter-clockwise order.</li>
 * <li>If {@code n < 0}, then the roots are stored in clockwise order.</p>
 * </ul>
 *
 * @param n the (signed) number of roots of unity to be computed
 * @throws ZeroException if {@code n = 0}
 */
public synchronized void computeRoots(int n) throws ZeroException {

    if (n == 0) {
        throw new ZeroException(
                LocalizedFormats.CANNOT_COMPUTE_0TH_ROOT_OF_UNITY);
    }

    isCounterClockWise = n > 0;

    // avoid repetitive calculations
    final int absN = FastMath.abs(n);

    if (absN == omegaCount) {
        return;
    }

    // calculate everything from scratch
    final double t = 2.0 * FastMath.PI / absN;
    final double cosT = FastMath.cos(t);
    final double sinT = FastMath.sin(t);
    omegaReal = new double[absN];
    omegaImaginaryCounterClockwise = new double[absN];
    omegaImaginaryClockwise = new double[absN];
    omegaReal[0] = 1.0;
    omegaImaginaryCounterClockwise[0] = 0.0;
    omegaImaginaryClockwise[0] = 0.0;
    for (int i = 1; i < absN; i++) {
        omegaReal[i] = omegaReal[i - 1] * cosT -
                omegaImaginaryCounterClockwise[i - 1] * sinT;
        omegaImaginaryCounterClockwise[i] = omegaReal[i - 1] * sinT +
                omegaImaginaryCounterClockwise[i - 1] * cosT;
        omegaImaginaryClockwise[i] = -omegaImaginaryCounterClockwise[i];
    }
    omegaCount = absN;
}
 
Example 3
Source File: RootsOfUnity.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Computes the {@code n}-th roots of unity. The roots are stored in
 * {@code omega[]}, such that {@code omega[k] = w ^ k}, where
 * {@code k = 0, ..., n - 1}, {@code w = exp(2 * pi * i / n)} and
 * {@code i = sqrt(-1)}.
 * </p>
 * <p>
 * Note that {@code n} can be positive of negative
 * </p>
 * <ul>
 * <li>{@code abs(n)} is always the number of roots of unity.</li>
 * <li>If {@code n > 0}, then the roots are stored in counter-clockwise order.</li>
 * <li>If {@code n < 0}, then the roots are stored in clockwise order.</p>
 * </ul>
 *
 * @param n the (signed) number of roots of unity to be computed
 * @throws ZeroException if {@code n = 0}
 */
public synchronized void computeRoots(int n) throws ZeroException {

    if (n == 0) {
        throw new ZeroException(
                LocalizedFormats.CANNOT_COMPUTE_0TH_ROOT_OF_UNITY);
    }

    isCounterClockWise = n > 0;

    // avoid repetitive calculations
    final int absN = FastMath.abs(n);

    if (absN == omegaCount) {
        return;
    }

    // calculate everything from scratch
    final double t = 2.0 * FastMath.PI / absN;
    final double cosT = FastMath.cos(t);
    final double sinT = FastMath.sin(t);
    omegaReal = new double[absN];
    omegaImaginaryCounterClockwise = new double[absN];
    omegaImaginaryClockwise = new double[absN];
    omegaReal[0] = 1.0;
    omegaImaginaryCounterClockwise[0] = 0.0;
    omegaImaginaryClockwise[0] = 0.0;
    for (int i = 1; i < absN; i++) {
        omegaReal[i] = omegaReal[i - 1] * cosT -
                omegaImaginaryCounterClockwise[i - 1] * sinT;
        omegaImaginaryCounterClockwise[i] = omegaReal[i - 1] * sinT +
                omegaImaginaryCounterClockwise[i - 1] * cosT;
        omegaImaginaryClockwise[i] = -omegaImaginaryCounterClockwise[i];
    }
    omegaCount = absN;
}
 
Example 4
Source File: RootsOfUnity.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Computes the {@code n}-th roots of unity. The roots are stored in
 * {@code omega[]}, such that {@code omega[k] = w ^ k}, where
 * {@code k = 0, ..., n - 1}, {@code w = exp(2 * pi * i / n)} and
 * {@code i = sqrt(-1)}.
 * </p>
 * <p>
 * Note that {@code n} can be positive of negative
 * </p>
 * <ul>
 * <li>{@code abs(n)} is always the number of roots of unity.</li>
 * <li>If {@code n > 0}, then the roots are stored in counter-clockwise order.</li>
 * <li>If {@code n < 0}, then the roots are stored in clockwise order.</p>
 * </ul>
 *
 * @param n the (signed) number of roots of unity to be computed
 * @throws ZeroException if {@code n = 0}
 */
public synchronized void computeRoots(int n) throws ZeroException {

    if (n == 0) {
        throw new ZeroException(
                LocalizedFormats.CANNOT_COMPUTE_0TH_ROOT_OF_UNITY);
    }

    isCounterClockWise = n > 0;

    // avoid repetitive calculations
    final int absN = FastMath.abs(n);

    if (absN == omegaCount) {
        return;
    }

    // calculate everything from scratch
    final double t = 2.0 * FastMath.PI / absN;
    final double cosT = FastMath.cos(t);
    final double sinT = FastMath.sin(t);
    omegaReal = new double[absN];
    omegaImaginaryCounterClockwise = new double[absN];
    omegaImaginaryClockwise = new double[absN];
    omegaReal[0] = 1.0;
    omegaImaginaryCounterClockwise[0] = 0.0;
    omegaImaginaryClockwise[0] = 0.0;
    for (int i = 1; i < absN; i++) {
        omegaReal[i] = omegaReal[i - 1] * cosT -
                omegaImaginaryCounterClockwise[i - 1] * sinT;
        omegaImaginaryCounterClockwise[i] = omegaReal[i - 1] * sinT +
                omegaImaginaryCounterClockwise[i - 1] * cosT;
        omegaImaginaryClockwise[i] = -omegaImaginaryCounterClockwise[i];
    }
    omegaCount = absN;
}
 
Example 5
Source File: RootsOfUnity.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Computes the {@code n}-th roots of unity. The roots are stored in
 * {@code omega[]}, such that {@code omega[k] = w ^ k}, where
 * {@code k = 0, ..., n - 1}, {@code w = exp(2 * pi * i / n)} and
 * {@code i = sqrt(-1)}.
 * </p>
 * <p>
 * Note that {@code n} can be positive of negative
 * </p>
 * <ul>
 * <li>{@code abs(n)} is always the number of roots of unity.</li>
 * <li>If {@code n > 0}, then the roots are stored in counter-clockwise order.</li>
 * <li>If {@code n < 0}, then the roots are stored in clockwise order.</p>
 * </ul>
 *
 * @param n the (signed) number of roots of unity to be computed
 * @throws ZeroException if {@code n = 0}
 */
public synchronized void computeRoots(int n) throws ZeroException {

    if (n == 0) {
        throw new ZeroException(
                LocalizedFormats.CANNOT_COMPUTE_0TH_ROOT_OF_UNITY);
    }

    isCounterClockWise = n > 0;

    // avoid repetitive calculations
    final int absN = FastMath.abs(n);

    if (absN == omegaCount) {
        return;
    }

    // calculate everything from scratch
    final double t = 2.0 * FastMath.PI / absN;
    final double cosT = FastMath.cos(t);
    final double sinT = FastMath.sin(t);
    omegaReal = new double[absN];
    omegaImaginaryCounterClockwise = new double[absN];
    omegaImaginaryClockwise = new double[absN];
    omegaReal[0] = 1.0;
    omegaImaginaryCounterClockwise[0] = 0.0;
    omegaImaginaryClockwise[0] = 0.0;
    for (int i = 1; i < absN; i++) {
        omegaReal[i] = omegaReal[i - 1] * cosT -
                omegaImaginaryCounterClockwise[i - 1] * sinT;
        omegaImaginaryCounterClockwise[i] = omegaReal[i - 1] * sinT +
                omegaImaginaryCounterClockwise[i - 1] * cosT;
        omegaImaginaryClockwise[i] = -omegaImaginaryCounterClockwise[i];
    }
    omegaCount = absN;
}
 
Example 6
Source File: RootsOfUnity.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Computes the {@code n}-th roots of unity. The roots are stored in
 * {@code omega[]}, such that {@code omega[k] = w ^ k}, where
 * {@code k = 0, ..., n - 1}, {@code w = exp(2 * pi * i / n)} and
 * {@code i = sqrt(-1)}.
 * </p>
 * <p>
 * Note that {@code n} can be positive of negative
 * </p>
 * <ul>
 * <li>{@code abs(n)} is always the number of roots of unity.</li>
 * <li>If {@code n > 0}, then the roots are stored in counter-clockwise order.</li>
 * <li>If {@code n < 0}, then the roots are stored in clockwise order.</p>
 * </ul>
 *
 * @param n the (signed) number of roots of unity to be computed
 * @throws ZeroException if {@code n = 0}
 */
public synchronized void computeRoots(int n) throws ZeroException {

    if (n == 0) {
        throw new ZeroException(
                LocalizedFormats.CANNOT_COMPUTE_0TH_ROOT_OF_UNITY);
    }

    isCounterClockWise = n > 0;

    // avoid repetitive calculations
    final int absN = FastMath.abs(n);

    if (absN == omegaCount) {
        return;
    }

    // calculate everything from scratch
    final double t = 2.0 * FastMath.PI / absN;
    final double cosT = FastMath.cos(t);
    final double sinT = FastMath.sin(t);
    omegaReal = new double[absN];
    omegaImaginaryCounterClockwise = new double[absN];
    omegaImaginaryClockwise = new double[absN];
    omegaReal[0] = 1.0;
    omegaImaginaryCounterClockwise[0] = 0.0;
    omegaImaginaryClockwise[0] = 0.0;
    for (int i = 1; i < absN; i++) {
        omegaReal[i] = omegaReal[i - 1] * cosT -
                omegaImaginaryCounterClockwise[i - 1] * sinT;
        omegaImaginaryCounterClockwise[i] = omegaReal[i - 1] * sinT +
                omegaImaginaryCounterClockwise[i - 1] * cosT;
        omegaImaginaryClockwise[i] = -omegaImaginaryCounterClockwise[i];
    }
    omegaCount = absN;
}
 
Example 7
Source File: RootsOfUnity.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Computes the {@code n}-th roots of unity. The roots are stored in
 * {@code omega[]}, such that {@code omega[k] = w ^ k}, where
 * {@code k = 0, ..., n - 1}, {@code w = exp(2 * pi * i / n)} and
 * {@code i = sqrt(-1)}.
 * </p>
 * <p>
 * Note that {@code n} can be positive of negative
 * </p>
 * <ul>
 * <li>{@code abs(n)} is always the number of roots of unity.</li>
 * <li>If {@code n > 0}, then the roots are stored in counter-clockwise order.</li>
 * <li>If {@code n < 0}, then the roots are stored in clockwise order.</p>
 * </ul>
 *
 * @param n the (signed) number of roots of unity to be computed
 * @throws ZeroException if {@code n = 0}
 */
public synchronized void computeRoots(int n) throws ZeroException {

    if (n == 0) {
        throw new ZeroException(
                LocalizedFormats.CANNOT_COMPUTE_0TH_ROOT_OF_UNITY);
    }

    isCounterClockWise = n > 0;

    // avoid repetitive calculations
    final int absN = FastMath.abs(n);

    if (absN == omegaCount) {
        return;
    }

    // calculate everything from scratch
    final double t = 2.0 * FastMath.PI / absN;
    final double cosT = FastMath.cos(t);
    final double sinT = FastMath.sin(t);
    omegaReal = new double[absN];
    omegaImaginaryCounterClockwise = new double[absN];
    omegaImaginaryClockwise = new double[absN];
    omegaReal[0] = 1.0;
    omegaImaginaryCounterClockwise[0] = 0.0;
    omegaImaginaryClockwise[0] = 0.0;
    for (int i = 1; i < absN; i++) {
        omegaReal[i] = omegaReal[i - 1] * cosT -
                omegaImaginaryCounterClockwise[i - 1] * sinT;
        omegaImaginaryCounterClockwise[i] = omegaReal[i - 1] * sinT +
                omegaImaginaryCounterClockwise[i - 1] * cosT;
        omegaImaginaryClockwise[i] = -omegaImaginaryCounterClockwise[i];
    }
    omegaCount = absN;
}
 
Example 8
Source File: RootsOfUnity.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Computes the {@code n}-th roots of unity. The roots are stored in
 * {@code omega[]}, such that {@code omega[k] = w ^ k}, where
 * {@code k = 0, ..., n - 1}, {@code w = exp(2 * pi * i / n)} and
 * {@code i = sqrt(-1)}.
 * </p>
 * <p>
 * Note that {@code n} can be positive of negative
 * </p>
 * <ul>
 * <li>{@code abs(n)} is always the number of roots of unity.</li>
 * <li>If {@code n > 0}, then the roots are stored in counter-clockwise order.</li>
 * <li>If {@code n < 0}, then the roots are stored in clockwise order.</p>
 * </ul>
 *
 * @param n the (signed) number of roots of unity to be computed
 * @throws ZeroException if {@code n = 0}
 */
public synchronized void computeRoots(int n) throws ZeroException {

    if (n == 0) {
        throw new ZeroException(
                LocalizedFormats.CANNOT_COMPUTE_0TH_ROOT_OF_UNITY);
    }

    isCounterClockWise = n > 0;

    // avoid repetitive calculations
    final int absN = FastMath.abs(n);

    if (absN == omegaCount) {
        return;
    }

    // calculate everything from scratch
    final double t = 2.0 * FastMath.PI / absN;
    final double cosT = FastMath.cos(t);
    final double sinT = FastMath.sin(t);
    omegaReal = new double[absN];
    omegaImaginaryCounterClockwise = new double[absN];
    omegaImaginaryClockwise = new double[absN];
    omegaReal[0] = 1.0;
    omegaImaginaryCounterClockwise[0] = 0.0;
    omegaImaginaryClockwise[0] = 0.0;
    for (int i = 1; i < absN; i++) {
        omegaReal[i] = omegaReal[i - 1] * cosT -
                omegaImaginaryCounterClockwise[i - 1] * sinT;
        omegaImaginaryCounterClockwise[i] = omegaReal[i - 1] * sinT +
                omegaImaginaryCounterClockwise[i - 1] * cosT;
        omegaImaginaryClockwise[i] = -omegaImaginaryCounterClockwise[i];
    }
    omegaCount = absN;
}