Package org.apache.commons.math3.complex
Class RootsOfUnity
- java.lang.Object
-
- org.apache.commons.math3.complex.RootsOfUnity
-
- All Implemented Interfaces:
java.io.Serializable
public class RootsOfUnity extends java.lang.Object implements java.io.SerializableA helper class for the computation and caching of then-th roots of unity.- Since:
- 3.0
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private booleanisCounterClockWiseprivate intomegaCountNumber of roots of unity.private double[]omegaImaginaryClockwiseImaginary part of then-th roots of unity, for negative values ofn.private double[]omegaImaginaryCounterClockwiseImaginary part of then-th roots of unity, for positive values ofn.private double[]omegaRealReal part of the roots.private static longserialVersionUIDSerializable version id.
-
Constructor Summary
Constructors Constructor Description RootsOfUnity()Build an engine for computing then-th roots of unity.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcomputeRoots(int n)Computes then-th roots of unity.doublegetImaginary(int k)Get the imaginary part of thek-thn-th root of unity.intgetNumberOfRoots()Returns the number of roots of unity currently stored.doublegetReal(int k)Get the real part of thek-thn-th root of unity.booleanisCounterClockWise()
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Serializable version id.- See Also:
- Constant Field Values
-
omegaCount
private int omegaCount
Number of roots of unity.
-
omegaReal
private double[] omegaReal
Real part of the roots.
-
omegaImaginaryCounterClockwise
private double[] omegaImaginaryCounterClockwise
Imaginary part of then-th roots of unity, for positive values ofn. In this array, the roots are stored in counter-clockwise order.
-
omegaImaginaryClockwise
private double[] omegaImaginaryClockwise
Imaginary part of then-th roots of unity, for negative values ofn. In this array, the roots are stored in clockwise order.
-
isCounterClockWise
private boolean isCounterClockWise
trueifcomputeRoots(int)was called with a positive value of its argumentn. In this case, counter-clockwise ordering of the roots of unity should be used.
-
-
Method Detail
-
isCounterClockWise
public boolean isCounterClockWise() throws MathIllegalStateExceptionReturnstrueifcomputeRoots(int)was called with a positive value of its argumentn. Iftrue, then counter-clockwise ordering of the roots of unity should be used.- Returns:
trueif the roots of unity are stored in counter-clockwise order- Throws:
MathIllegalStateException- if no roots of unity have been computed yet
-
computeRoots
public void computeRoots(int n) throws ZeroExceptionComputes the
n-th roots of unity. The roots are stored inomega[], such thatomega[k] = w ^ k, wherek = 0, ..., n - 1,w = exp(2 * pi * i / n)andi = sqrt(-1).Note that
ncan be positive of negativeabs(n)is always the number of roots of unity.- If
n > 0, then the roots are stored in counter-clockwise order. - If
n < 0, then the roots are stored in clockwise order.
- Parameters:
n- the (signed) number of roots of unity to be computed- Throws:
ZeroException- ifn = 0
-
getReal
public double getReal(int k) throws MathIllegalStateException, MathIllegalArgumentExceptionGet the real part of thek-thn-th root of unity.- Parameters:
k- index of then-th root of unity- Returns:
- real part of the
k-thn-th root of unity - Throws:
MathIllegalStateException- if no roots of unity have been computed yetMathIllegalArgumentException- ifkis out of range
-
getImaginary
public double getImaginary(int k) throws MathIllegalStateException, OutOfRangeExceptionGet the imaginary part of thek-thn-th root of unity.- Parameters:
k- index of then-th root of unity- Returns:
- imaginary part of the
k-thn-th root of unity - Throws:
MathIllegalStateException- if no roots of unity have been computed yetOutOfRangeException- ifkis out of range
-
getNumberOfRoots
public int getNumberOfRoots()
Returns the number of roots of unity currently stored. IfcomputeRoots(int)was called withn, then this method returnsabs(n). If no roots of unity have been computed yet, this method returns 0.- Returns:
- the number of roots of unity currently stored
-
-