Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/lang/StrictMath/PowTests.java
41149 views
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
*/
23
24
/*
25
* @test
26
* @bug 8136874
27
* @summary Tests for StrictMath.pow
28
* @author Joseph D. Darcy
29
*/
30
31
/**
32
* The tests in ../Math/PowTests.java test properties that should
33
* hold for any pow implementation, including the FDLIBM-based one
34
* required for StrictMath.pow. Therefore, the test cases in
35
* ../Math/PowTests.java are run against both the Math and
36
* StrictMath versions of pow. The role of this test is to verify
37
* that the FDLIBM pow algorithm is being used by running golden
38
* file tests on values that may vary from one conforming pow
39
* implementation to another.
40
*/
41
42
public class PowTests {
43
private PowTests(){}
44
45
private static final double INFINITY = Double.POSITIVE_INFINITY;
46
47
public static void main(String... args) {
48
int failures = 0;
49
50
failures += testPow();
51
52
if (failures > 0) {
53
System.err.println("Testing pow incurred "
54
+ failures + " failures.");
55
throw new RuntimeException();
56
}
57
}
58
59
private static int testPow() {
60
int failures = 0;
61
62
double [][] testCases = {
63
// Probe near decision points of the fdlibm algorithm
64
65
{0x1.00000_0000_0001p1, // |x| > 1.0
66
INFINITY, // infinity
67
INFINITY // 0
68
},
69
70
71
{0x1.fffffp-1, // |x| = 0.9999995231628418
72
0x1.0p31, // 2^31
73
0.0 // 0
74
},
75
76
{0x1.ffffe_ffffffffp-1, // |x| < 0.9999995231628418
77
0x1.0p31, // 2^31
78
0.0 // 0
79
},
80
81
{-0x1.ffffe_ffffffffp-1, // |x| < 0.9999995231628418
82
0x1.0p31, // 2^31
83
0.0 // 0
84
},
85
86
{0x1.fffffp-1, // |x| = 0.9999995231628418
87
0x1.0000000000001p31, // nextUp(2^31)
88
0.0 // 0
89
},
90
91
{0x1.fffffp-1, // |x| = 0.9999995231628418
92
0x1.0p31 + 1.0, // 2^31 + 1, odd integer
93
0.0 // 0
94
},
95
96
{0x1.fffffp-1, // |x| = 0.9999995231628418
97
0x1.0p31 + 2.0, // 2^31 + 2, even integer
98
0.0 // 0
99
},
100
101
{0x1.ffffe_ffffffffp-1, // |x| < 0.9999995231628418
102
0x1.0000000000001p31, // nextUp(2^31)
103
0.0 // 0
104
},
105
106
{-0x1.ffffe_ffffffffp-1, // |x| < 0.9999995231628418
107
0x1.0000000000001p31, // nextUp(2^31)
108
Double.NaN // 0
109
},
110
111
{-0x1.ffffe_ffffffffp-1, // |x| < 0.9999995231628418
112
0x1.0p31 + 1.0, // 2^31 + 1, odd integer
113
-0.0 // 0
114
},
115
116
{-0x1.ffffe_ffffffffp-1, // |x| < 0.9999995231628418
117
0x1.0p31 + 2.0, // 2^31 + 2, even integer
118
0.0 // 0
119
},
120
121
{0x1.0000000000001p0, // nextUp(1)
122
0x1.0000000000001p31, // nextUp(2^31)
123
0x1.00000800002p0
124
},
125
126
{0x1.0000000000001p0, // nextUp(1)
127
-0x1.0000000000001p31, // -nextUp(2^31)
128
0x1.fffff000004p-1
129
},
130
131
{-0x1.0000000000001p0, // -nextUp(1)
132
-0x1.0000000000001p31, // -nextUp(2^31)
133
Double.NaN
134
},
135
136
{-0x1.0000000000001p0, // -nextUp(1)
137
0x1.0p31 + 1.0, // 2^31 + 1, odd integer
138
-0x1.0000080000201p0
139
},
140
141
{-0x1.0000000000001p0, // -nextUp(1)
142
0x1.0p31 + 2.0, // 2^31 + 2, even integer
143
0x1.0000080000202p0
144
},
145
146
{0x1.00000_ffff_ffffp0,
147
0x1.00001_0000_0000p31,
148
INFINITY
149
},
150
151
// Huge y, |y| > 0x1.00000_ffff_ffffp31 ~2**31 is a decision point
152
153
// First y = 0x1.00001_0000_0000p31
154
{0x1.fffff_ffff_ffffp-1,
155
0x1.00001_0000_0000p31,
156
0x1.fffff7ffff9p-1
157
},
158
159
{0x1.fffff_ffff_fffep-1,
160
0x1.00001_0000_0000p31,
161
0x1.ffffefffff4p-1
162
},
163
164
{0x1.fffff_0000_0000p-1,
165
0x1.00001_0000_0000p31,
166
0.0
167
},
168
169
// Cycle through decision points on x values
170
171
{0x1.fffff_0000_0000p-1,
172
0x1.00001_0000_0000p31,
173
0.0
174
},
175
176
{-0x1.fffff_0000_0000p-1,
177
0x1.00001_0000_0000p31,
178
0.0
179
},
180
181
{0x1.ffffe_ffff_ffffp-1,
182
0x1.00001_0000_0000p31,
183
0.0
184
},
185
186
{-0x1.ffffe_ffff_ffffp-1,
187
0x1.00001_0000_0000p31,
188
0.0
189
},
190
191
{0x1.00000_ffff_ffffp0,
192
0x1.00001_0000_0000p31,
193
INFINITY
194
},
195
196
197
{0x1.00001_0000_0000p0,
198
0x1.00001_0000_0000p31,
199
INFINITY
200
},
201
202
{-0x1.00000_ffff_ffffp0,
203
0x1.00001_0000_0000p31,
204
INFINITY
205
},
206
207
208
{-0x1.00001_0000_0000p0,
209
0x1.00001_0000_0000p31,
210
INFINITY
211
},
212
213
// Now y = -0x1.00001_0000_0000p31
214
215
{0x1.fffff_0000_0000p-1,
216
-0x1.00001_0000_0000p31,
217
INFINITY
218
},
219
220
{-0x1.fffff_0000_0000p-1,
221
0x1.00001_0000_0000p31,
222
0.0
223
},
224
225
{0x1.ffffe_ffff_ffffp-1,
226
-0x1.00001_0000_0000p31,
227
INFINITY
228
},
229
230
{-0x1.ffffe_ffff_ffffp-1,
231
-0x1.00001_0000_0000p31,
232
INFINITY
233
},
234
235
{0x1.00000_ffff_ffffp0,
236
-0x1.00001_0000_0000p31,
237
0.0
238
},
239
240
241
{0x1.00001_0000_0000p0,
242
-0x1.00001_0000_0000p31,
243
0.0
244
},
245
246
{-0x1.00000_ffff_ffffp0,
247
-0x1.00001_0000_0000p31,
248
0.0
249
},
250
251
252
{-0x1.00001_0000_0000p0,
253
-0x1.00001_0000_0000p31,
254
0.0
255
},
256
257
//-----------------------
258
259
{0x1.ffffe_ffff_ffffp-1,
260
-0x1.00001_0000_0000p31,
261
INFINITY
262
},
263
264
{0x1.00001_0000_0000p0,
265
-0x1.00001_0000_0000p31,
266
0.0
267
},
268
269
270
{0x1.0000000000002p0, // 1.0000000000000004
271
0x1.f4add4p30, // 2.1E9
272
0x1.00000fa56f1a6p0 // 1.0000009325877754
273
},
274
275
// Verify no early overflow
276
{0x1.0000000000002p0, // 1.0000000000000004
277
0x1.0642acp31, // 2.2E9
278
0x1.000010642b465p0, // 1.0000009769967388
279
},
280
281
// Verify proper overflow
282
{0x1.0000000000002p0, // 1.0000000000000004
283
0x1.62e42fefa39fp60, // 1.59828858065033216E18
284
0x1.ffffffffffd9fp1023, // 1.7976931348621944E308
285
},
286
287
};
288
289
for (double[] testCase: testCases)
290
failures += testPowCase(testCase[0], testCase[1], testCase[2]);
291
292
return failures;
293
}
294
295
private static int testPowCase(double input1, double input2, double expected) {
296
int failures = 0;
297
failures += Tests.test("StrictMath.pow(double)", input1, input2,
298
StrictMath.pow(input1, input2), expected);
299
return failures;
300
}
301
}
302
303