Skip to content

Commit 201042f

Browse files
committedMar 12, 2024
8327487: Further augment WorstCaseTests with more cases
Reviewed-by: rgiulietti
1 parent 379ad1f commit 201042f

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
 

‎test/jdk/java/lang/Math/WorstCaseTests.java

+54
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ public static void main(String... args) {
8989
failures += testWorstAcos();
9090
failures += testWorstTan();
9191
failures += testWorstAtan();
92+
failures += testWorstAtan2();
9293
failures += testWorstPow2();
9394
failures += testWorstSinh();
9495
failures += testWorstCosh();
96+
failures += testWorstHypot();
9597

9698
if (failures > 0) {
9799
System.err.printf("Testing worst cases incurred %d failures.%n", failures);
@@ -481,6 +483,32 @@ private static int testAtanCase(double input, double expected) {
481483
return failures;
482484
}
483485

486+
/*
487+
* 2 ulp stated error bound
488+
*/
489+
private static int testWorstAtan2() {
490+
int failures = 0;
491+
double [][] testCases = {
492+
// Input with large worst-case observed error for another math library
493+
{-0x0.00000000039a2p-1022, 0x0.000fdf02p-1022, -0x1.d0ce6fac85de8p-27},
494+
};
495+
496+
for(double[] testCase: testCases) {
497+
failures += testAtan2Case(testCase[0], testCase[1], testCase[2]);
498+
}
499+
500+
return failures;
501+
}
502+
503+
private static int testAtan2Case(double input1, double input2, double expected) {
504+
int failures = 0;
505+
// Cannot represent exact result, allow 1 additional ulp on top of documented bound.
506+
double ulps = 2.0 + 1.0;
507+
failures += Tests.testUlpDiff("Math.atan2", input1, input2, Math::atan2, expected, ulps);
508+
failures += Tests.testUlpDiff("StrictMath.atan2", input1, input2, StrictMath::atan2, expected, ulps);
509+
return failures;
510+
}
511+
484512
/*
485513
* 1 ulp stated error bound
486514
*/
@@ -570,4 +598,30 @@ private static int testCoshCase(double input, double expected) {
570598
failures += Tests.testBounds("StrictMath.cosh", input, StrictMath::cosh, expected, out);
571599
return failures;
572600
}
601+
602+
/*
603+
* 1.5 ulp stated error bound
604+
*/
605+
private static int testWorstHypot() {
606+
int failures = 0;
607+
double [][] testCases = {
608+
// Input with large worst-case observed error for another math library
609+
{-0x0.fffffffffffffp-1022, 0x0.0000000000001p-1022, 0x0.fffffffffffffp-1022},
610+
};
611+
612+
for(double[] testCase: testCases) {
613+
failures += testHypotCase(testCase[0], testCase[1], testCase[2]);
614+
}
615+
616+
return failures;
617+
}
618+
619+
private static int testHypotCase(double input1, double input2, double expected) {
620+
int failures = 0;
621+
// Cannot represent exact result, allow 1 additional ulp on top of documented bound, rounding up.
622+
double ulps = 3.0; // 1.5 + 1.0, rounded up
623+
failures += Tests.testUlpDiff("Math.hypot", input1, input2, Math::hypot, expected, ulps);
624+
failures += Tests.testUlpDiff("StrictMath.hypot", input1, input2, StrictMath::hypot, expected, ulps);
625+
return failures;
626+
}
573627
}

0 commit comments

Comments
 (0)
Please sign in to comment.