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:23:19 UTC
svn commit: r996161 -
/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/util/FastMathTest.java
Author: luc
Date: Sat Sep 11 16:23:18 2010
New Revision: 996161
URL: http://svn.apache.org/viewvc?rev=996161&view=rev
Log:
added tests for asin and acos
JIRA: MATH-375
Modified:
commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/util/FastMathTest.java
Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/util/FastMathTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/util/FastMathTest.java?rev=996161&r1=996160&r2=996161&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/util/FastMathTest.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/util/FastMathTest.java Sat Sep 11 16:23:18 2010
@@ -742,6 +742,69 @@ 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);
+ }
+
+ private Dfp cbrt(Dfp x) {
+ boolean negative=false;
+
+ if (x.lessThan(field.getZero())) {
+ negative = true;
+ x = x.negate();
+ }
+
+ Dfp y = DfpMath.pow(x, field.getOne().divide(3));
+
+ if (negative) {
+ y = y.negate();
+ }
+
+ return y;
+ }
+
+ @Test
public void testToDegrees() {
double maxerrulp = 0.0;
for (int i = 0; i < NUMBER_OF_TRIALS; i++) {
@@ -850,6 +913,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");
@@ -861,6 +938,19 @@ public class FastMathTest {
time = System.currentTimeMillis() - time;
System.out.println("FastMath.cos " + time + "\t" + x);
+ 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++)