commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r1373781 - 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:08:00 GMT
Author: luc
Date: Thu Aug 16 10:07:59 2012
New Revision: 1373781

URL: http://svn.apache.org/viewvc?rev=1373781&view=rev
Log:
Added signum 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=1373781&r1=1373780&r2=1373781&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:59 2012
@@ -402,6 +402,17 @@ public class DerivativeStructure impleme
         return FastMath.round(data[0]);
     }
 
+    /** Compute the signum of the instance.
+     * The signum is -1 for negative numbers, +1 for positive numbers and 0 otherwise
+     * @param a number on which evaluation is done
+     * @return -1.0, -0.0, +0.0, +1.0 or NaN depending on sign of a
+     */
+    public DerivativeStructure signum() {
+        return new DerivativeStructure(compiler.getFreeParameters(),
+                                       compiler.getOrder(),
+                                       FastMath.signum(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=1373781&r1=1373780&r2=1373781&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:59 2012
@@ -838,6 +838,29 @@ public class DerivativeStructureTest {
     }
 
     @Test
+    public void testSignum() {
+
+        DerivativeStructure minusOne = new DerivativeStructure(1, 1, 0, -1.0);
+        Assert.assertEquals(-1.0, minusOne.signum().getPartialDerivative(0), 1.0e-15);
+        Assert.assertEquals( 0.0, minusOne.signum().getPartialDerivative(1), 1.0e-15);
+
+        DerivativeStructure plusOne = new DerivativeStructure(1, 1, 0, +1.0);
+        Assert.assertEquals(+1.0, plusOne.signum().getPartialDerivative(0), 1.0e-15);
+        Assert.assertEquals( 0.0, plusOne.signum().getPartialDerivative(1), 1.0e-15);
+
+        DerivativeStructure minusZero = new DerivativeStructure(1, 1, 0, -0.0);
+        Assert.assertEquals(-0.0, minusZero.signum().getPartialDerivative(0), 1.0e-15);
+        Assert.assertTrue(Double.doubleToLongBits(minusZero.signum().getValue()) < 0);
+        Assert.assertEquals( 0.0, minusZero.signum().getPartialDerivative(1), 1.0e-15);
+
+        DerivativeStructure plusZero = new DerivativeStructure(1, 1, 0, +0.0);
+        Assert.assertEquals(+0.0, plusZero.signum().getPartialDerivative(0), 1.0e-15);
+        Assert.assertTrue(Double.doubleToLongBits(plusZero.signum().getValue()) == 0);
+        Assert.assertEquals( 0.0, plusZero.signum().getPartialDerivative(1), 1.0e-15);
+
+    }
+
+    @Test
     public void testCeilFloorRintLong() {
 
         DerivativeStructure x = new DerivativeStructure(1, 1, 0, -1.5);



Mime
View raw message