Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/math/TestPow0Dot5Opt.java
41153 views
1
/*
2
* Copyright (C) 2021 THL A29 Limited, a Tencent company. 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 8265325 8265940
27
* @summary test the optimization of pow(x, 0.5)
28
* @run main/othervm TestPow0Dot5Opt
29
* @run main/othervm -Xint TestPow0Dot5Opt
30
* @run main/othervm -Xbatch -XX:TieredStopAtLevel=1 TestPow0Dot5Opt
31
* @run main/othervm -Xbatch -XX:-TieredCompilation TestPow0Dot5Opt
32
*/
33
34
public class TestPow0Dot5Opt {
35
36
static void test(double a) throws Exception {
37
// pow(x, 0.5) isn't replaced with sqrt(x) for x < 0.0
38
if (a < 0.0) return;
39
40
double r1 = Math.sqrt(a);
41
double r2 = Math.pow(a, 0.5);
42
if (r1 != r2) {
43
throw new RuntimeException("pow(" + a + ", 0.5), expected: " + r1 + ", actual: " + r2);
44
}
45
46
// Special case: pow(+0.0, 0.5) = 0.0
47
double r = Math.pow(+0.0, 0.5);
48
if (Double.doubleToRawLongBits(r) != Double.doubleToRawLongBits(0.0)) {
49
throw new RuntimeException("pow(+0.0, 0.5), expected: 0.0, actual: " + r);
50
}
51
52
// Special case: pow(-0.0, 0.5) = 0.0
53
r = Math.pow(-0.0, 0.5);
54
if (Double.doubleToRawLongBits(r) != Double.doubleToRawLongBits(0.0)) {
55
throw new RuntimeException("pow(-0.0, 0.5), expected: 0.0, actual: " + r);
56
}
57
58
// Special case: pow(Double.POSITIVE_INFINITY, 0.5) = Infinity
59
r = Math.pow(Double.POSITIVE_INFINITY, 0.5);
60
if (!(r > 0 && Double.isInfinite(r))) {
61
throw new RuntimeException("pow(+Infinity, 0.5), expected: Infinity, actual: " + r);
62
}
63
64
// Special case: pow(Double.NEGATIVE_INFINITY, 0.5) = Infinity
65
r = Math.pow(Double.NEGATIVE_INFINITY, 0.5);
66
if (!(r > 0 && Double.isInfinite(r))) {
67
throw new RuntimeException("pow(-Infinity, 0.5), expected: Infinity, actual: " + r);
68
}
69
70
// Special case: pow(Double.NaN, 0.5) = NaN
71
r = Math.pow(Double.NaN, 0.5);
72
if (!Double.isNaN(r)) {
73
throw new RuntimeException("pow(NaN, 0.5), expected: NaN, actual: " + r);
74
}
75
}
76
77
public static void main(String[] args) throws Exception {
78
for (int i = 0; i < 10; i++) {
79
for (int j = 1; j < 100000; j++) {
80
test(j * 1.0);
81
test(1.0 / j);
82
}
83
}
84
}
85
86
}
87
88