## 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.Serializable

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

Since:
  3.0
Version:
  $Id: RootsOfUnity.java 1416643 2012-12-03 19:37:14Z tn $
See Also:
  Serialized Form

Field Summary
`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 long` `serialVersionUID` Serializable version id.

Constructor Summary
`RootsOfUnity()` Build an engine for computing the `n`-th roots of unity.

Method Summary
`void` `computeRoots(int n)` Computes the `n`-th roots of unity.
`double` `getImaginary(int k)` Get the imaginary part of the `k`-th `n`-th root of unity.
`int` `getNumberOfRoots()` Returns the number of roots of unity currently stored.
`double` `getReal(int k)` Get the real part of the `k`-th `n`-th root of unity.
`boolean` `isCounterClockWise()` Returns `true` if `computeRoots(int)` was called with a positive value of its argument `n`.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

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 the `n`-th roots of unity, for positive values of `n`. In this array, the roots are stored in counter-clockwise order.

### omegaImaginaryClockwise

    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.

### isCounterClockWise

    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.

Constructor Detail

### RootsOfUnity

    public RootsOfUnity()

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

Method Detail

### isCounterClockWise

    public 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:
    `true` if 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 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` - the (signed) number of roots of unity to be computed
  Throws:
    `ZeroException` - if `n = 0`

### getReal

    public double getReal(int k)
                   throws MathIllegalStateException,
                          MathIllegalArgumentException

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

  Parameters:
    `k` - index of the `n`-th root of unity
  Returns:
    real part of the `k`-th `n`-th root of unity
  Throws:
    `MathIllegalStateException` - if no roots of unity have been computed yet
    `MathIllegalArgumentException` - if `k` is out of range

### getImaginary

    public double getImaginary(int k)
                        throws MathIllegalStateException,
                               OutOfRangeException

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

  Parameters:
    `k` - index of the `n`-th root of unity
  Returns:
    imaginary part of the `k`-th `n`-th root of unity
  Throws:
    `MathIllegalStateException` - if no roots of unity have been computed yet
    `OutOfRangeException` - if `k` is out of range

### getNumberOfRoots

    public 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:
    the number of roots of unity currently stored

Copyright (c) 2003-2013 Apache Software Foundation