added tests for asin and acos
JIRA: MATH-375 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@996167 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
742f3cd33e
commit
0f5d514dd7
|
@ -741,6 +741,52 @@ public class FastMathTest {
|
|||
Assert.assertTrue("expm1() had errors in excess of " + MAX_ERROR_ULP + " ULP", maxerrulp < MAX_ERROR_ULP);
|
||||
}
|
||||
|
||||
@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;
|
||||
|
@ -847,6 +893,20 @@ public class FastMathTest {
|
|||
time = System.currentTimeMillis() - time;
|
||||
System.out.println("FastMath.sin " + time + "\t" + x);
|
||||
|
||||
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++)
|
||||
|
@ -861,6 +921,20 @@ public class FastMathTest {
|
|||
time = System.currentTimeMillis() - time;
|
||||
System.out.println("FastMath.cos " + time + "\t" + x);
|
||||
|
||||
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++)
|
||||
|
@ -889,6 +963,13 @@ public class FastMathTest {
|
|||
time = System.currentTimeMillis() - time;
|
||||
System.out.println("FastMath.atan " + time + "\t" + x);
|
||||
|
||||
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++)
|
||||
|
|
Loading…
Reference in New Issue