1 /*
2 * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
25 * @test
26 * @bug 4851638
27 * @summary Tests for StrictMath.hypot
28 * @author Joseph D. Darcy
29 */
30
31 /**
32 * The tests in ../Math/HypotTests.java test properties that should
33 * hold for any hypot implementation, including the FDLIBM-based one
34 * required for StrictMath.hypot. Therefore, the test cases in
35 * ../Math/HypotTests.java are run against both the Math and
36 * StrictMath versions of hypot. The role of this test is to verify
37 * that the FDLIBM hypot algorithm is being used by running golden
38 * file tests on values that may vary from one conforming hypot
39 * implementation to another.
40 */
41
42 public class HypotTests {
43 private HypotTests(){}
44
45 static int testHypotCase(double input1, double input2, double expected) {
46 return Tests.test("StrictMath.hypot(double)", input1, input2,
47 StrictMath.hypot(input1, input2), expected);
48 }
49
50 static int testHypot() {
51 int failures = 0;
52
53 double [][] testCases = {
54 {0x1.0p0, 0x1.ffffffffffab5p-1, 0x1.6a09e667f39edp0},
55 {0x1.0p0, 0x1.ffffffffffffbp0, 0x1.1e3779b97f4a6p1},
56 {0x1.0p0, 0x1.7ffffffffffffp1, 0x1.94c583ada5b51p1},
57 {0x1.0p0, 0x1.ffffffffffffdp1, 0x1.07e0f66afed06p2},
58 {0x1.0p0, 0x1.3fffffffffffdp2, 0x1.465655f122ff3p2},
59 {0x1.0p0, 0x1.4p2, 0x1.465655f122ff6p2},
60 {0x1.0p0, 0x1.7ffffffffffffp2, 0x1.854bfb363dc38p2},
61 {0x1.0p0, 0x1.8p2, 0x1.854bfb363dc39p2},
62 {0x1.0p0, 0x1.bfffffffffffep2, 0x1.c48c6001f0abdp2},
63 {0x1.0p0, 0x1.fffffffffffffp2, 0x1.01fe03f61badp3},
64 {0x1.0p0, 0x1.1fffffffffffap3, 0x1.21c5b70d9f81dp3},
65 {0x1.0p0, 0x1.3ffffffffffe5p3, 0x1.419894c2329d5p3},
66 {0x1.0p0, 0x1.3ffffffffffe7p3, 0x1.419894c2329d8p3},
67 {0x1.0p0, 0x1.5ffffffffff7ep3, 0x1.617398f2aa9c6p3},
594 {0x1.8p1, 0x1.6bfffffffffep6, 0x1.6c329fa502ccfp6},
595 {0x1.8p1, 0x1.6cp6, 0x1.6c329fa502cefp6},
596 {0x1.8p1, 0x1.6fffffffffff8p6, 0x1.703212daa75f3p6},
597 {0x1.8p1, 0x1.6ffffffffffffp6, 0x1.703212daa75fbp6},
598 {0x1.8p1, 0x1.73fffffffffap6, 0x1.74318916ca409p6},
599 {0x1.8p1, 0x1.74p6, 0x1.74318916ca46ap6},
600 {0x1.8p1, 0x1.77ffffffffffp6, 0x1.78310240ba47p6},
601 {0x1.8p1, 0x1.78p6, 0x1.78310240ba481p6},
602 {0x1.8p1, 0x1.7bfffffffffep6, 0x1.7c307e40cff7fp6},
603 {0x1.8p1, 0x1.7bfffffffffe4p6, 0x1.7c307e40cff83p6},
604 {0x1.8p1, 0x1.7fffffffffff7p6, 0x1.802ffd005ff07p6},
605 {0x1.8p1, 0x1.7fffffffffff9p6, 0x1.802ffd005ff0ap6},
606 {0x1.8p1, 0x1.83fffffffffap6, 0x1.842f7e69adc1ep6},
607 {0x1.8p1, 0x1.83fffffffffffp6, 0x1.842f7e69adc7dp6},
608 {0x1.8p1, 0x1.87fffffffffdp6, 0x1.882f0267dfef4p6},
609 {0x1.8p1, 0x1.88p6, 0x1.882f0267dff24p6},
610 {0x1.8p1, 0x1.8bfffffffffep6, 0x1.8c2e88e6f449ap6},
611 {0x1.8p1, 0x1.8bffffffffff6p6, 0x1.8c2e88e6f44b1p6},
612 {0x1.8p1, 0x1.8ffffffffffe8p6, 0x1.902e11d3b5549p6},
613 {0x1.8p1, 0x1.8fffffffffffep6, 0x1.902e11d3b556p6},
614 };
615
616 for (double[] testCase: testCases)
617 failures+=testHypotCase(testCase[0], testCase[1], testCase[2]);
618
619 return failures;
620 }
621
622 public static void main(String [] argv) {
623 int failures = 0;
624
625 failures += testHypot();
626
627 if (failures > 0) {
628 System.err.println("Testing log1p incurred "
629 + failures + " failures.");
630 throw new RuntimeException();
631 }
632 }
633 }
|
1 /*
2 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
25 * @test
26 * @bug 4851638
27 * @summary Tests for StrictMath.hypot
28 * @author Joseph D. Darcy
29 */
30
31 /**
32 * The tests in ../Math/HypotTests.java test properties that should
33 * hold for any hypot implementation, including the FDLIBM-based one
34 * required for StrictMath.hypot. Therefore, the test cases in
35 * ../Math/HypotTests.java are run against both the Math and
36 * StrictMath versions of hypot. The role of this test is to verify
37 * that the FDLIBM hypot algorithm is being used by running golden
38 * file tests on values that may vary from one conforming hypot
39 * implementation to another.
40 */
41
42 public class HypotTests {
43 private HypotTests(){}
44
45 /**
46 * The hypot implementation is commuative, {@code hypot(a, b) ==
47 * hypot(b, a)}, and indepenent of sign, {@code hypot(a, b) ==
48 * hypot(-a, b) == hypot(a, -b) == hypot(-a, -b)}.
49 */
50 static int testHypotCase(double input1, double input2, double expected) {
51 int failures = 0;
52 failures += Tests.test("StrictMath.hypot(double)", input1, input2,
53 StrictMath.hypot(input1, input2), expected);
54
55 failures += Tests.test("StrictMath.hypot(double)", input2, input1,
56 StrictMath.hypot(input2, input1), expected);
57
58 failures += Tests.test("StrictMath.hypot(double)", -input1, input2,
59 StrictMath.hypot(-input1, input2), expected);
60
61 failures += Tests.test("StrictMath.hypot(double)", input2, -input1,
62 StrictMath.hypot(input2, -input1), expected);
63
64 failures += Tests.test("StrictMath.hypot(double)", input1, -input2,
65 StrictMath.hypot(input1, -input2), expected);
66
67 failures += Tests.test("StrictMath.hypot(double)", -input2, input1,
68 StrictMath.hypot(-input2, input1), expected);
69
70 failures += Tests.test("StrictMath.hypot(double)", -input1, -input2,
71 StrictMath.hypot(-input1, -input2), expected);
72
73 failures += Tests.test("StrictMath.hypot(double)", -input2, -input1,
74 StrictMath.hypot(-input2, -input1), expected);
75 return failures;
76 }
77
78 static int testHypot() {
79 int failures = 0;
80
81 double [][] testCases = {
82 {0x1.0p0, 0x1.ffffffffffab5p-1, 0x1.6a09e667f39edp0},
83 {0x1.0p0, 0x1.ffffffffffffbp0, 0x1.1e3779b97f4a6p1},
84 {0x1.0p0, 0x1.7ffffffffffffp1, 0x1.94c583ada5b51p1},
85 {0x1.0p0, 0x1.ffffffffffffdp1, 0x1.07e0f66afed06p2},
86 {0x1.0p0, 0x1.3fffffffffffdp2, 0x1.465655f122ff3p2},
87 {0x1.0p0, 0x1.4p2, 0x1.465655f122ff6p2},
88 {0x1.0p0, 0x1.7ffffffffffffp2, 0x1.854bfb363dc38p2},
89 {0x1.0p0, 0x1.8p2, 0x1.854bfb363dc39p2},
90 {0x1.0p0, 0x1.bfffffffffffep2, 0x1.c48c6001f0abdp2},
91 {0x1.0p0, 0x1.fffffffffffffp2, 0x1.01fe03f61badp3},
92 {0x1.0p0, 0x1.1fffffffffffap3, 0x1.21c5b70d9f81dp3},
93 {0x1.0p0, 0x1.3ffffffffffe5p3, 0x1.419894c2329d5p3},
94 {0x1.0p0, 0x1.3ffffffffffe7p3, 0x1.419894c2329d8p3},
95 {0x1.0p0, 0x1.5ffffffffff7ep3, 0x1.617398f2aa9c6p3},
622 {0x1.8p1, 0x1.6bfffffffffep6, 0x1.6c329fa502ccfp6},
623 {0x1.8p1, 0x1.6cp6, 0x1.6c329fa502cefp6},
624 {0x1.8p1, 0x1.6fffffffffff8p6, 0x1.703212daa75f3p6},
625 {0x1.8p1, 0x1.6ffffffffffffp6, 0x1.703212daa75fbp6},
626 {0x1.8p1, 0x1.73fffffffffap6, 0x1.74318916ca409p6},
627 {0x1.8p1, 0x1.74p6, 0x1.74318916ca46ap6},
628 {0x1.8p1, 0x1.77ffffffffffp6, 0x1.78310240ba47p6},
629 {0x1.8p1, 0x1.78p6, 0x1.78310240ba481p6},
630 {0x1.8p1, 0x1.7bfffffffffep6, 0x1.7c307e40cff7fp6},
631 {0x1.8p1, 0x1.7bfffffffffe4p6, 0x1.7c307e40cff83p6},
632 {0x1.8p1, 0x1.7fffffffffff7p6, 0x1.802ffd005ff07p6},
633 {0x1.8p1, 0x1.7fffffffffff9p6, 0x1.802ffd005ff0ap6},
634 {0x1.8p1, 0x1.83fffffffffap6, 0x1.842f7e69adc1ep6},
635 {0x1.8p1, 0x1.83fffffffffffp6, 0x1.842f7e69adc7dp6},
636 {0x1.8p1, 0x1.87fffffffffdp6, 0x1.882f0267dfef4p6},
637 {0x1.8p1, 0x1.88p6, 0x1.882f0267dff24p6},
638 {0x1.8p1, 0x1.8bfffffffffep6, 0x1.8c2e88e6f449ap6},
639 {0x1.8p1, 0x1.8bffffffffff6p6, 0x1.8c2e88e6f44b1p6},
640 {0x1.8p1, 0x1.8ffffffffffe8p6, 0x1.902e11d3b5549p6},
641 {0x1.8p1, 0x1.8fffffffffffep6, 0x1.902e11d3b556p6},
642
643 // Test near decision points of the fdlibm algorithm
644 {0x1.0000000000001p501, 0x1.000000000000p501, 0x1.6a09e667f3bcdp501},
645 {0x1.0p501, 0x1.0p499, 0x1.07e0f66afed07p501},
646
647 {0x1.0p500, 0x1.0p450, 0x1.0p500},
648 {0x1.0000000000001p500, 0x1.0p450, 0x1.0000000000001p500},
649
650 {0x1.0p500, 0x1.0p440, 0x1.0p500},
651 {0x1.0000000000001p500, 0x1.0p440, 0x1.0000000000001p500},
652 {0x1.0p500, 0x1.0p439, 0x1.0p500},
653 {0x1.0000000000001p500, 0x1.0p439, 0x1.0000000000001p500},
654
655 {0x1.0p-450, 0x1.0p-500, 0x1.0p-450},
656 {0x1.0000000000001p-450, 0x1.0p-500, 0x1.0000000000001p-450},
657 {0x1.0p-450, 0x1.fffffffffffffp-499, 0x1.0p-450},
658 {0x1.0000000000001p-450, 0x1.fffffffffffffp-499, 0x1.0000000000001p-450},
659
660
661 {0x1.0p-450, 0x1.0p-500, 0x1.0p-450},
662 {0x1.0000000000001p-450, 0x1.0p-500, 0x1.0000000000001p-450},
663 {0x1.0p-450, 0x1.fffffffffffffp-499, 0x1.0p-450},
664 {0x1.0000000000001p-450, 0x1.fffffffffffffp-499, 0x1.0000000000001p-450},
665
666 // 0x1.0p-1022 is MIN_NORMAL
667 {0x1.0000000000001p-1022, 0x1.0000000000001p-1022, 0x1.6a09e667f3bcep-1022},
668 {0x1.0000000000001p-1022, 0x1.0p-1022, 0x1.6a09e667f3bcdp-1022},
669 {0x1.0000000000001p-1022, 0x0.fffffffffffffp-1022, 0x1.6a09e667f3bcdp-1022},
670 {0x1.0000000000001p-1022, 0x0.0000000000001P-1022, 0x1.0000000000001p-1022},
671 {0x1.0000000000001p-1022, 0.0, 0x1.0000000000001p-1022},
672 };
673
674 for (double[] testCase: testCases)
675 failures += testHypotCase(testCase[0], testCase[1], testCase[2]);
676
677 return failures;
678 }
679
680 public static void main(String... args) {
681 int failures = 0;
682
683 failures += testHypot();
684
685 if (failures > 0) {
686 System.err.println("Testing hypot incurred "
687 + failures + " failures.");
688 throw new RuntimeException();
689 }
690 }
691 }
|