commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r1373776 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructure.java test/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructureTest.java
Date Thu, 16 Aug 2012 10:06:33 GMT
Author: luc
Date: Thu Aug 16 10:06:33 2012
New Revision: 1373776

URL: http://svn.apache.org/viewvc?rev=1373776&view=rev
Log:
Added ceil and floor 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=1373776&r1=1373775&r2=1373776&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:06:33 2012
@@ -22,6 +22,7 @@ import org.apache.commons.math3.Field;
 import org.apache.commons.math3.FieldElement;
 import org.apache.commons.math3.exception.DimensionMismatchException;
 import org.apache.commons.math3.exception.NumberIsTooLargeException;
+import org.apache.commons.math3.util.FastMath;
 
 /** Class representing both the value and the differentials of a function.
  * <p>This class is the workhorse of the differentiation package.</p>
@@ -367,6 +368,24 @@ public class DerivativeStructure impleme
         }
     }
 
+    /** Get the smallest whole number larger than instance.
+     * @return ceil(this)
+     */
+    public DerivativeStructure ceil() {
+        return new DerivativeStructure(compiler.getFreeParameters(),
+                                       compiler.getOrder(),
+                                       FastMath.ceil(data[0]));
+    }
+
+    /** Get the largest whole number smaller than instance.
+     * @return floor(this)
+     */
+    public DerivativeStructure floor() {
+        return new DerivativeStructure(compiler.getFreeParameters(),
+                                       compiler.getOrder(),
+                                       FastMath.floor(data[0]));
+    }
+
     /** {@inheritDoc} */
     public DerivativeStructure reciprocal() {
         final DerivativeStructure result = new DerivativeStructure(compiler);

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=1373776&r1=1373775&r2=1373776&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:06:33 2012
@@ -753,6 +753,19 @@ public class DerivativeStructureTest {
     }
 
     @Test
+    public void testCeilFloor() {
+
+        DerivativeStructure x = new DerivativeStructure(1, 1, 0, -1.5);
+        Assert.assertEquals(-1.5, x.getPartialDerivative(0), 1.0e-15);
+        Assert.assertEquals(+1.0, x.getPartialDerivative(1), 1.0e-15);
+        Assert.assertEquals(-1.0, x.ceil().getPartialDerivative(0), 1.0e-15);
+        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);
+
+    }
+
+    @Test
     public void testField() {
         for (int maxOrder = 1; maxOrder < 5; ++maxOrder) {
             DerivativeStructure x = new DerivativeStructure(3, maxOrder, 0, 1.0);



Mime
View raw message