author | dfuchs |
Mon, 28 Oct 2013 10:52:07 +0100 | |
changeset 21369 | 45d88a0a11d5 |
parent 17453 | 1de0e7df9a90 |
child 38455 | 43fec67d51a3 |
permissions | -rw-r--r-- |
14420
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
1 |
/* |
17453 | 2 |
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
14420
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
4 |
* |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
8 |
* |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
13 |
* accompanied this code). |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
14 |
* |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
18 |
* |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
21 |
* questions. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
22 |
*/ |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
23 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
24 |
import java.math.BigDecimal; |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
25 |
import java.math.RoundingMode; |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
26 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
27 |
/** |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
28 |
* @test Test Math and StrictMath Floor Div / Modulo operations. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
29 |
* @bug 6282196 |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
30 |
* @summary Basic tests for Floor division and modulo methods for both Math |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
31 |
* and StrictMath for int and long datatypes. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
32 |
*/ |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
33 |
public class DivModTests { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
34 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
35 |
/** |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
36 |
* The count of test errors. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
37 |
*/ |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
38 |
private static int errors = 0; |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
39 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
40 |
/** |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
41 |
* @param args the command line arguments are unused |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
42 |
*/ |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
43 |
public static void main(String[] args) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
44 |
errors = 0; |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
45 |
testIntFloorDivMod(); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
46 |
testLongFloorDivMod(); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
47 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
48 |
if (errors > 0) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
49 |
throw new RuntimeException(errors + " errors found in DivMod methods."); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
50 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
51 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
52 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
53 |
/** |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
54 |
* Report a test failure and increment the error count. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
55 |
* @param message the formatting string |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
56 |
* @param args the variable number of arguments for the message. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
57 |
*/ |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
58 |
static void fail(String message, Object... args) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
59 |
errors++; |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
60 |
System.out.printf(message, args); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
61 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
62 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
63 |
/** |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
64 |
* Test the integer floorDiv and floorMod methods. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
65 |
* Math and StrictMath tested and the same results are expected for both. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
66 |
*/ |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
67 |
static void testIntFloorDivMod() { |
14703
84efc7a1216e
8004066: TEST_BUG: test/java/lang/Math/DivModTests.java assumes ArithmeticException message
kmo
parents:
14420
diff
changeset
|
68 |
testIntFloorDivMod(4, 0, new ArithmeticException(), new ArithmeticException()); // Should throw ArithmeticException |
14420
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
69 |
testIntFloorDivMod(4, 3, 1, 1); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
70 |
testIntFloorDivMod(3, 3, 1, 0); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
71 |
testIntFloorDivMod(2, 3, 0, 2); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
72 |
testIntFloorDivMod(1, 3, 0, 1); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
73 |
testIntFloorDivMod(0, 3, 0, 0); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
74 |
testIntFloorDivMod(4, -3, -2, -2); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
75 |
testIntFloorDivMod(3, -3, -1, 0); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
76 |
testIntFloorDivMod(2, -3, -1, -1); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
77 |
testIntFloorDivMod(1, -3, -1, -2); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
78 |
testIntFloorDivMod(0, -3, 0, 0); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
79 |
testIntFloorDivMod(-1, 3, -1, 2); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
80 |
testIntFloorDivMod(-2, 3, -1, 1); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
81 |
testIntFloorDivMod(-3, 3, -1, 0); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
82 |
testIntFloorDivMod(-4, 3, -2, 2); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
83 |
testIntFloorDivMod(-1, -3, 0, -1); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
84 |
testIntFloorDivMod(-2, -3, 0, -2); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
85 |
testIntFloorDivMod(-3, -3, 1, 0); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
86 |
testIntFloorDivMod(-4, -3, 1, -1); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
87 |
testIntFloorDivMod(Integer.MAX_VALUE, 1, Integer.MAX_VALUE, 0); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
88 |
testIntFloorDivMod(Integer.MAX_VALUE, -1, -Integer.MAX_VALUE, 0); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
89 |
testIntFloorDivMod(Integer.MAX_VALUE, 3, 715827882, 1); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
90 |
testIntFloorDivMod(Integer.MAX_VALUE - 1, 3, 715827882, 0); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
91 |
testIntFloorDivMod(Integer.MIN_VALUE, 3, -715827883, 1); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
92 |
testIntFloorDivMod(Integer.MIN_VALUE + 1, 3, -715827883, 2); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
93 |
testIntFloorDivMod(Integer.MIN_VALUE + 1, -1, Integer.MAX_VALUE, 0); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
94 |
// Special case of integer overflow |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
95 |
testIntFloorDivMod(Integer.MIN_VALUE, -1, Integer.MIN_VALUE, 0); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
96 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
97 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
98 |
/** |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
99 |
* Test FloorDiv and then FloorMod with int data. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
100 |
*/ |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
101 |
static void testIntFloorDivMod(int x, int y, Object divExpected, Object modExpected) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
102 |
testIntFloorDiv(x, y, divExpected); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
103 |
testIntFloorMod(x, y, modExpected); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
104 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
105 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
106 |
/** |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
107 |
* Test FloorDiv with int data. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
108 |
*/ |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
109 |
static void testIntFloorDiv(int x, int y, Object expected) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
110 |
Object result = doFloorDiv(x, y); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
111 |
if (!resultEquals(result, expected)) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
112 |
fail("FAIL: Math.floorDiv(%d, %d) = %s; expected %s%n", x, y, result, expected); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
113 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
114 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
115 |
Object strict_result = doStrictFloorDiv(x, y); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
116 |
if (!resultEquals(strict_result, expected)) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
117 |
fail("FAIL: StrictMath.floorDiv(%d, %d) = %s; expected %s%n", x, y, strict_result, expected); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
118 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
119 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
120 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
121 |
/** |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
122 |
* Test FloorMod with int data. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
123 |
*/ |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
124 |
static void testIntFloorMod(int x, int y, Object expected) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
125 |
Object result = doFloorMod(x, y); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
126 |
if (!resultEquals(result, expected)) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
127 |
fail("FAIL: Math.floorMod(%d, %d) = %s; expected %s%n", x, y, result, expected); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
128 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
129 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
130 |
Object strict_result = doStrictFloorMod(x, y); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
131 |
if (!resultEquals(strict_result, expected)) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
132 |
fail("FAIL: StrictMath.floorMod(%d, %d) = %s; expected %s%n", x, y, strict_result, expected); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
133 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
134 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
135 |
try { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
136 |
// Verify result against double precision floor function |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
137 |
int tmp = x / y; // Force ArithmeticException for divide by zero |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
138 |
double ff = x - Math.floor((double)x / (double)y) * y; |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
139 |
int fr = (int)ff; |
17453 | 140 |
boolean t = (fr == ((Integer)result)); |
141 |
if (!result.equals(fr)) { |
|
14420
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
142 |
fail("FAIL: Math.floorMod(%d, %d) = %s differs from Math.floor(x, y): %d%n", x, y, result, fr); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
143 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
144 |
} catch (ArithmeticException ae) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
145 |
if (y != 0) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
146 |
fail("FAIL: Math.floorMod(%d, %d); unexpected %s%n", x, y, ae); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
147 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
148 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
149 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
150 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
151 |
/** |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
152 |
* Test the floorDiv and floorMod methods for primitive long. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
153 |
*/ |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
154 |
static void testLongFloorDivMod() { |
14703
84efc7a1216e
8004066: TEST_BUG: test/java/lang/Math/DivModTests.java assumes ArithmeticException message
kmo
parents:
14420
diff
changeset
|
155 |
testLongFloorDivMod(4L, 0L, new ArithmeticException(), new ArithmeticException()); // Should throw ArithmeticException |
14420
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
156 |
testLongFloorDivMod(4L, 3L, 1L, 1L); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
157 |
testLongFloorDivMod(3L, 3L, 1L, 0L); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
158 |
testLongFloorDivMod(2L, 3L, 0L, 2L); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
159 |
testLongFloorDivMod(1L, 3L, 0L, 1L); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
160 |
testLongFloorDivMod(0L, 3L, 0L, 0L); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
161 |
testLongFloorDivMod(4L, -3L, -2L, -2L); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
162 |
testLongFloorDivMod(3L, -3L, -1L, 0l); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
163 |
testLongFloorDivMod(2L, -3L, -1L, -1L); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
164 |
testLongFloorDivMod(1L, -3L, -1L, -2L); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
165 |
testLongFloorDivMod(0L, -3L, 0L, 0L); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
166 |
testLongFloorDivMod(-1L, 3L, -1L, 2L); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
167 |
testLongFloorDivMod(-2L, 3L, -1L, 1L); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
168 |
testLongFloorDivMod(-3L, 3L, -1L, 0L); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
169 |
testLongFloorDivMod(-4L, 3L, -2L, 2L); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
170 |
testLongFloorDivMod(-1L, -3L, 0L, -1L); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
171 |
testLongFloorDivMod(-2L, -3L, 0L, -2L); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
172 |
testLongFloorDivMod(-3L, -3L, 1L, 0L); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
173 |
testLongFloorDivMod(-4L, -3L, 1L, -1L); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
174 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
175 |
testLongFloorDivMod(Long.MAX_VALUE, 1, Long.MAX_VALUE, 0L); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
176 |
testLongFloorDivMod(Long.MAX_VALUE, -1, -Long.MAX_VALUE, 0L); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
177 |
testLongFloorDivMod(Long.MAX_VALUE, 3L, Long.MAX_VALUE / 3L, 1L); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
178 |
testLongFloorDivMod(Long.MAX_VALUE - 1L, 3L, (Long.MAX_VALUE - 1L) / 3L, 0L); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
179 |
testLongFloorDivMod(Long.MIN_VALUE, 3L, Long.MIN_VALUE / 3L - 1L, 1L); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
180 |
testLongFloorDivMod(Long.MIN_VALUE + 1L, 3L, Long.MIN_VALUE / 3L - 1L, 2L); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
181 |
testLongFloorDivMod(Long.MIN_VALUE + 1, -1, Long.MAX_VALUE, 0L); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
182 |
// Special case of integer overflow |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
183 |
testLongFloorDivMod(Long.MIN_VALUE, -1, Long.MIN_VALUE, 0L); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
184 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
185 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
186 |
/** |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
187 |
* Test the integer floorDiv and floorMod methods. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
188 |
* Math and StrictMath are tested and the same results are expected for both. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
189 |
*/ |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
190 |
static void testLongFloorDivMod(long x, long y, Object divExpected, Object modExpected) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
191 |
testLongFloorDiv(x, y, divExpected); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
192 |
testLongFloorMod(x, y, modExpected); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
193 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
194 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
195 |
/** |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
196 |
* Test FloorDiv with long arguments against expected value. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
197 |
* The expected value is usually a Long but in some cases is |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
198 |
* an ArithmeticException. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
199 |
* |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
200 |
* @param x dividend |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
201 |
* @param y modulus |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
202 |
* @param expected expected value, |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
203 |
*/ |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
204 |
static void testLongFloorDiv(long x, long y, Object expected) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
205 |
Object result = doFloorDiv(x, y); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
206 |
if (!resultEquals(result, expected)) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
207 |
fail("FAIL: long Math.floorDiv(%d, %d) = %s; expected %s%n", x, y, result, expected); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
208 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
209 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
210 |
Object strict_result = doStrictFloorDiv(x, y); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
211 |
if (!resultEquals(strict_result, expected)) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
212 |
fail("FAIL: long StrictMath.floorDiv(%d, %d) = %s; expected %s%n", x, y, strict_result, expected); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
213 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
214 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
215 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
216 |
/** |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
217 |
* Test FloorMod of long arguments against expected value. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
218 |
* The expected value is usually a Long but in some cases is |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
219 |
* an ArithmeticException. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
220 |
* |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
221 |
* @param x dividend |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
222 |
* @param y modulus |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
223 |
* @param expected expected value |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
224 |
*/ |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
225 |
static void testLongFloorMod(long x, long y, Object expected) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
226 |
Object result = doFloorMod(x, y); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
227 |
if (!resultEquals(result, expected)) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
228 |
fail("FAIL: long Math.floorMod(%d, %d) = %s; expected %s%n", x, y, result, expected); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
229 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
230 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
231 |
Object strict_result = doStrictFloorMod(x, y); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
232 |
if (!resultEquals(strict_result, expected)) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
233 |
fail("FAIL: long StrictMath.floorMod(%d, %d) = %s; expected %s%n", x, y, strict_result, expected); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
234 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
235 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
236 |
try { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
237 |
// Verify the result against BigDecimal rounding mode. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
238 |
BigDecimal xD = new BigDecimal(x); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
239 |
BigDecimal yD = new BigDecimal(y); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
240 |
BigDecimal resultD = xD.divide(yD, RoundingMode.FLOOR); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
241 |
resultD = resultD.multiply(yD); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
242 |
resultD = xD.subtract(resultD); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
243 |
long fr = resultD.longValue(); |
17453 | 244 |
if (!result.equals(fr)) { |
245 |
fail("FAIL: Long.floorMod(%d, %d) = %d is different than BigDecimal result: %d%n", x, y, result, fr); |
|
14420
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
246 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
247 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
248 |
} catch (ArithmeticException ae) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
249 |
if (y != 0) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
250 |
fail("FAIL: long Math.floorMod(%d, %d); unexpected ArithmeticException from bigdecimal"); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
251 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
252 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
253 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
254 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
255 |
/** |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
256 |
* Invoke floorDiv and return the result or any exception. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
257 |
* @param x the x value |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
258 |
* @param y the y value |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
259 |
* @return the result Integer or an exception. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
260 |
*/ |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
261 |
static Object doFloorDiv(int x, int y) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
262 |
try { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
263 |
return Math.floorDiv(x, y); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
264 |
} catch (ArithmeticException ae) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
265 |
return ae; |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
266 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
267 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
268 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
269 |
/** |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
270 |
* Invoke floorDiv and return the result or any exception. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
271 |
* @param x the x value |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
272 |
* @param y the y value |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
273 |
* @return the result Integer or an exception. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
274 |
*/ |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
275 |
static Object doFloorDiv(long x, long y) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
276 |
try { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
277 |
return Math.floorDiv(x, y); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
278 |
} catch (ArithmeticException ae) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
279 |
return ae; |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
280 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
281 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
282 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
283 |
/** |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
284 |
* Invoke floorDiv and return the result or any exception. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
285 |
* @param x the x value |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
286 |
* @param y the y value |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
287 |
* @return the result Integer or an exception. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
288 |
*/ |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
289 |
static Object doFloorMod(int x, int y) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
290 |
try { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
291 |
return Math.floorMod(x, y); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
292 |
} catch (ArithmeticException ae) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
293 |
return ae; |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
294 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
295 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
296 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
297 |
/** |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
298 |
* Invoke floorDiv and return the result or any exception. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
299 |
* @param x the x value |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
300 |
* @param y the y value |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
301 |
* @return the result Integer or an exception. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
302 |
*/ |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
303 |
static Object doFloorMod(long x, long y) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
304 |
try { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
305 |
return Math.floorMod(x, y); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
306 |
} catch (ArithmeticException ae) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
307 |
return ae; |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
308 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
309 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
310 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
311 |
/** |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
312 |
* Invoke floorDiv and return the result or any exception. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
313 |
* @param x the x value |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
314 |
* @param y the y value |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
315 |
* @return the result Integer or an exception. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
316 |
*/ |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
317 |
static Object doStrictFloorDiv(int x, int y) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
318 |
try { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
319 |
return StrictMath.floorDiv(x, y); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
320 |
} catch (ArithmeticException ae) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
321 |
return ae; |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
322 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
323 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
324 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
325 |
/** |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
326 |
* Invoke floorDiv and return the result or any exception. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
327 |
* @param x the x value |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
328 |
* @param y the y value |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
329 |
* @return the result Integer or an exception. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
330 |
*/ |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
331 |
static Object doStrictFloorDiv(long x, long y) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
332 |
try { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
333 |
return StrictMath.floorDiv(x, y); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
334 |
} catch (ArithmeticException ae) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
335 |
return ae; |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
336 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
337 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
338 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
339 |
/** |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
340 |
* Invoke floorDiv and return the result or any exception. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
341 |
* @param x the x value |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
342 |
* @param y the y value |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
343 |
* @return the result Integer or an exception. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
344 |
*/ |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
345 |
static Object doStrictFloorMod(int x, int y) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
346 |
try { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
347 |
return StrictMath.floorMod(x, y); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
348 |
} catch (ArithmeticException ae) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
349 |
return ae; |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
350 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
351 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
352 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
353 |
/** |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
354 |
* Invoke floorDiv and return the result or any exception. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
355 |
* @param x the x value |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
356 |
* @param y the y value |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
357 |
* @return the result Integer or an exception. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
358 |
*/ |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
359 |
static Object doStrictFloorMod(long x, long y) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
360 |
try { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
361 |
return StrictMath.floorMod(x, y); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
362 |
} catch (ArithmeticException ae) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
363 |
return ae; |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
364 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
365 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
366 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
367 |
/** |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
368 |
* Returns a boolean by comparing the result and the expected value. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
369 |
* The equals method is not defined for ArithmeticException but it is |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
370 |
* desirable to have equals return true if the expected and the result |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
371 |
* both threw the same exception (class and message.) |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
372 |
* |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
373 |
* @param result the result from testing the method |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
374 |
* @param expected the expected value |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
375 |
* @return true if the result is equal to the expected values; false otherwise. |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
376 |
*/ |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
377 |
static boolean resultEquals(Object result, Object expected) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
378 |
if (result.getClass() != expected.getClass()) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
379 |
fail("FAIL: Result type mismatch, %s; expected: %s%n", |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
380 |
result.getClass().getName(), expected.getClass().getName()); |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
381 |
return false; |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
382 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
383 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
384 |
if (result.equals(expected)) { |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
385 |
return true; |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
386 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
387 |
// Handle special case to compare ArithmeticExceptions |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
388 |
if (result instanceof ArithmeticException && expected instanceof ArithmeticException) { |
14703
84efc7a1216e
8004066: TEST_BUG: test/java/lang/Math/DivModTests.java assumes ArithmeticException message
kmo
parents:
14420
diff
changeset
|
389 |
return true; |
14420
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
390 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
391 |
return false; |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
392 |
} |
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
393 |
|
5cbeeccf4a40
6282196: There should be Math.mod(number, modulo) methods
sherman
parents:
diff
changeset
|
394 |
} |