@@ -89,9 +89,11 @@ public static void main(String... args) {
89
89
failures += testWorstAcos ();
90
90
failures += testWorstTan ();
91
91
failures += testWorstAtan ();
92
+ failures += testWorstAtan2 ();
92
93
failures += testWorstPow2 ();
93
94
failures += testWorstSinh ();
94
95
failures += testWorstCosh ();
96
+ failures += testWorstHypot ();
95
97
96
98
if (failures > 0 ) {
97
99
System .err .printf ("Testing worst cases incurred %d failures.%n" , failures );
@@ -481,6 +483,32 @@ private static int testAtanCase(double input, double expected) {
481
483
return failures ;
482
484
}
483
485
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
+
484
512
/*
485
513
* 1 ulp stated error bound
486
514
*/
@@ -570,4 +598,30 @@ private static int testCoshCase(double input, double expected) {
570
598
failures += Tests .testBounds ("StrictMath.cosh" , input , StrictMath ::cosh , expected , out );
571
599
return failures ;
572
600
}
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
+ }
573
627
}
0 commit comments