Skip to content

Commit

Permalink
MATH-1416: Delete functionality available in "Commons Numbers".
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilles committed Jun 3, 2017
1 parent af7f247 commit 6f27b4a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 41 deletions.
23 changes: 0 additions & 23 deletions src/main/java/org/apache/commons/math4/util/MathUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,29 +85,6 @@ public static int hash(double[] value) {
return Arrays.hashCode(value);
}

/**
* Normalize an angle in a 2π wide interval around a center value.
* <p>This method has three main uses:</p>
* <ul>
* <li>normalize an angle between 0 and 2&pi;:<br>
* {@code a = MathUtils.normalizeAngle(a, FastMath.PI);}</li>
* <li>normalize an angle between -&pi; and +&pi;<br>
* {@code a = MathUtils.normalizeAngle(a, 0.0);}</li>
* <li>compute the angle between two defining angular positions:<br>
* {@code angle = MathUtils.normalizeAngle(end, start) - start;}</li>
* </ul>
* <p>Note that due to numerical accuracy and since &pi; cannot be represented
* exactly, the result interval is <em>closed</em>, it cannot be half-closed
* as would be more satisfactory in a purely mathematical view.</p>
* @param a angle to normalize
* @param center center of the desired 2&pi; interval for the result
* @return a-2k&pi; with integer k and center-&pi; &lt;= a-2k&pi; &lt;= center+&pi;
* @since 1.2
*/
public static double normalizeAngle(double a, double center) {
return a - TWO_PI * FastMath.floor((a + FastMath.PI - center) / TWO_PI);
}

/** Find the maximum of two field elements.
* @param <T> the type of the field elements
* @param e1 first element
Expand Down
24 changes: 6 additions & 18 deletions src/test/java/org/apache/commons/math4/util/MathUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package org.apache.commons.math4.util;

import org.apache.commons.numbers.angle.PlaneAngleRadians;
import org.apache.commons.math4.distribution.RealDistribution;
import org.apache.commons.math4.distribution.UniformRealDistribution;
import org.apache.commons.math4.exception.MathArithmeticException;
Expand Down Expand Up @@ -153,19 +154,6 @@ public void testIndicatorShort() {
Assert.assertEquals((short)(-1), MathUtils.copySign((short)1, (short)(-2)));
}

@Test
public void testNormalizeAngle() {
for (double a = -15.0; a <= 15.0; a += 0.1) {
for (double b = -15.0; b <= 15.0; b += 0.2) {
double c = MathUtils.normalizeAngle(a, b);
Assert.assertTrue((b - FastMath.PI) <= c);
Assert.assertTrue(c <= (b + FastMath.PI));
double twoK = FastMath.rint((a - c) / FastMath.PI);
Assert.assertEquals(c, a - twoK * FastMath.PI, 1.0e-14);
}
}
}

@Test
public void testReduce() {
final double period = -12.222;
Expand Down Expand Up @@ -220,15 +208,15 @@ public void testReduce() {
}

@Test
public void testReduceComparedWithNormalizeAngle() {
final double tol = Math.ulp(1d);
public void testReduceComparedWithNormalize() {
final double period = 2 * Math.PI;
for (double a = -15; a <= 15; a += 0.5) {
for (double center = -15; center <= 15; center += 1) {
final double nA = MathUtils.normalizeAngle(a, center);
final double nA = PlaneAngleRadians.normalize(a, center);
final double offset = center - Math.PI;
final double r = MathUtils.reduce(a, period, offset);
Assert.assertEquals(nA, r + offset, tol);
final double r = MathUtils.reduce(a, period, offset) + offset;
Assert.assertEquals("a=" + a + " center=" + center,
nA, r, 52 * Math.ulp(nA));
}
}
}
Expand Down

0 comments on commit 6f27b4a

Please sign in to comment.