Author: luc
Date: Thu Aug 16 10:07:42 2012
New Revision: 1373780
URL: http://svn.apache.org/viewvc?rev=1373780&view=rev
Log:
Added rint and round to DerivativeStructure.
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructure.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructureTest.java
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructure.java
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructure.java?rev=1373780&r1=1373779&r2=1373780&view=diff
==============================================================================
---
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructure.java
(original)
+++
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructure.java
Thu Aug 16 10:07:42 2012
@@ -386,6 +386,22 @@ public class DerivativeStructure impleme
FastMath.floor(data[0]));
}
+ /** Get the whole number that is the nearest to the instance, or the even
one if x is exactly half way between two integers.
+ * @return a double number r such that r is an integer r - 0.5 <= this <=
r + 0.5
+ */
+ public DerivativeStructure rint() {
+ return new DerivativeStructure(compiler.getFreeParameters(),
+ compiler.getOrder(),
+ FastMath.rint(data[0]));
+ }
+
+ /** Get the closest long to instance value.
+ * @return closest long to {@link #getValue()}
+ */
+ public long round() {
+ return FastMath.round(data[0]);
+ }
+
/**
* Returns the instance with the sign of the argument.
* A NaN {@code sign} argument is treated as positive.
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=1373780&r1=1373779&r2=1373780&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
Thu Aug 16 10:07:42 2012
@@ -838,7 +838,7 @@ public class DerivativeStructureTest {
}
@Test
- public void testCeilFloor() {
+ public void testCeilFloorRintLong() {
DerivativeStructure x = new DerivativeStructure(1, 1, 0, -1.5);
Assert.assertEquals(-1.5, x.getPartialDerivative(0), 1.0e-15);
@@ -847,6 +847,10 @@ public class DerivativeStructureTest {
Assert.assertEquals(+0.0, x.ceil().getPartialDerivative(1), 1.0e-15);
Assert.assertEquals(-2.0, x.floor().getPartialDerivative(0), 1.0e-15);
Assert.assertEquals(+0.0, x.floor().getPartialDerivative(1), 1.0e-15);
+ Assert.assertEquals(-2.0, x.rint().getPartialDerivative(0), 1.0e-15);
+ Assert.assertEquals(+0.0, x.rint().getPartialDerivative(1), 1.0e-15);
+ Assert.assertEquals(-2.0,
x.subtract(x.getField().getOne()).rint().getPartialDerivative(0), 1.0e-15);
+ Assert.assertEquals(-1l, x.round());
}