Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/lang/Math/MinMax.java
41152 views
1
/*
2
* Copyright (c) 1997, 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
/* @test
25
@bug 4010528 4010529
26
@summary Math.min and Math.max should treat negative zero as strictly
27
less than positive zero
28
*/
29
30
31
public class MinMax {
32
33
34
static void go(String what, float result, float correctResult) {
35
String v = what + ": got " + result + ", expected " + correctResult;
36
if (!(Float.toString(result).equals(Float.toString(correctResult))))
37
throw new RuntimeException(v);
38
System.err.println(v);
39
}
40
41
static void go(String what, double result, double correctResult) {
42
String v = what + ": got " + result + ", expected " + correctResult;
43
if (!(Double.toString(result).equals(Double.toString(correctResult))))
44
throw new RuntimeException(v);
45
System.err.println(v);
46
}
47
48
49
public static void main(String[] args) {
50
51
float fnz = -0.0f;
52
float fpz = +0.0f;
53
54
go("Math.min(fnz, fnz)", Math.min(fnz, fnz), fnz);
55
go("Math.min(fnz, fpz)", Math.min(fnz, fpz), fnz);
56
go("Math.min(fpz, fnz)", Math.min(fpz, fnz), fnz);
57
go("Math.min(fpz, fpz)", Math.min(fpz, fpz), fpz);
58
59
go("Math.min(-1.0f, fnz)", Math.min(-1.0f, fnz), -1.0f);
60
go("Math.min(-1.0f, fpz)", Math.min(-1.0f, fpz), -1.0f);
61
go("Math.min(+1.0f, fnz)", Math.min(+1.0f, fnz), fnz);
62
go("Math.min(+1.0f, fpz)", Math.min(+1.0f, fpz), fpz);
63
go("Math.min(-1.0f, +1.0f)", Math.min(-1.0f, +1.0f), -1.0f);
64
go("Math.min(fnz, -1.0f)", Math.min(fnz, -1.0f), -1.0f);
65
go("Math.min(fpz, -1.0f)", Math.min(fpz, -1.0f), -1.0f);
66
go("Math.min(fnz, +1.0f)", Math.min(fnz, +1.0f), fnz);
67
go("Math.min(fpz, +1.0f)", Math.min(fpz, +1.0f), fpz);
68
go("Math.min(+1.0f, -1.0f)", Math.min(+1.0f, -1.0f), -1.0f);
69
70
go("Math.max(fnz, fnz)", Math.max(fnz, fnz), fnz);
71
go("Math.max(fnz, fpz)", Math.max(fnz, fpz), fpz);
72
go("Math.max(fpz, fnz)", Math.max(fpz, fnz), fpz);
73
go("Math.max(fpz, fpz)", Math.max(fpz, fpz), fpz);
74
75
go("Math.max(-1.0f, fnz)", Math.max(-1.0f, fnz), fnz);
76
go("Math.max(-1.0f, fpz)", Math.max(-1.0f, fpz), fpz);
77
go("Math.max(+1.0f, fnz)", Math.max(+1.0f, fnz), +1.0f);
78
go("Math.max(+1.0f, fpz)", Math.max(+1.0f, fpz), +1.0f);
79
go("Math.max(-1.0f, +1.0f)", Math.max(-1.0f, +1.0f), +1.0f);
80
go("Math.max(fnz, -1.0f)", Math.max(fnz, -1.0f), fnz);
81
go("Math.max(fpz, -1.0f)", Math.max(fpz, -1.0f), fpz);
82
go("Math.max(fnz, +1.0f)", Math.max(fnz, +1.0f), +1.0f);
83
go("Math.max(fpz, +1.0f)", Math.max(fpz, +1.0f), +1.0f);
84
go("Math.max(+1.0f, -1.0f)", Math.max(+1.0f, -1.0f), +1.0f);
85
86
87
double dnz = -0.0d;
88
double dpz = +0.0d;
89
90
go("Math.min(dnz, dnz)", Math.min(dnz, dnz), dnz);
91
go("Math.min(dnz, dpz)", Math.min(dnz, dpz), dnz);
92
go("Math.min(dpz, dnz)", Math.min(dpz, dnz), dnz);
93
go("Math.min(dpz, dpz)", Math.min(dpz, dpz), dpz);
94
95
go("Math.min(-1.0d, dnz)", Math.min(-1.0d, dnz), -1.0d);
96
go("Math.min(-1.0d, dpz)", Math.min(-1.0d, dpz), -1.0d);
97
go("Math.min(+1.0d, dnz)", Math.min(+1.0d, dnz), dnz);
98
go("Math.min(+1.0d, dpz)", Math.min(+1.0d, dpz), dpz);
99
go("Math.min(-1.0d, +1.0d)", Math.min(-1.0d, +1.0d), -1.0d);
100
go("Math.min(dnz, -1.0d)", Math.min(dnz, -1.0d), -1.0d);
101
go("Math.min(dpz, -1.0d)", Math.min(dpz, -1.0d), -1.0d);
102
go("Math.min(dnz, +1.0d)", Math.min(dnz, +1.0d), dnz);
103
go("Math.min(dpz, +1.0d)", Math.min(dpz, +1.0d), dpz);
104
go("Math.min(+1.0d, -1.0d)", Math.min(+1.0d, -1.0d), -1.0d);
105
106
go("Math.max(dnz, dnz)", Math.max(dnz, dnz), dnz);
107
go("Math.max(dnz, dpz)", Math.max(dnz, dpz), dpz);
108
go("Math.max(dpz, dnz)", Math.max(dpz, dnz), dpz);
109
go("Math.max(dpz, dpz)", Math.max(dpz, dpz), dpz);
110
111
go("Math.max(-1.0d, dnz)", Math.max(-1.0d, dnz), dnz);
112
go("Math.max(-1.0d, dpz)", Math.max(-1.0d, dpz), dpz);
113
go("Math.max(+1.0d, dnz)", Math.max(+1.0d, dnz), +1.0d);
114
go("Math.max(+1.0d, dpz)", Math.max(+1.0d, dpz), +1.0d);
115
go("Math.max(-1.0d, +1.0d)", Math.max(-1.0d, +1.0d), +1.0d);
116
go("Math.max(dnz, -1.0d)", Math.max(dnz, -1.0d), dnz);
117
go("Math.max(dpz, -1.0d)", Math.max(dpz, -1.0d), dpz);
118
go("Math.max(dnz, +1.0d)", Math.max(dnz, +1.0d), +1.0d);
119
go("Math.max(dpz, +1.0d)", Math.max(dpz, +1.0d), +1.0d);
120
go("Math.max(+1.0d, -1.0d)", Math.max(+1.0d, -1.0d), +1.0d);
121
122
}
123
124
}
125
126