Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/lang/Math/FusedMultiplyAddTests.java
41149 views
1
/*
2
* Copyright (c) 2016, 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 4851642 8253409
27
* @summary Tests for Math.fusedMac and StrictMath.fusedMac.
28
* @build Tests
29
* @build FusedMultiplyAddTests
30
* @run main FusedMultiplyAddTests
31
* @run main/othervm -XX:-UseFMA FusedMultiplyAddTests
32
*/
33
34
/**
35
* The specifications for both Math.fusedMac and StrictMath.fusedMac
36
* are the same and both are exactly specified. Therefore, both
37
* methods are tested in this file.
38
*/
39
40
public class FusedMultiplyAddTests {
41
private FusedMultiplyAddTests(){}
42
43
private static final double Infinity = Double.POSITIVE_INFINITY;
44
private static final float InfinityF = Float.POSITIVE_INFINITY;
45
private static final double NaN = Double.NaN;
46
private static final float NaNf = Float.NaN;
47
48
public static void main(String... args) {
49
int failures = 0;
50
51
failures += testNonFiniteD();
52
failures += testZeroesD();
53
failures += testSimpleD();
54
55
failures += testNonFiniteF();
56
failures += testZeroesF();
57
failures += testSimpleF();
58
59
if (failures > 0) {
60
System.err.println("Testing fma incurred "
61
+ failures + " failures.");
62
throw new RuntimeException();
63
}
64
}
65
66
private static int testNonFiniteD() {
67
int failures = 0;
68
69
double [][] testCases = {
70
{Infinity, Infinity, Infinity,
71
Infinity,
72
},
73
74
{-Infinity, Infinity, -Infinity,
75
-Infinity,
76
},
77
78
{-Infinity, Infinity, Infinity,
79
NaN,
80
},
81
82
{Infinity, Infinity, -Infinity,
83
NaN,
84
},
85
86
{1.0, Infinity, 2.0,
87
Infinity,
88
},
89
90
{1.0, 2.0, Infinity,
91
Infinity,
92
},
93
94
{Infinity, 1.0, Infinity,
95
Infinity,
96
},
97
98
{Double.MAX_VALUE, 2.0, -Infinity,
99
-Infinity},
100
101
{Infinity, 1.0, -Infinity,
102
NaN,
103
},
104
105
{-Infinity, 1.0, Infinity,
106
NaN,
107
},
108
109
{1.0, NaN, 2.0,
110
NaN,
111
},
112
113
{1.0, 2.0, NaN,
114
NaN,
115
},
116
117
{Infinity, 2.0, NaN,
118
NaN,
119
},
120
121
{NaN, 2.0, Infinity,
122
NaN,
123
},
124
};
125
126
for (double[] testCase: testCases)
127
failures += testFusedMacCase(testCase[0], testCase[1], testCase[2], testCase[3]);
128
129
return failures;
130
}
131
132
private static int testZeroesD() {
133
int failures = 0;
134
135
double [][] testCases = {
136
{+0.0, +0.0, +0.0,
137
+0.0,
138
},
139
140
{-0.0, +0.0, +0.0,
141
+0.0,
142
},
143
144
{+0.0, +0.0, -0.0,
145
+0.0,
146
},
147
148
{+0.0, +0.0, -0.0,
149
+0.0,
150
},
151
152
{-0.0, +0.0, -0.0,
153
-0.0,
154
},
155
156
{-0.0, -0.0, -0.0,
157
+0.0,
158
},
159
160
{-1.0, +0.0, -0.0,
161
-0.0,
162
},
163
164
{-1.0, +0.0, +0.0,
165
+0.0,
166
},
167
168
{-2.0, +0.0, -0.0,
169
-0.0,
170
},
171
172
{-2.0, +0.0, +0.0,
173
+0.0,
174
},
175
};
176
177
for (double[] testCase: testCases)
178
failures += testFusedMacCase(testCase[0], testCase[1], testCase[2], testCase[3]);
179
180
return failures;
181
}
182
183
private static int testSimpleD() {
184
int failures = 0;
185
186
double [][] testCases = {
187
{1.0, 2.0, 3.0,
188
5.0,},
189
190
{1.0, 2.0, -2.0,
191
0.0,},
192
193
{5.0, 5.0, -25.0,
194
0.0,},
195
196
{Double.MAX_VALUE, 2.0, -Double.MAX_VALUE,
197
Double.MAX_VALUE},
198
199
{Double.MAX_VALUE, 2.0, 1.0,
200
Infinity},
201
202
{Double.MIN_VALUE, -Double.MIN_VALUE, +0.0,
203
-0.0},
204
205
{Double.MIN_VALUE, -Double.MIN_VALUE, -0.0,
206
-0.0},
207
208
{Double.MIN_VALUE, Double.MIN_VALUE, +0.0,
209
+0.0},
210
211
{Double.MIN_VALUE, Double.MIN_VALUE, -0.0,
212
+0.0},
213
214
{Double.MIN_VALUE, +0.0, -0.0,
215
+0.0},
216
217
{Double.MIN_VALUE, -0.0, -0.0,
218
-0.0},
219
220
{Double.MIN_VALUE, +0.0, +0.0,
221
+0.0},
222
223
{Double.MIN_VALUE, -0.0, +0.0,
224
+0.0},
225
226
{1.0+Math.ulp(1.0), 1.0+Math.ulp(1.0), -1.0-2.0*Math.ulp(1.0),
227
Math.ulp(1.0)*Math.ulp(1.0)},
228
};
229
230
for (double[] testCase: testCases)
231
failures += testFusedMacCase(testCase[0], testCase[1], testCase[2], testCase[3]);
232
233
return failures;
234
}
235
236
private static int testNonFiniteF() {
237
int failures = 0;
238
239
float [][] testCases = {
240
{1.0f, InfinityF, 2.0f,
241
InfinityF,
242
},
243
244
{1.0f, 2.0f, InfinityF,
245
InfinityF,
246
},
247
248
{InfinityF, 1.0f, InfinityF,
249
InfinityF,
250
},
251
252
{Float.MAX_VALUE, 2.0f, -InfinityF,
253
-InfinityF},
254
255
{InfinityF, 1.0f, -InfinityF,
256
NaNf,
257
},
258
259
{-InfinityF, 1.0f, InfinityF,
260
NaNf,
261
},
262
263
{1.0f, NaNf, 2.0f,
264
NaNf,
265
},
266
267
{1.0f, 2.0f, NaNf,
268
NaNf,
269
},
270
271
{InfinityF, 2.0f, NaNf,
272
NaNf,
273
},
274
275
{NaNf, 2.0f, InfinityF,
276
NaNf,
277
},
278
};
279
280
for (float[] testCase: testCases)
281
failures += testFusedMacCase(testCase[0], testCase[1], testCase[2], testCase[3]);
282
283
return failures;
284
}
285
286
private static int testZeroesF() {
287
int failures = 0;
288
289
float [][] testCases = {
290
{+0.0f, +0.0f, +0.0f,
291
+0.0f,
292
},
293
294
{-0.0f, +0.0f, +0.0f,
295
+0.0f,
296
},
297
298
{+0.0f, +0.0f, -0.0f,
299
+0.0f,
300
},
301
302
{+0.0f, +0.0f, -0.0f,
303
+0.0f,
304
},
305
306
{-0.0f, +0.0f, -0.0f,
307
-0.0f,
308
},
309
310
{-0.0f, -0.0f, -0.0f,
311
+0.0f,
312
},
313
314
{-1.0f, +0.0f, -0.0f,
315
-0.0f,
316
},
317
318
{-1.0f, +0.0f, +0.0f,
319
+0.0f,
320
},
321
322
{-2.0f, +0.0f, -0.0f,
323
-0.0f,
324
},
325
};
326
327
for (float[] testCase: testCases)
328
failures += testFusedMacCase(testCase[0], testCase[1], testCase[2], testCase[3]);
329
330
return failures;
331
}
332
333
private static int testSimpleF() {
334
int failures = 0;
335
336
float [][] testCases = {
337
{1.0f, 2.0f, 3.0f,
338
5.0f,},
339
340
{1.0f, 2.0f, -2.0f,
341
0.0f,},
342
343
{5.0f, 5.0f, -25.0f,
344
0.0f,},
345
346
{Float.MAX_VALUE, 2.0f, -Float.MAX_VALUE,
347
Float.MAX_VALUE},
348
349
{Float.MAX_VALUE, 2.0f, 1.0f,
350
InfinityF},
351
352
{1.0f+Math.ulp(1.0f), 1.0f+Math.ulp(1.0f), -1.0f-2.0f*Math.ulp(1.0f),
353
Math.ulp(1.0f)*Math.ulp(1.0f)},
354
355
// Double-rounding if done in double precision
356
{0x1.fffffep23f, 0x1.000004p28f, 0x1.fep5f, 0x1.000002p52f}
357
};
358
359
for (float[] testCase: testCases)
360
failures += testFusedMacCase(testCase[0], testCase[1], testCase[2], testCase[3]);
361
362
return failures;
363
}
364
365
366
private static int testFusedMacCase(double input1, double input2, double input3, double expected) {
367
int failures = 0;
368
failures += Tests.test("Math.fma(double)", input1, input2, input3,
369
Math.fma(input1, input2, input3), expected);
370
failures += Tests.test("StrictMath.fma(double)", input1, input2, input3,
371
StrictMath.fma(input1, input2, input3), expected);
372
373
// Permute first two inputs
374
failures += Tests.test("Math.fma(double)", input2, input1, input3,
375
Math.fma(input2, input1, input3), expected);
376
failures += Tests.test("StrictMath.fma(double)", input2, input1, input3,
377
StrictMath.fma(input2, input1, input3), expected);
378
return failures;
379
}
380
381
private static int testFusedMacCase(float input1, float input2, float input3, float expected) {
382
int failures = 0;
383
failures += Tests.test("Math.fma(float)", input1, input2, input3,
384
Math.fma(input1, input2, input3), expected);
385
failures += Tests.test("StrictMath.fma(float)", input1, input2, input3,
386
StrictMath.fma(input1, input2, input3), expected);
387
388
// Permute first two inputs
389
failures += Tests.test("Math.fma(float)", input2, input1, input3,
390
Math.fma(input2, input1, input3), expected);
391
failures += Tests.test("StrictMath.fma(float)", input2, input1, input3,
392
StrictMath.fma(input2, input1, input3), expected);
393
return failures;
394
}
395
}
396
397