commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1166771 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/util/FastMath.java site/xdoc/changes.xml test/java/org/apache/commons/math/util/FastMathTest.java
Date Thu, 08 Sep 2011 15:59:11 GMT
Author: sebb
Date: Thu Sep  8 15:59:11 2011
New Revision: 1166771

URL: http://svn.apache.org/viewvc?rev=1166771&view=rev
Log:
MATH-658 Dead code in FastMath.pow(double, double) and some improvement in test coverage

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/FastMath.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/FastMathTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/FastMath.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/FastMath.java?rev=1166771&r1=1166770&r2=1166771&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/FastMath.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/FastMath.java Thu
Sep  8 15:59:11 2011
@@ -7876,10 +7876,6 @@ public class FastMath {
                     return Double.NEGATIVE_INFINITY;
                 }
 
-                if (y < 0 && y == yi && (yi & 1) == 1) {
-                    return -0.0;
-                }
-
                 if (y > 0 && y == yi && (yi & 1) == 1) {
                     return -0.0;
                 }

Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=1166771&r1=1166770&r2=1166771&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Thu Sep  8 15:59:11 2011
@@ -52,6 +52,9 @@ The <action> type attribute can be add,u
     If the output is not quite correct, check for invisible trailing spaces!
      -->
     <release version="3.0" date="TBD" description="TBD">
+      <action dev="sebb" type="fix" issue="MATH-658" due-to="Yannick TANGUY">
+        Dead code in FastMath.pow(double, double) and some improvement in test coverage.
+      </action>
       <action dev="erans" type="fix" issue="MATH-663">
         Removed "getData()" method from "RealVector" as it was redundant with
         "toArray()".

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=1166771&r1=1166770&r2=1166771&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 Sep  8 15:59:11 2011
@@ -16,6 +16,8 @@
  */
 package org.apache.commons.math.util;
 
+import static org.junit.Assert.*;
+
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.lang.reflect.Type;
@@ -252,6 +254,15 @@ public class FastMathTest {
     }
 
     @Test
+    public void testLog1pSpecialCases() {
+        double x;
+
+    	x = FastMath.log1p(-1.0);
+        if (x != Double.NEGATIVE_INFINITY)
+            throw new RuntimeException("Log1p of -1 should be -infinity");
+    }
+
+    @Test
     public void testLogSpecialCases() {
         double x;
 
@@ -399,6 +410,45 @@ public class FastMathTest {
         x = FastMath.pow(-2.0, 3.5);
         if (x == x)
             throw new RuntimeException("pow(-2.0, 3.5) should be NaN");
+
+        // Added tests for a 100% coverage
+
+        x = FastMath.pow(Double.POSITIVE_INFINITY, Double.NaN);
+        if (x == x)
+            throw new RuntimeException("pow(+Inf, NaN) should be NaN");
+
+        x = FastMath.pow(Double.POSITIVE_INFINITY, Double.NaN);
+        if (x == x)
+            throw new RuntimeException("pow(+Inf, NaN) should be NaN");
+
+        x = FastMath.pow(1.0, Double.POSITIVE_INFINITY);
+        if (x == x)
+            throw new RuntimeException("pow(1.0, +Inf) should be NaN");
+
+        x = FastMath.pow(Double.NEGATIVE_INFINITY, Double.NaN);
+        if (x == x)
+            throw new RuntimeException("pow(-Inf, NaN) should be NaN");
+
+        x = FastMath.pow(Double.NEGATIVE_INFINITY, -1.0);
+        if (x != -0.0)
+            throw new RuntimeException("pow(-Inf, -1.0) should be 0.0");
+
+        x = FastMath.pow(Double.NEGATIVE_INFINITY, -2.0);
+        if (x != 0.0)
+            throw new RuntimeException("pow(-Inf, -2.0) should be 0.0");
+
+        x = FastMath.pow(Double.NEGATIVE_INFINITY, 1.0);
+        if (x != Double.NEGATIVE_INFINITY)
+            throw new RuntimeException("pow(-Inf, 1.0) should be -Inf");
+
+        x = FastMath.pow(Double.NEGATIVE_INFINITY, 2.0);
+        if (x != Double.POSITIVE_INFINITY)
+            throw new RuntimeException("pow(-Inf, 2.0) should be +Inf");
+
+        x = FastMath.pow(1.0, Double.NEGATIVE_INFINITY);
+        if (x == x)
+            throw new RuntimeException("pow(1.0, -Inf) should be NaN");
+
     }
 
     @Test
@@ -793,6 +843,58 @@ public class FastMathTest {
         Assert.assertTrue("acos() had errors in excess of " + MAX_ERROR_ULP + " ULP", maxerrulp
< MAX_ERROR_ULP);
     }
 
+    /**
+     * Added tests for a 100% coverage of acos().
+     */
+    @Test
+    public void testAcosSpecialCases() {
+    	double x;
+
+    	x = FastMath.acos(Double.NaN);
+    	if (x == x)
+    		throw new RuntimeException("acos(NaN) should NaN");
+
+    	x = FastMath.acos(-1.1);
+    	if (x == x)
+    		throw new RuntimeException("acos(-1.1) should NaN");
+    	
+    	x = FastMath.acos(1.1);
+    	if (x == x)
+    		throw new RuntimeException("acos(-1.1) should NaN");
+
+    	assertEquals(FastMath.acos(-1.0), FastMath.PI, Double.MIN_VALUE);
+
+    	assertEquals(FastMath.acos(1.0), 0.0, Double.MIN_VALUE);
+
+    	assertEquals(FastMath.acos(0.0), FastMath.PI / 2.0, Double.MIN_VALUE);
+    }
+
+    /**
+     * Added tests for a 100% coverage of asin().
+     */
+    @Test
+    public void testAsinSpecialCases() {
+    	double x;
+
+    	x = FastMath.asin(Double.NaN);
+    	if (x == x)
+    		throw new RuntimeException("asin(NaN) should NaN");
+
+    	x = FastMath.asin(-1.1);
+    	if (x == x)
+    		throw new RuntimeException("asin(-1.1) should NaN");
+    	
+    	x = FastMath.asin(1.1);
+    	if (x == x)
+    		throw new RuntimeException("asin(-1.1) should NaN");
+
+    	assertEquals(FastMath.asin(1.0), FastMath.PI / 2.0, Double.MIN_VALUE);
+
+    	assertEquals(FastMath.asin(-1.0), -FastMath.PI / 2.0, Double.MIN_VALUE);
+
+    	assertEquals(FastMath.asin(0.0), 0.0, Double.MIN_VALUE);
+    }
+
     private Dfp cosh(Dfp x) {
       return DfpMath.exp(x).add(DfpMath.exp(x.negate())).divide(2);
     }



Mime
View raw message