Package org.hipparchus.complex
Class RootsOfUnity
java.lang.Object
org.hipparchus.complex.RootsOfUnity
- All Implemented Interfaces:
Serializable
A helper class for the computation and caching of the
n
-th roots
of unity.- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
computeRoots
(int n) Computes then
-th roots of unity.double
getImaginary
(int k) Get the imaginary part of thek
-thn
-th root of unity.int
Returns the number of roots of unity currently stored.double
getReal
(int k) Get the real part of thek
-thn
-th root of unity.boolean
-
Constructor Details
-
RootsOfUnity
public RootsOfUnity()Build an engine for computing then
-th roots of unity.
-
-
Method Details
-
isCounterClockWise
Returnstrue
ifcomputeRoots(int)
was called with a positive value of its argumentn
. Iftrue
, then counter-clockwise ordering of the roots of unity should be used.- Returns:
true
if the roots of unity are stored in counter-clockwise order- Throws:
MathIllegalStateException
- if no roots of unity have been computed yet
-
computeRoots
Computes then
-th roots of unity.The roots are stored in
omega[]
, such thatomega[k] = w ^ k
, wherek = 0, ..., n - 1
,w = exp(2 * pi * i / n)
andi = sqrt(-1)
.Note that
n
can 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:
MathIllegalArgumentException
- ifn = 0
-
getReal
Get 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
- ifk
is out of range
-
getImaginary
Get 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 yetMathIllegalArgumentException
- ifk
is out of range
-
getNumberOfRoots
public int getNumberOfRoots()Returns the number of roots of unity currently stored.If
computeRoots(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
-