commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1183138 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/analysis/solvers/ main/java/org/apache/commons/math/util/ test/java/org/apache/commons/math/util/
Date Thu, 13 Oct 2011 22:21:05 GMT
Author: erans
Date: Thu Oct 13 22:21:04 2011
New Revision: 1183138

URL: http://svn.apache.org/viewvc?rev=1183138&view=rev
Log:
MATH-690
Removed "sign(float)" and "sign(double)" from "MathUtils"; replaced uses by
calls to "signum" in "FastMath".

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/MullerSolver.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/RiddersSolver.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/FastMathTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/MullerSolver.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/MullerSolver.java?rev=1183138&r1=1183137&r2=1183138&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/MullerSolver.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/MullerSolver.java
Thu Oct 13 22:21:04 2011
@@ -17,7 +17,6 @@
 package org.apache.commons.math.analysis.solvers;
 
 import org.apache.commons.math.util.FastMath;
-import org.apache.commons.math.util.MathUtils;
 
 /**
  * This class implements the <a href="http://mathworld.wolfram.com/MullersMethod.html">
@@ -181,7 +180,7 @@ public class MullerSolver extends Abstra
             } else {
                 double xm = 0.5 * (x0 + x2);
                 double ym = computeObjectiveValue(xm);
-                if (MathUtils.sign(y0) + MathUtils.sign(ym) == 0.0) {
+                if (FastMath.signum(y0) + FastMath.signum(ym) == 0.0) {
                     x2 = xm; y2 = ym;
                 } else {
                     x0 = xm; y0 = ym;

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/RiddersSolver.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/RiddersSolver.java?rev=1183138&r1=1183137&r2=1183138&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/RiddersSolver.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/RiddersSolver.java
Thu Oct 13 22:21:04 2011
@@ -17,7 +17,6 @@
 package org.apache.commons.math.analysis.solvers;
 
 import org.apache.commons.math.util.FastMath;
-import org.apache.commons.math.util.MathUtils;
 
 /**
  * Implements the <a href="http://mathworld.wolfram.com/RiddersMethod.html">
@@ -97,7 +96,7 @@ public class RiddersSolver extends Abstr
                 return x3;
             }
             final double delta = 1 - (y1 * y2) / (y3 * y3);  // delta > 1 due to bracketing
-            final double correction = (MathUtils.sign(y2) * MathUtils.sign(y3)) *
+            final double correction = (FastMath.signum(y2) * FastMath.signum(y3)) *
                                       (x3 - x1) / FastMath.sqrt(delta);
             final double x = x3 - correction;                // correction != 0
             final double y = computeObjectiveValue(x);
@@ -114,7 +113,7 @@ public class RiddersSolver extends Abstr
             // prepare the new interval for next iteration
             // Ridders' method guarantees x1 < x < x2
             if (correction > 0.0) {             // x1 < x < x3
-                if (MathUtils.sign(y1) + MathUtils.sign(y) == 0.0) {
+                if (FastMath.signum(y1) + FastMath.signum(y) == 0.0) {
                     x2 = x;
                     y2 = y;
                 } else {
@@ -124,7 +123,7 @@ public class RiddersSolver extends Abstr
                     y2 = y3;
                 }
             } else {                            // x3 < x < x2
-                if (MathUtils.sign(y2) + MathUtils.sign(y) == 0.0) {
+                if (FastMath.signum(y2) + FastMath.signum(y) == 0.0) {
                     x1 = x;
                     y1 = y;
                 } else {

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java?rev=1183138&r1=1183137&r2=1183138&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java Thu
Oct 13 22:21:04 2011
@@ -420,43 +420,6 @@ public final class MathUtils {
 
     /**
      * Returns the <a href="http://mathworld.wolfram.com/Sign.html"> sign</a>
-     * for double precision {@code x}.
-     * <p>
-     * For a double value {@code x}, this method returns
-     * {@code +1.0} if {@code x > 0}, {@code 0.0} if
-     * {@code x = 0.0}, and {@code -1.0} if {@code x < 0}.
-     * Returns {@code NaN} if {@code x} is {@code NaN}.</p>
-     *
-     * @param x the value, a double
-     * @return +1.0, 0.0, or -1.0, depending on the sign of x
-     */
-    public static double sign(final double x) {
-        if (Double.isNaN(x)) {
-            return Double.NaN;
-        }
-        return (x == 0.0) ? 0.0 : (x > 0.0) ? 1.0 : -1.0;
-    }
-
-    /**
-     * Returns the <a href="http://mathworld.wolfram.com/Sign.html"> sign</a>
-     * for float value {@code x}.
-     * <p>
-     * For a float value x, this method returns +1.0F if x > 0, 0.0F if x =
-     * 0.0F, and -1.0F if x < 0. Returns {@code NaN} if {@code x}
-     * is {@code NaN}.</p>
-     *
-     * @param x the value, a float
-     * @return +1.0F, 0.0F, or -1.0F, depending on the sign of x
-     */
-    public static float sign(final float x) {
-        if (Float.isNaN(x)) {
-            return Float.NaN;
-        }
-        return (x == 0.0F) ? 0.0F : (x > 0.0F) ? 1.0F : -1.0F;
-    }
-
-    /**
-     * Returns the <a href="http://mathworld.wolfram.com/Sign.html"> sign</a>
      * for int value {@code x}.
      * <p>
      * For an int value x, this method returns +1 if x > 0, 0 if x = 0, and -1

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/FastMathTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/FastMathTest.java?rev=1183138&r1=1183137&r2=1183138&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/FastMathTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/FastMathTest.java
Thu Oct 13 22:21:04 2011
@@ -25,6 +25,7 @@ import org.apache.commons.math.dfp.DfpFi
 import org.apache.commons.math.dfp.DfpMath;
 import org.apache.commons.math.random.MersenneTwister;
 import org.apache.commons.math.random.RandomGenerator;
+import org.apache.commons.math.TestUtils;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Ignore;
@@ -1060,4 +1061,21 @@ public class FastMathTest {
         compareClassMethods( FastMath.class, StrictMath.class);
     }
 
+    @Test
+    public void testSignumDouble() {
+        final double delta = 0.0;
+        Assert.assertEquals(1.0, FastMath.signum(2.0), delta);
+        Assert.assertEquals(0.0, FastMath.signum(0.0), delta);
+        Assert.assertEquals(-1.0, FastMath.signum(-2.0), delta);
+        TestUtils.assertSame(-0. / 0., FastMath.signum(Double.NaN));
+    }
+
+    @Test
+    public void testSignumFloat() {
+        final float delta = 0.0F;
+        Assert.assertEquals(1.0F, FastMath.signum(2.0F), delta);
+        Assert.assertEquals(0.0F, FastMath.signum(0.0F), delta);
+        Assert.assertEquals(-1.0F, FastMath.signum(-2.0F), delta);
+        TestUtils.assertSame(Float.NaN, FastMath.signum(Float.NaN));
+    }
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java?rev=1183138&r1=1183137&r2=1183138&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java
Thu Oct 13 22:21:04 2011
@@ -455,24 +455,6 @@ public final class MathUtilsTest {
     }
 
     @Test
-    public void testSignDouble() {
-        double delta = 0.0;
-        Assert.assertEquals(1.0, MathUtils.sign(2.0), delta);
-        Assert.assertEquals(0.0, MathUtils.sign(0.0), delta);
-        Assert.assertEquals(-1.0, MathUtils.sign(-2.0), delta);
-        TestUtils.assertSame(-0. / 0., MathUtils.sign(Double.NaN));
-    }
-
-    @Test
-    public void testSignFloat() {
-        float delta = 0.0F;
-        Assert.assertEquals(1.0F, MathUtils.sign(2.0F), delta);
-        Assert.assertEquals(0.0F, MathUtils.sign(0.0F), delta);
-        Assert.assertEquals(-1.0F, MathUtils.sign(-2.0F), delta);
-        TestUtils.assertSame(Float.NaN, MathUtils.sign(Float.NaN));
-    }
-
-    @Test
     public void testSignInt() {
         Assert.assertEquals(1, MathUtils.sign(2));
         Assert.assertEquals(0, MathUtils.sign(0));



Mime
View raw message