Top Description Fields Constructors Methods
org.apache.commons.math3.complex

public Class RootsOfUnity

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable, org.apache.commons.math3.exception.MathIllegalArgumentException, .MathIllegalStateException, .OutOfRangeException, .ZeroException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.util.FastMath

A helper class for the computation and caching of the n-th roots of unity.
Since
3.0

Field Summary

Modifier and TypeField and Description
private boolean
isCounterClockWise

true if computeRoots(int) was called with a positive value of its argument n.

private int
omegaCount

Number of roots of unity.

private double[]
omegaImaginaryClockwise

Imaginary part of the n-th roots of unity, for negative values of n.

private double[]
omegaImaginaryCounterClockwise

Imaginary part of the n-th roots of unity, for positive values of n.

private double[]
omegaReal

Real part of the roots.

private static final long
serialVersionUID

Serializable version id.

Constructor Summary

AccessConstructor and Description
public
RootsOfUnity()

Build an engine for computing the n-th roots of unity.

Method Summary

Modifier and TypeMethod and Description
public synchronized void
computeRoots(int
the (signed) number of roots of unity to be computed
n
)

Computes the n-th roots of unity.

public synchronized double

Returns:

imaginary part of the k-th n-th root of unity
getImaginary
(int
index of the n-th root of unity
k
)

Get the imaginary part of the k-th n-th root of unity.

public synchronized int

Returns:

the number of roots of unity currently stored
getNumberOfRoots
()

Returns the number of roots of unity currently stored.

public synchronized double

Returns:

real part of the k-th n-th root of unity
getReal
(int
index of the n-th root of unity
k
)

Get the real part of the k-th n-th root of unity.

public synchronized boolean

Returns:

true if the roots of unity are stored in counter-clockwise order
isCounterClockWise
()

Returns true if computeRoots(int) was called with a positive value of its argument n.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

isCounterClockWiseback to summary
private boolean isCounterClockWise

true if computeRoots(int) was called with a positive value of its argument n. In this case, counter-clockwise ordering of the roots of unity should be used.

omegaCountback to summary
private int omegaCount

Number of roots of unity.

omegaImaginaryClockwiseback to summary
private double[] omegaImaginaryClockwise

Imaginary part of the n-th roots of unity, for negative values of n. In this array, the roots are stored in clockwise order.

omegaImaginaryCounterClockwiseback to summary
private double[] omegaImaginaryCounterClockwise

Imaginary part of the n-th roots of unity, for positive values of n. In this array, the roots are stored in counter-clockwise order.

omegaRealback to summary
private double[] omegaReal

Real part of the roots.

serialVersionUIDback to summary
private static final long serialVersionUID

Serializable version id.

Constructor Detail

RootsOfUnityback to summary
public RootsOfUnity()

Build an engine for computing the n-th roots of unity.

Method Detail

computeRootsback to summary
public synchronized void computeRoots(int n) throws ZeroException

Computes the n-th roots of unity. The roots are stored in omega[], such that omega[k] = w ^ k, where k = 0, ..., n - 1, w = exp(2 * pi * i / n) and i = sqrt(-1).

Note that n can be positive of negative

  • abs(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:int

the (signed) number of roots of unity to be computed

Exceptions
ZeroException:
if n = 0
getImaginaryback to summary
public synchronized double getImaginary(int k) throws MathIllegalStateException, OutOfRangeException

Get the imaginary part of the k-th n-th root of unity.

Parameters
k:int

index of the n-th root of unity

Returns:double

imaginary part of the k-th n-th root of unity

Exceptions
MathIllegalStateException:
if no roots of unity have been computed yet
OutOfRangeException:
if k is out of range
getNumberOfRootsback to summary
public synchronized int getNumberOfRoots()

Returns the number of roots of unity currently stored. If computeRoots(int) was called with n, then this method returns abs(n). If no roots of unity have been computed yet, this method returns 0.

Returns:int

the number of roots of unity currently stored

getRealback to summary
public synchronized double getReal(int k) throws MathIllegalStateException, MathIllegalArgumentException

Get the real part of the k-th n-th root of unity.

Parameters
k:int

index of the n-th root of unity

Returns:double

real part of the k-th n-th root of unity

Exceptions
MathIllegalStateException:
if no roots of unity have been computed yet
MathIllegalArgumentException:
if k is out of range
isCounterClockWiseback to summary
public synchronized boolean isCounterClockWise() throws MathIllegalStateException

Returns true if computeRoots(int) was called with a positive value of its argument n. If true, then counter-clockwise ordering of the roots of unity should be used.

Returns:boolean

true if the roots of unity are stored in counter-clockwise order

Exceptions
MathIllegalStateException:
if no roots of unity have been computed yet