Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/lang/Math/Ieee754SpecialCaseTests.java
41149 views
1
/*
2
* Copyright (c) 2011, 2021, 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
*/
23
24
/*
25
* @test
26
* @bug 8240632
27
* @summary Test special cases of IEEE 754 recommended ops not otherwise tested
28
* @build Tests
29
* @build Ieee754SpecialCaseTests
30
* @run main Ieee754SpecialCaseTests
31
*/
32
33
public class Ieee754SpecialCaseTests {
34
private Ieee754SpecialCaseTests() {throw new AssertionError("No instances for you.");}
35
36
public static void main(String... args) {
37
int failures = 0;
38
39
failures += testSpecialCos();
40
failures += testSpecialAcos();
41
failures += testSpecialAtan();
42
failures += testSpecialLog();
43
44
if (failures > 0) {
45
System.err.printf("Testing special cases incurred %d failures.%n", failures);
46
throw new RuntimeException();
47
}
48
}
49
private static int testSpecialCos() {
50
int failures = 0;
51
double [][] testCases = {
52
{+0.0, 1.0},
53
{-0.0, 1.0},
54
};
55
56
for(double[] testCase: testCases) {
57
failures += testCosCase(testCase[0], testCase[1]);
58
}
59
60
return failures;
61
}
62
63
private static int testCosCase(double input, double expected) {
64
int failures = 0;
65
failures += Tests.test("Math.cos", input, Math.cos(input), expected);
66
failures += Tests.test("StrictMath.cos", input, StrictMath.cos(input), expected);
67
return failures;
68
}
69
70
private static int testSpecialAcos() {
71
int failures = 0;
72
double [][] testCases = {
73
{1.0, 0.0},
74
};
75
76
for(double[] testCase: testCases) {
77
failures += testAcosCase(testCase[0], testCase[1]);
78
}
79
80
return failures;
81
}
82
83
private static int testAcosCase(double input, double expected) {
84
int failures = 0;
85
failures += Tests.test("Math.acos", input, Math.acos(input), expected);
86
failures += Tests.test("StrictMath.acos", input, StrictMath.acos(input), expected);
87
return failures;
88
}
89
90
private static int testSpecialAtan() {
91
int failures = 0;
92
double [][] testCases = {
93
{Double.POSITIVE_INFINITY, +Math.PI/2.0},
94
{Double.NEGATIVE_INFINITY, -Math.PI/2.0},
95
};
96
97
for(double[] testCase: testCases) {
98
failures += testAtanCase(testCase[0], testCase[1]);
99
}
100
101
return failures;
102
}
103
104
private static int testAtanCase(double input, double expected) {
105
int failures = 0;
106
failures += Tests.test("Math.atan", input, Math.atan(input), expected);
107
failures += Tests.test("StrictMath.atan", input, StrictMath.atan(input), expected);
108
return failures;
109
}
110
111
private static int testSpecialLog() {
112
int failures = 0;
113
double [][] testCases = {
114
{1.0, +0.0},
115
};
116
117
for(double[] testCase: testCases) {
118
failures += testLogCase(testCase[0], testCase[1]);
119
}
120
121
return failures;
122
}
123
124
private static int testLogCase(double input, double expected) {
125
int failures = 0;
126
failures += Tests.test("Math.log", input, Math.log(input), expected);
127
failures += Tests.test("StrictMath.log", input, StrictMath.log(input), expected);
128
return failures;
129
}
130
}
131
132