Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/math/BigDecimal/MultiplyTests.java
41149 views
1
/*
2
* Copyright (c) 2006, 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 6850606
27
* @summary Test BigDecimal.multiply(BigDecimal)
28
* @author xlu
29
*/
30
31
import java.math.*;
32
import static java.math.BigDecimal.*;
33
34
public class MultiplyTests {
35
36
private static int multiplyTests() {
37
int failures = 0;
38
39
BigDecimal[] bd1 = {
40
new BigDecimal("123456789"),
41
new BigDecimal("1234567898"),
42
new BigDecimal("12345678987")
43
};
44
45
BigDecimal[] bd2 = {
46
new BigDecimal("987654321"),
47
new BigDecimal("8987654321"),
48
new BigDecimal("78987654321")
49
};
50
51
// Two dimensonal array recording bd1[i] * bd2[j] &
52
// 0 <= i <= 2 && 0 <= j <= 2;
53
BigDecimal[][] expectedResults = {
54
{new BigDecimal("121932631112635269"),
55
new BigDecimal("1109586943112635269"),
56
new BigDecimal("9751562173112635269")
57
},
58
{ new BigDecimal("1219326319027587258"),
59
new BigDecimal("11095869503027587258"),
60
new BigDecimal("97515622363027587258")
61
},
62
{ new BigDecimal("12193263197189452827"),
63
new BigDecimal("110958695093189452827"),
64
new BigDecimal("975156224183189452827")
65
}
66
};
67
68
for (int i = 0; i < bd1.length; i++) {
69
for (int j = 0; j < bd2.length; j++) {
70
if (!bd1[i].multiply(bd2[j]).equals(expectedResults[i][j])) {
71
failures++;
72
}
73
}
74
}
75
76
BigDecimal x = BigDecimal.valueOf(8L, 1);
77
BigDecimal xPower = BigDecimal.valueOf(-1L);
78
try {
79
for (int i = 0; i < 100; i++) {
80
xPower = xPower.multiply(x);
81
}
82
} catch (Exception ex) {
83
failures++;
84
}
85
return failures;
86
}
87
88
public static void main(String[] args) {
89
int failures = 0;
90
91
failures += multiplyTests();
92
93
if (failures > 0) {
94
throw new RuntimeException("Incurred " + failures +
95
" failures while testing multiply.");
96
}
97
}
98
}
99
100