You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2010/09/11 18:42:48 UTC

svn commit: r996167 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/FastMathTest.java

Author: luc
Date: Sat Sep 11 16:42:48 2010
New Revision: 996167

URL: http://svn.apache.org/viewvc?rev=996167&view=rev
Log:
added tests for asin and acos
JIRA: MATH-375

Modified:
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/FastMathTest.java

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=996167&r1=996166&r2=996167&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 Sat Sep 11 16:42:48 2010
@@ -742,6 +742,52 @@ public class FastMathTest {
     }
 
     @Test
+    public void testAsinAccuracy() {
+        double maxerrulp = 0.0;
+
+        for (int i=0; i<10000; i++) {
+            double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble(); 
+
+            double tst = FastMath.asin(x);
+            double ref = DfpMath.asin(field.newDfp(x)).toDouble();
+            double err = (tst - ref) / ref;
+
+            if (err != 0) {
+                double ulp = Math.abs(ref - Double.longBitsToDouble((Double.doubleToLongBits(ref) ^ 1)));
+                double errulp = field.newDfp(tst).subtract(DfpMath.asin(field.newDfp(x))).divide(field.newDfp(ulp)).toDouble();
+                //System.out.println(x+"\t"+tst+"\t"+ref+"\t"+err+"\t"+errulp);
+
+                maxerrulp = Math.max(maxerrulp, Math.abs(errulp));
+            }
+        }
+
+        Assert.assertTrue("asin() had errors in excess of " + MAX_ERROR_ULP + " ULP", maxerrulp < MAX_ERROR_ULP);
+    }
+
+    @Test
+    public void testAcosAccuracy() {
+        double maxerrulp = 0.0;
+
+        for (int i=0; i<10000; i++) {
+            double x = ((generator.nextDouble() * 2.0) - 1.0) * generator.nextDouble(); 
+
+            double tst = FastMath.acos(x);
+            double ref = DfpMath.acos(field.newDfp(x)).toDouble();
+            double err = (tst - ref) / ref;
+
+            if (err != 0) {
+                double ulp = Math.abs(ref - Double.longBitsToDouble((Double.doubleToLongBits(ref) ^ 1)));
+                double errulp = field.newDfp(tst).subtract(DfpMath.acos(field.newDfp(x))).divide(field.newDfp(ulp)).toDouble();
+                //System.out.println(x+"\t"+tst+"\t"+ref+"\t"+err+"\t"+errulp);
+
+                maxerrulp = Math.max(maxerrulp, Math.abs(errulp));
+            }
+        }
+
+        Assert.assertTrue("acos() had errors in excess of " + MAX_ERROR_ULP + " ULP", maxerrulp < MAX_ERROR_ULP);
+    }
+
+    @Test
     public void testToDegrees() {
         double maxerrulp = 0.0;
         for (int i = 0; i < NUMBER_OF_TRIALS; i++) {
@@ -850,6 +896,20 @@ public class FastMathTest {
             x = 0;
             time = System.currentTimeMillis();
             for (int i = 0; i < numberOfRuns; i++)
+                x += StrictMath.asin(i / 10000000.0);
+            time = System.currentTimeMillis() - time;
+            System.out.print("StrictMath.asin " + time + "\t" + x + "\t");
+
+            x = 0;
+            time = System.currentTimeMillis();
+            for (int i = 0; i < numberOfRuns; i++)
+                x += FastMath.asin(i / 10000000.0);
+            time = System.currentTimeMillis() - time;
+            System.out.println("FastMath.asin " + time + "\t" + x);
+
+            x = 0;
+            time = System.currentTimeMillis();
+            for (int i = 0; i < numberOfRuns; i++)
                 x += StrictMath.cos(i / 1000000.0);
             time = System.currentTimeMillis() - time;
             System.out.print("StrictMath.cos " + time + "\t" + x + "\t");
@@ -864,6 +924,20 @@ public class FastMathTest {
             x = 0;
             time = System.currentTimeMillis();
             for (int i = 0; i < numberOfRuns; i++)
+                x += StrictMath.acos(i / 10000000.0);
+            time = System.currentTimeMillis() - time;
+            System.out.print("StrictMath.acos " + time + "\t" + x + "\t");
+
+            x = 0;
+            time = System.currentTimeMillis();
+            for (int i = 0; i < numberOfRuns; i++)
+                x += FastMath.acos(i / 10000000.0);
+            time = System.currentTimeMillis() - time;
+            System.out.println("FastMath.acos " + time + "\t" + x);
+
+            x = 0;
+            time = System.currentTimeMillis();
+            for (int i = 0; i < numberOfRuns; i++)
                 x += StrictMath.tan(i / 1000000.0);
             time = System.currentTimeMillis() - time;
             System.out.print("StrictMath.tan " + time + "\t" + x + "\t");
@@ -892,6 +966,13 @@ public class FastMathTest {
             x = 0;
             time = System.currentTimeMillis();
             for (int i = 0; i < numberOfRuns; i++)
+                x += FastMath.cbrt(i / 1000000.0);
+            time = System.currentTimeMillis() - time;
+            System.out.println("FastMath.cbrt " + time + "\t" + x);
+
+           x = 0;
+            time = System.currentTimeMillis();
+            for (int i = 0; i < numberOfRuns; i++)
                 x += StrictMath.expm1(-i / 100000.0);
             time = System.currentTimeMillis() - time;
             System.out.print("StrictMath.expm1 " + time + "\t" + x + "\t");