diff --git a/src/main/java/org/apache/commons/math/complex/RootsOfUnity.java b/src/main/java/org/apache/commons/math/complex/RootsOfUnity.java index 0b53bfbdc..f14dad94c 100644 --- a/src/main/java/org/apache/commons/math/complex/RootsOfUnity.java +++ b/src/main/java/org/apache/commons/math/complex/RootsOfUnity.java @@ -26,8 +26,8 @@ import org.apache.commons.math.exception.util.LocalizedFormats; import org.apache.commons.math.util.FastMath; /** - * A helper class for the computation and caching of the {@code n}th - * roots of unity. + * A helper class for the computation and caching of the {@code n}-th roots of + * unity. * * @version $Id$ * @since 3.0 @@ -43,59 +43,75 @@ public class RootsOfUnity implements Serializable { /** Real part of the roots. */ private double[] omegaReal; - /** Imaginary part of the roots for forward transform. */ - private double[] omegaImaginaryForward; - - /** Imaginary part of the roots for reverse transform. */ - private double[] omegaImaginaryInverse; - - /** Forward/reverse indicator. */ - private boolean isForward; + /** + * Imaginary part of the {@code n}-th roots of unity, for positive values + * of {@code n}. In this array, the roots are stored in counter-clockwise + * order. + */ + private double[] omegaImaginaryCounterClockwise; /** - * Build an engine for computing the {@code n}th roots of - * unity. + * Imaginary part of the {@code n}-th roots of unity, for negative values + * of {@code n}. In this array, the roots are stored in clockwise order. + */ + private double[] omegaImaginaryClockwise; + + /** + * {@code true} if {@link #computeOmega(int)} was called with a positive + * value of its argument {@code n}. In this case, counter-clockwise ordering + * of the roots of unity should be used. + */ + private boolean isCounterClockWise; + + /** + * Build an engine for computing the {@code n}-th roots of unity. */ public RootsOfUnity() { omegaCount = 0; omegaReal = null; - omegaImaginaryForward = null; - omegaImaginaryInverse = null; - isForward = true; + omegaImaginaryCounterClockwise = null; + omegaImaginaryClockwise = null; + isCounterClockWise = true; } /** - * Check if computation has been done for forward or reverse transform. + * Returns {@code true} if {@link #computeOmega(int)} was called with a + * positive value of its argument {@code n}. If {@code true}, then + * counter-clockwise ordering of the roots of unity should be used. * - * @return {@code true} if computation has been done for forward transform + * @return {@code true} if the roots of unity are stored in + * counter-clockwise order * @throws MathIllegalStateException if no roots of unity have been computed * yet */ - public synchronized boolean isForward() + public synchronized boolean isCounterClockWise() throws MathIllegalStateException { if (omegaCount == 0) { throw new MathIllegalStateException( LocalizedFormats.ROOTS_OF_UNITY_NOT_COMPUTED_YET); } - return isForward; + return isCounterClockWise; } /** *
- * 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 π i / n)} and + * 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)}. *
*- * Note that {@code n} is positive for forward transform and negative - * for inverse transform. + * Note that {@code n} can be positive of negative *
+ *