You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2013/02/15 09:20:11 UTC
svn commit: r1446473 - in /commons/proper/math/trunk/src: changes/changes.xml
main/java/org/apache/commons/math3/analysis/differentiation/DSCompiler.java
test/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructureTest.java
Author: luc
Date: Fri Feb 15 08:20:11 2013
New Revision: 1446473
URL: http://svn.apache.org/r1446473
Log:
Fixed DerivativeStructure.atan2 for special cases when both arguments
are +/-0.
JIRA: MATH-935
Modified:
commons/proper/math/trunk/src/changes/changes.xml
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/differentiation/DSCompiler.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructureTest.java
Modified: commons/proper/math/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/changes/changes.xml?rev=1446473&r1=1446472&r2=1446473&view=diff
==============================================================================
--- commons/proper/math/trunk/src/changes/changes.xml (original)
+++ commons/proper/math/trunk/src/changes/changes.xml Fri Feb 15 08:20:11 2013
@@ -55,6 +55,9 @@ This is a minor release: It combines bug
Changes to existing features were made in a backwards-compatible
way such as to allow drop-in replacement of the v3.1[.1] JAR file.
">
+ <action dev="luc" type="fix" issue="MATH-935" >
+ Fixed DerivativeStructure.atan2 for special cases when both arguments are +/-0.
+ </action>
<action dev="luc" type="add" >
Added accurate linear combination of DerivativeStructure instances,
avoiding cancellation.
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/differentiation/DSCompiler.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/differentiation/DSCompiler.java?rev=1446473&r1=1446472&r2=1446473&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/differentiation/DSCompiler.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/differentiation/DSCompiler.java Fri Feb 15 08:20:11 2013
@@ -1415,6 +1415,9 @@ public class DSCompiler {
}
+ // fix value to take special cases (+0/+0, +0/-0, -0/+0, -0/-0, +/-infinity) correctly
+ result[resultOffset] = FastMath.atan2(y[yOffset], x[xOffset]);
+
}
/** Compute hyperbolic cosine of a derivative structure.
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructureTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructureTest.java?rev=1446473&r1=1446472&r2=1446473&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructureTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructureTest.java Fri Feb 15 08:20:11 2013
@@ -808,6 +808,33 @@ public class DerivativeStructureTest {
}
@Test
+ public void testAtan2SpecialCases() {
+
+ DerivativeStructure pp =
+ DerivativeStructure.atan2(new DerivativeStructure(2, 2, 1, +0.0),
+ new DerivativeStructure(2, 2, 1, +0.0));
+ Assert.assertEquals(0, pp.getValue(), 1.0e-15);
+ Assert.assertEquals(+1, FastMath.copySign(1, pp.getValue()), 1.0e-15);
+
+ DerivativeStructure pn =
+ DerivativeStructure.atan2(new DerivativeStructure(2, 2, 1, +0.0),
+ new DerivativeStructure(2, 2, 1, -0.0));
+ Assert.assertEquals(FastMath.PI, pn.getValue(), 1.0e-15);
+
+ DerivativeStructure np =
+ DerivativeStructure.atan2(new DerivativeStructure(2, 2, 1, -0.0),
+ new DerivativeStructure(2, 2, 1, +0.0));
+ Assert.assertEquals(0, np.getValue(), 1.0e-15);
+ Assert.assertEquals(-1, FastMath.copySign(1, np.getValue()), 1.0e-15);
+
+ DerivativeStructure nn =
+ DerivativeStructure.atan2(new DerivativeStructure(2, 2, 1, -0.0),
+ new DerivativeStructure(2, 2, 1, -0.0));
+ Assert.assertEquals(-FastMath.PI, nn.getValue(), 1.0e-15);
+
+ }
+
+ @Test
public void testSinhDefinition() {
double[] epsilon = new double[] { 3.0e-16, 3.0e-16, 5.0e-16, 2.0e-15, 6.0e-15 };
for (int maxOrder = 0; maxOrder < 5; ++maxOrder) {