本文整理汇总了Java中org.apache.commons.math3.exception.util.LocalizedFormats.CANNOT_COMPUTE_0TH_ROOT_OF_UNITY属性的典型用法代码示例。如果您正苦于以下问题:Java LocalizedFormats.CANNOT_COMPUTE_0TH_ROOT_OF_UNITY属性的具体用法?Java LocalizedFormats.CANNOT_COMPUTE_0TH_ROOT_OF_UNITY怎么用?Java LocalizedFormats.CANNOT_COMPUTE_0TH_ROOT_OF_UNITY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.commons.math3.exception.util.LocalizedFormats
的用法示例。
在下文中一共展示了LocalizedFormats.CANNOT_COMPUTE_0TH_ROOT_OF_UNITY属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeRoots
/**
* <p>
* 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)}.
* </p>
* <p>
* Note that {@code n} can be positive of negative
* </p>
* <ul>
* <li>{@code abs(n)} is always the number of roots of unity.</li>
* <li>If {@code n > 0}, then the roots are stored in counter-clockwise order.</li>
* <li>If {@code n < 0}, then the roots are stored in clockwise order.</p>
* </ul>
*
* @param n the (signed) number of roots of unity to be computed
* @throws ZeroException if {@code n = 0}
*/
public synchronized void computeRoots(int n) throws ZeroException {
if (n == 0) {
throw new ZeroException(
LocalizedFormats.CANNOT_COMPUTE_0TH_ROOT_OF_UNITY);
}
isCounterClockWise = n > 0;
// avoid repetitive calculations
final int absN = FastMath.abs(n);
if (absN == omegaCount) {
return;
}
// calculate everything from scratch
final double t = 2.0 * FastMath.PI / absN;
final double cosT = FastMath.cos(t);
final double sinT = FastMath.sin(t);
omegaReal = new double[absN];
omegaImaginaryCounterClockwise = new double[absN];
omegaImaginaryClockwise = new double[absN];
omegaReal[0] = 1.0;
omegaImaginaryCounterClockwise[0] = 0.0;
omegaImaginaryClockwise[0] = 0.0;
for (int i = 1; i < absN; i++) {
omegaReal[i] = omegaReal[i - 1] * cosT -
omegaImaginaryCounterClockwise[i - 1] * sinT;
omegaImaginaryCounterClockwise[i] = omegaReal[i - 1] * sinT +
omegaImaginaryCounterClockwise[i - 1] * cosT;
omegaImaginaryClockwise[i] = -omegaImaginaryCounterClockwise[i];
}
omegaCount = absN;
}