blob: 06f193af32f605434d1ff854354610bd3a31fe22 [file] [log] [blame]
jeffhao5d1ac922011-09-29 17:41:15 -07001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
jeffhao5d1ac922011-09-29 17:41:15 -070017import junit.framework.Assert;
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +070018import java.util.Arrays;
19import java.lang.reflect.Method;
jeffhao5d1ac922011-09-29 17:41:15 -070020
21public class Main {
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +070022 public static void main(String args[]) throws Exception {
Elliott Hughes28c384b2012-06-15 16:46:25 -070023 test_Double_doubleToRawLongBits();
24 test_Double_longBitsToDouble();
25 test_Float_floatToRawIntBits();
26 test_Float_intBitsToFloat();
27 test_Math_abs_I();
28 test_Math_abs_J();
Serban Constantinescu23abec92014-07-02 16:13:38 +010029 test_Math_min_I();
30 test_Math_max_I();
31 test_Math_min_J();
32 test_Math_max_J();
33 test_Math_min_F();
34 test_Math_max_F();
35 test_Math_min_D();
36 test_Math_max_D();
Chao-ying Fuff87d7b2015-01-19 15:51:57 -080037 test_Math_sqrt();
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010038 test_Math_ceil();
39 test_Math_floor();
40 test_Math_rint();
41 test_Math_round_D();
42 test_Math_round_F();
Chris Larsen2714fe62016-02-11 14:23:53 -080043 test_Math_isNaN_D();
44 test_Math_isNaN_F();
45 test_Math_isInfinite_D();
46 test_Math_isInfinite_F();
Zheng Xua3fe7422014-07-09 14:03:15 +080047 test_Short_reverseBytes();
48 test_Integer_reverseBytes();
49 test_Long_reverseBytes();
Serban Constantinescu23abec92014-07-02 16:13:38 +010050 test_Integer_reverse();
51 test_Long_reverse();
Scott Wakeling611d3392015-07-10 11:42:06 +010052 test_Integer_numberOfLeadingZeros();
53 test_Long_numberOfLeadingZeros();
Sebastien Hertzbf1442d2013-03-05 15:12:40 +010054 test_StrictMath_abs_I();
55 test_StrictMath_abs_J();
Serban Constantinescu23abec92014-07-02 16:13:38 +010056 test_StrictMath_min_I();
57 test_StrictMath_max_I();
58 test_StrictMath_min_J();
59 test_StrictMath_max_J();
60 test_StrictMath_min_F();
61 test_StrictMath_max_F();
62 test_StrictMath_min_D();
63 test_StrictMath_max_D();
Chao-ying Fuff87d7b2015-01-19 15:51:57 -080064 test_StrictMath_sqrt();
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010065 test_StrictMath_ceil();
66 test_StrictMath_floor();
67 test_StrictMath_rint();
68 test_StrictMath_round_D();
69 test_StrictMath_round_F();
Elliott Hughes28c384b2012-06-15 16:46:25 -070070 test_String_charAt();
71 test_String_compareTo();
72 test_String_indexOf();
73 test_String_isEmpty();
74 test_String_length();
Andreas Gampe7a949612014-07-08 11:03:59 -070075 test_Thread_currentThread();
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +070076 initSupportMethodsForPeekPoke();
77 test_Memory_peekByte();
78 test_Memory_peekShort();
79 test_Memory_peekInt();
80 test_Memory_peekLong();
81 test_Memory_pokeByte();
82 test_Memory_pokeShort();
83 test_Memory_pokeInt();
84 test_Memory_pokeLong();
Scott Wakeling9ee23f42015-07-23 10:44:35 +010085 test_Integer_numberOfTrailingZeros();
86 test_Long_numberOfTrailingZeros();
87 test_Integer_rotateRight();
88 test_Long_rotateRight();
89 test_Integer_rotateLeft();
90 test_Long_rotateLeft();
91 test_Integer_rotateRightLeft();
92 test_Long_rotateRightLeft();
Elliott Hughes28c384b2012-06-15 16:46:25 -070093 }
94
Andreas Gampe7a949612014-07-08 11:03:59 -070095 /**
96 * Will test inlining Thread.currentThread().
97 */
98 public static void test_Thread_currentThread() {
99 // 1. Do not use result.
100 Thread.currentThread();
101
102 // 2. Result should not be null.
103 Assert.assertNotNull(Thread.currentThread());
104 }
105
Elliott Hughes28c384b2012-06-15 16:46:25 -0700106 public static void test_String_length() {
107 String str0 = "";
108 String str1 = "x";
109 String str80 = "01234567890123456789012345678901234567890123456789012345678901234567890123456789";
110
111 Assert.assertEquals(str0.length(), 0);
112 Assert.assertEquals(str1.length(), 1);
113 Assert.assertEquals(str80.length(), 80);
114
115 String strNull = null;
116 try {
117 strNull.length();
118 Assert.fail();
119 } catch (NullPointerException expected) {
120 }
121 }
122
123 public static void test_String_isEmpty() {
124 String str0 = "";
125 String str1 = "x";
126
127 Assert.assertTrue(str0.isEmpty());
128 Assert.assertFalse(str1.isEmpty());
129
130 String strNull = null;
131 try {
132 strNull.isEmpty();
133 Assert.fail();
134 } catch (NullPointerException expected) {
135 }
136 }
137
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800138 // Break up the charAt tests. The optimizing compiler doesn't optimize methods with try-catch yet,
139 // so we need to separate out the tests that are expected to throw exception
140
Elliott Hughes28c384b2012-06-15 16:46:25 -0700141 public static void test_String_charAt() {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800142 String testStr = "Now is the time to test some stuff";
Elliott Hughes28c384b2012-06-15 16:46:25 -0700143
Andreas Gampe878d58c2015-01-15 23:24:00 -0800144 Assert.assertEquals(testStr.length() - 1, 33); // 33 = testStr.length()-1 as a constant.
145 Assert.assertEquals('f', testStr.charAt(33));
Elliott Hughes28c384b2012-06-15 16:46:25 -0700146
Andreas Gampe878d58c2015-01-15 23:24:00 -0800147 test_String_charAt(testStr, 'N', 'o', ' ', 'f');
148 test_String_charAt(testStr.substring(3,15), ' ', 'i', 'm', 'e');
149 }
150 public static void test_String_charAt(String testStr, char a, char b, char c, char d) {
151 Assert.assertEquals(a, testStr.charAt(0));
152 Assert.assertEquals(b, testStr.charAt(1));
153 Assert.assertEquals(c, testStr.charAt(10));
154 Assert.assertEquals(d, testStr.charAt(testStr.length()-1));
155
156 test_String_charAtExc(testStr);
157 test_String_charAtExc2(testStr);
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800158 }
159
Andreas Gampe878d58c2015-01-15 23:24:00 -0800160 private static void test_String_charAtExc(String testStr) {
Elliott Hughes28c384b2012-06-15 16:46:25 -0700161 try {
162 testStr.charAt(-1);
163 Assert.fail();
164 } catch (StringIndexOutOfBoundsException expected) {
165 }
166 try {
167 testStr.charAt(80);
168 Assert.fail();
169 } catch (StringIndexOutOfBoundsException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700170 }
Vladimir Marko00ca8472015-01-26 14:06:46 +0000171 try {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800172 if (testStr.length() == 34) {
173 testStr.charAt(34); // 34 = "Now is the time to test some stuff".length()
174 } else {
175 Assert.assertEquals(testStr.length(), 12); // 12 = " is the time".length()
176 testStr.charAt(12);
177 }
Vladimir Marko00ca8472015-01-26 14:06:46 +0000178 Assert.fail();
179 } catch (StringIndexOutOfBoundsException expected) {
180 }
181 try {
182 test_String_charAt_inner(testStr, -1);
183 Assert.fail();
184 } catch (StringIndexOutOfBoundsException expected) {
185 }
186 try {
187 test_String_charAt_inner(testStr, 80);
188 Assert.fail();
189 } catch (StringIndexOutOfBoundsException expected) {
190 }
191 try {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800192 if (testStr.length() == 34) {
193 // 34 = "Now is the time to test some stuff".length()
194 test_String_charAt_inner(testStr, 34);
195 } else {
196 Assert.assertEquals(testStr.length(), 12); // 12 = " is the time".length()
197 test_String_charAt_inner(testStr, 12);
198 }
Vladimir Marko00ca8472015-01-26 14:06:46 +0000199 Assert.fail();
200 } catch (StringIndexOutOfBoundsException expected) {
201 }
202
203 String strEmpty = "";
204 try {
205 strEmpty.charAt(0);
206 Assert.fail();
207 } catch (StringIndexOutOfBoundsException expected) {
208 }
jeffhao5d1ac922011-09-29 17:41:15 -0700209
Elliott Hughes28c384b2012-06-15 16:46:25 -0700210 String strNull = null;
211 try {
212 strNull.charAt(0);
213 Assert.fail();
214 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700215 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700216 }
jeffhao5d1ac922011-09-29 17:41:15 -0700217
Vladimir Marko00ca8472015-01-26 14:06:46 +0000218 private static char test_String_charAt_inner(String s, int index) {
219 // Using non-constant index here (assuming that this method wasn't inlined).
220 return s.charAt(index);
221 }
222
Andreas Gampe878d58c2015-01-15 23:24:00 -0800223 private static void test_String_charAtExc2(String testStr) {
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800224 try {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800225 test_String_charAtExc3(testStr);
226 Assert.fail();
227 } catch (StringIndexOutOfBoundsException expected) {
228 }
229 try {
230 test_String_charAtExc4(testStr);
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800231 Assert.fail();
232 } catch (StringIndexOutOfBoundsException expected) {
233 }
234 }
235
Andreas Gampe878d58c2015-01-15 23:24:00 -0800236 private static void test_String_charAtExc3(String testStr) {
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800237 Assert.assertEquals('N', testStr.charAt(-1));
238 }
239
Andreas Gampe878d58c2015-01-15 23:24:00 -0800240 private static void test_String_charAtExc4(String testStr) {
241 Assert.assertEquals('N', testStr.charAt(100));
242 }
243
Yevgeny Rouban34fa0d92014-03-13 12:15:58 +0700244 static int start;
Alexei Zavjalova1758d82014-04-17 01:55:43 +0700245 private static int[] negIndex = { -100000 };
Elliott Hughes28c384b2012-06-15 16:46:25 -0700246 public static void test_String_indexOf() {
247 String str0 = "";
Yevgeny Rouban34fa0d92014-03-13 12:15:58 +0700248 String str1 = "/";
Elliott Hughes28c384b2012-06-15 16:46:25 -0700249 String str3 = "abc";
250 String str10 = "abcdefghij";
251 String str40 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabc";
jeffhao5d1ac922011-09-29 17:41:15 -0700252
Elliott Hughes28c384b2012-06-15 16:46:25 -0700253 Assert.assertEquals(str0.indexOf('a'), -1);
254 Assert.assertEquals(str3.indexOf('a'), 0);
255 Assert.assertEquals(str3.indexOf('b'), 1);
256 Assert.assertEquals(str3.indexOf('c'), 2);
257 Assert.assertEquals(str10.indexOf('j'), 9);
258 Assert.assertEquals(str40.indexOf('a'), 0);
259 Assert.assertEquals(str40.indexOf('b'), 38);
260 Assert.assertEquals(str40.indexOf('c'), 39);
261 Assert.assertEquals(str0.indexOf('a',20), -1);
262 Assert.assertEquals(str0.indexOf('a',0), -1);
263 Assert.assertEquals(str0.indexOf('a',-1), -1);
Yevgeny Rouban34fa0d92014-03-13 12:15:58 +0700264 Assert.assertEquals(str1.indexOf('/',++start), -1);
Alexei Zavjalova1758d82014-04-17 01:55:43 +0700265 Assert.assertEquals(str1.indexOf('a',negIndex[0]), -1);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700266 Assert.assertEquals(str3.indexOf('a',0), 0);
267 Assert.assertEquals(str3.indexOf('a',1), -1);
268 Assert.assertEquals(str3.indexOf('a',1234), -1);
269 Assert.assertEquals(str3.indexOf('b',0), 1);
270 Assert.assertEquals(str3.indexOf('b',1), 1);
271 Assert.assertEquals(str3.indexOf('c',2), 2);
272 Assert.assertEquals(str10.indexOf('j',5), 9);
273 Assert.assertEquals(str10.indexOf('j',9), 9);
274 Assert.assertEquals(str40.indexOf('a',10), 10);
275 Assert.assertEquals(str40.indexOf('b',40), -1);
276
Andreas Gampe678e6952015-05-07 16:44:58 -0700277 testIndexOfNull();
278
Andreas Gampe21030dd2015-05-07 14:46:15 -0700279 // Same data as above, but stored so it's not a literal in the next test. -2 stands for
280 // indexOf(I) instead of indexOf(II).
281 start--;
282 int[][] searchData = {
283 { 'a', -2, -1 },
284 { 'a', -2, 0 },
285 { 'b', -2, 1 },
286 { 'c', -2, 2 },
287 { 'j', -2, 9 },
288 { 'a', -2, 0 },
289 { 'b', -2, 38 },
290 { 'c', -2, 39 },
291 { 'a', 20, -1 },
292 { 'a', 0, -1 },
293 { 'a', -1, -1 },
294 { '/', ++start, -1 },
295 { 'a', negIndex[0], -1 },
296 { 'a', 0, 0 },
297 { 'a', 1, -1 },
298 { 'a', 1234, -1 },
299 { 'b', 0, 1 },
300 { 'b', 1, 1 },
301 { 'c', 2, 2 },
302 { 'j', 5, 9 },
303 { 'j', 9, 9 },
304 { 'a', 10, 10 },
305 { 'b', 40, -1 },
306 };
307 testStringIndexOfChars(searchData);
308
Andreas Gampe678e6952015-05-07 16:44:58 -0700309 testSurrogateIndexOf();
310 }
311
Andreas Gampe21030dd2015-05-07 14:46:15 -0700312 private static void testStringIndexOfChars(int[][] searchData) {
313 // Use a try-catch to avoid inlining.
314 try {
315 testStringIndexOfCharsImpl(searchData);
316 } catch (Exception e) {
317 System.out.println("Unexpected exception");
318 }
319 }
320
321 private static void testStringIndexOfCharsImpl(int[][] searchData) {
322 String str0 = "";
323 String str1 = "/";
324 String str3 = "abc";
325 String str10 = "abcdefghij";
326 String str40 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabc";
327
328 Assert.assertEquals(str0.indexOf(searchData[0][0]), searchData[0][2]);
329 Assert.assertEquals(str3.indexOf(searchData[1][0]), searchData[1][2]);
330 Assert.assertEquals(str3.indexOf(searchData[2][0]), searchData[2][2]);
331 Assert.assertEquals(str3.indexOf(searchData[3][0]), searchData[3][2]);
332 Assert.assertEquals(str10.indexOf(searchData[4][0]), searchData[4][2]);
333 Assert.assertEquals(str40.indexOf(searchData[5][0]), searchData[5][2]);
334 Assert.assertEquals(str40.indexOf(searchData[6][0]), searchData[6][2]);
335 Assert.assertEquals(str40.indexOf(searchData[7][0]), searchData[7][2]);
336 Assert.assertEquals(str0.indexOf(searchData[8][0], searchData[8][1]), searchData[8][2]);
337 Assert.assertEquals(str0.indexOf(searchData[9][0], searchData[9][1]), searchData[9][2]);
338 Assert.assertEquals(str0.indexOf(searchData[10][0], searchData[10][1]), searchData[10][2]);
339 Assert.assertEquals(str1.indexOf(searchData[11][0], searchData[11][1]), searchData[11][2]);
340 Assert.assertEquals(str1.indexOf(searchData[12][0], searchData[12][1]), searchData[12][2]);
341 Assert.assertEquals(str3.indexOf(searchData[13][0], searchData[13][1]), searchData[13][2]);
342 Assert.assertEquals(str3.indexOf(searchData[14][0], searchData[14][1]), searchData[14][2]);
343 Assert.assertEquals(str3.indexOf(searchData[15][0], searchData[15][1]), searchData[15][2]);
344 Assert.assertEquals(str3.indexOf(searchData[16][0], searchData[16][1]), searchData[16][2]);
345 Assert.assertEquals(str3.indexOf(searchData[17][0], searchData[17][1]), searchData[17][2]);
346 Assert.assertEquals(str3.indexOf(searchData[18][0], searchData[18][1]), searchData[18][2]);
347 Assert.assertEquals(str10.indexOf(searchData[19][0], searchData[19][1]), searchData[19][2]);
348 Assert.assertEquals(str10.indexOf(searchData[20][0], searchData[20][1]), searchData[20][2]);
349 Assert.assertEquals(str40.indexOf(searchData[21][0], searchData[21][1]), searchData[21][2]);
350 Assert.assertEquals(str40.indexOf(searchData[22][0], searchData[22][1]), searchData[22][2]);
351 }
352
Andreas Gampe678e6952015-05-07 16:44:58 -0700353 private static void testSurrogateIndexOf() {
354 int supplementaryChar = 0x20b9f;
355 String surrogatePair = "\ud842\udf9f";
356 String stringWithSurrogates = "hello " + surrogatePair + " world";
357
358 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar), "hello ".length());
359 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 2), "hello ".length());
360 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 6), 6);
361 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 7), -1);
Andreas Gampeba6fdbc2015-05-07 22:31:55 -0700362
363 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar - 0x10000), -1);
364 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar | 0x80000000), -1);
Andreas Gampe678e6952015-05-07 16:44:58 -0700365 }
366
367 private static void testIndexOfNull() {
Elliott Hughes28c384b2012-06-15 16:46:25 -0700368 String strNull = null;
369 try {
Andreas Gampe678e6952015-05-07 16:44:58 -0700370 testNullIndex(strNull, 'a');
Elliott Hughes28c384b2012-06-15 16:46:25 -0700371 Assert.fail();
372 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700373 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700374 try {
Andreas Gampe678e6952015-05-07 16:44:58 -0700375 testNullIndex(strNull, 'a', 0);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700376 Assert.fail();
377 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700378 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700379 try {
Andreas Gampe678e6952015-05-07 16:44:58 -0700380 testNullIndex(strNull, 'a', -1);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700381 Assert.fail();
382 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700383 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700384 }
jeffhao5d1ac922011-09-29 17:41:15 -0700385
Andreas Gampe678e6952015-05-07 16:44:58 -0700386 private static int testNullIndex(String strNull, int c) {
387 return strNull.indexOf(c);
388 }
389
390 private static int testNullIndex(String strNull, int c, int startIndex) {
391 return strNull.indexOf(c, startIndex);
392 }
393
Elliott Hughes28c384b2012-06-15 16:46:25 -0700394 public static void test_String_compareTo() {
395 String test = "0123456789";
396 String test1 = new String("0123456789"); // different object
397 String test2 = new String("0123456780"); // different value
398 String offset = new String("xxx0123456789yyy");
399 String sub = offset.substring(3, 13);
400 String str32 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
401 String str33 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxy";
402 String lc = "abcdefg";
403 String uc = "ABCDEFG";
404 Object blah = new Object();
405
406 Assert.assertTrue(lc.toUpperCase().equals(uc));
407
408 Assert.assertEquals(str32.compareTo(str33), -1);
409 Assert.assertEquals(str33.compareTo(str32), 1);
410
411 Assert.assertTrue(test.equals(test));
412 Assert.assertTrue(test.equals(test1));
413 Assert.assertFalse(test.equals(test2));
414
415 Assert.assertEquals(test.compareTo(test1), 0);
416 Assert.assertTrue(test1.compareTo(test2) > 0);
417 Assert.assertTrue(test2.compareTo(test1) < 0);
418
419 // Compare string with a nonzero offset, in left/right side.
420 Assert.assertEquals(test.compareTo(sub), 0);
421 Assert.assertEquals(sub.compareTo(test), 0);
422 Assert.assertTrue(test.equals(sub));
423 Assert.assertTrue(sub.equals(test));
424 // Same base, one is a substring.
425 Assert.assertFalse(offset.equals(sub));
426 Assert.assertFalse(sub.equals(offset));
427 // Wrong class.
428 Assert.assertFalse(test.equals(blah));
429
430 // Null lhs - throw.
431 try {
432 test.compareTo(null);
433 Assert.fail("didn't get expected npe");
434 } catch (NullPointerException npe) {
435 }
436 // Null rhs - okay.
437 Assert.assertFalse(test.equals(null));
438
439 test = test.substring(1);
440 Assert.assertTrue(test.equals("123456789"));
441 Assert.assertFalse(test.equals(test1));
442
443 test = test.substring(1);
444 Assert.assertTrue(test.equals("23456789"));
445
446 test = test.substring(1);
447 Assert.assertTrue(test.equals("3456789"));
448
449 test = test.substring(1);
450 Assert.assertTrue(test.equals("456789"));
451
452 test = test.substring(3,5);
453 Assert.assertTrue(test.equals("78"));
454
455 test = "this/is/a/path";
456 String[] strings = test.split("/");
457 Assert.assertEquals(4, strings.length);
458
459 Assert.assertEquals("this is a path", test.replaceAll("/", " "));
460 Assert.assertEquals("this is a path", test.replace("/", " "));
461 }
462
463 public static void test_Math_abs_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800464 Math.abs(-1);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700465 Assert.assertEquals(Math.abs(0), 0);
466 Assert.assertEquals(Math.abs(123), 123);
467 Assert.assertEquals(Math.abs(-123), 123);
468 Assert.assertEquals(Math.abs(Integer.MAX_VALUE), Integer.MAX_VALUE);
469 Assert.assertEquals(Math.abs(Integer.MIN_VALUE), Integer.MIN_VALUE);
470 Assert.assertEquals(Math.abs(Integer.MIN_VALUE - 1), Integer.MAX_VALUE);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100471 Assert.assertEquals(Math.abs(Integer.MIN_VALUE + 1), Integer.MAX_VALUE);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700472 }
473
474 public static void test_Math_abs_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800475 Math.abs(-1L);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700476 Assert.assertEquals(Math.abs(0L), 0L);
477 Assert.assertEquals(Math.abs(123L), 123L);
478 Assert.assertEquals(Math.abs(-123L), 123L);
479 Assert.assertEquals(Math.abs(Long.MAX_VALUE), Long.MAX_VALUE);
480 Assert.assertEquals(Math.abs(Long.MIN_VALUE), Long.MIN_VALUE);
481 Assert.assertEquals(Math.abs(Long.MIN_VALUE - 1), Long.MAX_VALUE);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800482 Assert.assertEquals(Math.abs(2147483648L), 2147483648L);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700483 }
484
Serban Constantinescu23abec92014-07-02 16:13:38 +0100485 public static void test_Math_min_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800486 Math.min(1, 0);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700487 Assert.assertEquals(Math.min(0, 0), 0);
488 Assert.assertEquals(Math.min(1, 0), 0);
489 Assert.assertEquals(Math.min(0, 1), 0);
490 Assert.assertEquals(Math.min(0, Integer.MAX_VALUE), 0);
491 Assert.assertEquals(Math.min(Integer.MIN_VALUE, 0), Integer.MIN_VALUE);
492 Assert.assertEquals(Math.min(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MIN_VALUE);
493 }
494
Serban Constantinescu23abec92014-07-02 16:13:38 +0100495 public static void test_Math_max_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800496 Math.max(1, 0);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700497 Assert.assertEquals(Math.max(0, 0), 0);
498 Assert.assertEquals(Math.max(1, 0), 1);
499 Assert.assertEquals(Math.max(0, 1), 1);
500 Assert.assertEquals(Math.max(0, Integer.MAX_VALUE), Integer.MAX_VALUE);
501 Assert.assertEquals(Math.max(Integer.MIN_VALUE, 0), 0);
502 Assert.assertEquals(Math.max(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MAX_VALUE);
503 }
504
Serban Constantinescu23abec92014-07-02 16:13:38 +0100505 public static void test_Math_min_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800506 Math.min(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100507 Assert.assertEquals(Math.min(0L, 0L), 0L);
508 Assert.assertEquals(Math.min(1L, 0L), 0L);
509 Assert.assertEquals(Math.min(0L, 1L), 0L);
510 Assert.assertEquals(Math.min(0L, Long.MAX_VALUE), 0L);
511 Assert.assertEquals(Math.min(Long.MIN_VALUE, 0L), Long.MIN_VALUE);
512 Assert.assertEquals(Math.min(Long.MIN_VALUE, Long.MAX_VALUE), Long.MIN_VALUE);
513 }
514
515 public static void test_Math_max_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800516 Math.max(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100517 Assert.assertEquals(Math.max(0L, 0L), 0L);
518 Assert.assertEquals(Math.max(1L, 0L), 1L);
519 Assert.assertEquals(Math.max(0L, 1L), 1L);
520 Assert.assertEquals(Math.max(0L, Long.MAX_VALUE), Long.MAX_VALUE);
521 Assert.assertEquals(Math.max(Long.MIN_VALUE, 0L), 0L);
522 Assert.assertEquals(Math.max(Long.MIN_VALUE, Long.MAX_VALUE), Long.MAX_VALUE);
523 }
524
525 public static void test_Math_min_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800526 Math.min(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700527 Assert.assertTrue(Float.isNaN(Math.min(1.0f, Float.NaN)));
528 Assert.assertTrue(Float.isNaN(Math.min(Float.NaN, 1.0f)));
529 Assert.assertEquals(Math.min(-0.0f, 0.0f), -0.0f);
530 Assert.assertEquals(Math.min(0.0f, -0.0f), -0.0f);
531 Assert.assertEquals(Math.min(-0.0f, -0.0f), -0.0f);
532 Assert.assertEquals(Math.min(0.0f, 0.0f), 0.0f);
533 Assert.assertEquals(Math.min(1.0f, 0.0f), 0.0f);
534 Assert.assertEquals(Math.min(0.0f, 1.0f), 0.0f);
535 Assert.assertEquals(Math.min(0.0f, Float.MAX_VALUE), 0.0f);
536 Assert.assertEquals(Math.min(Float.MIN_VALUE, 0.0f), 0.0f);
537 Assert.assertEquals(Math.min(Float.MIN_VALUE, Float.MAX_VALUE), Float.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100538 }
539
540 public static void test_Math_max_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800541 Math.max(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700542 Assert.assertTrue(Float.isNaN(Math.max(1.0f, Float.NaN)));
543 Assert.assertTrue(Float.isNaN(Math.max(Float.NaN, 1.0f)));
544 Assert.assertEquals(Math.max(-0.0f, 0.0f), 0.0f);
545 Assert.assertEquals(Math.max(0.0f, -0.0f), 0.0f);
546 Assert.assertEquals(Math.max(-0.0f, -0.0f), -0.0f);
547 Assert.assertEquals(Math.max(0.0f, 0.0f), 0.0f);
548 Assert.assertEquals(Math.max(1.0f, 0.0f), 1.0f);
549 Assert.assertEquals(Math.max(0.0f, 1.0f), 1.0f);
550 Assert.assertEquals(Math.max(0.0f, Float.MAX_VALUE), Float.MAX_VALUE);
551 Assert.assertEquals(Math.max(Float.MIN_VALUE, 0.0f), Float.MIN_VALUE);
552 Assert.assertEquals(Math.max(Float.MIN_VALUE, Float.MAX_VALUE), Float.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100553 }
554
555 public static void test_Math_min_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800556 Math.min(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700557 Assert.assertTrue(Double.isNaN(Math.min(1.0d, Double.NaN)));
558 Assert.assertTrue(Double.isNaN(Math.min(Double.NaN, 1.0d)));
559 Assert.assertEquals(Math.min(-0.0d, 0.0d), -0.0d);
560 Assert.assertEquals(Math.min(0.0d, -0.0d), -0.0d);
561 Assert.assertEquals(Math.min(-0.0d, -0.0d), -0.0d);
562 Assert.assertEquals(Math.min(0.0d, 0.0d), 0.0d);
563 Assert.assertEquals(Math.min(1.0d, 0.0d), 0.0d);
564 Assert.assertEquals(Math.min(0.0d, 1.0d), 0.0d);
565 Assert.assertEquals(Math.min(0.0d, Double.MAX_VALUE), 0.0d);
566 Assert.assertEquals(Math.min(Double.MIN_VALUE, 0.0d), 0.0d);
567 Assert.assertEquals(Math.min(Double.MIN_VALUE, Double.MAX_VALUE), Double.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100568 }
569
570 public static void test_Math_max_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800571 Math.max(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700572 Assert.assertTrue(Double.isNaN(Math.max(1.0d, Double.NaN)));
573 Assert.assertTrue(Double.isNaN(Math.max(Double.NaN, 1.0d)));
574 Assert.assertEquals(Math.max(-0.0d, 0.0d), 0.0d);
575 Assert.assertEquals(Math.max(0.0d, -0.0d), 0.0d);
576 Assert.assertEquals(Math.max(-0.0d, -0.0d), -0.0d);
577 Assert.assertEquals(Math.max(0.0d, 0.0d), 0.0d);
578 Assert.assertEquals(Math.max(1.0d, 0.0d), 1.0d);
579 Assert.assertEquals(Math.max(0.0d, 1.0d), 1.0d);
580 Assert.assertEquals(Math.max(0.0d, Double.MAX_VALUE), Double.MAX_VALUE);
581 Assert.assertEquals(Math.max(Double.MIN_VALUE, 0.0d), Double.MIN_VALUE);
582 Assert.assertEquals(Math.max(Double.MIN_VALUE, Double.MAX_VALUE), Double.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100583 }
584
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800585 public static void test_Math_sqrt() {
586 Math.sqrt(+4.0);
587 Assert.assertEquals(Math.sqrt(+4.0), +2.0d, 0.0);
588 Assert.assertEquals(Math.sqrt(+49.0), +7.0d, 0.0);
589 Assert.assertEquals(Math.sqrt(+1.44), +1.2d, 0.0);
590 }
591
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100592 public static void test_Math_ceil() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800593 Math.ceil(-0.9);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100594 Assert.assertEquals(Math.ceil(+0.0), +0.0d, 0.0);
595 Assert.assertEquals(Math.ceil(-0.0), -0.0d, 0.0);
596 Assert.assertEquals(Math.ceil(-0.9), -0.0d, 0.0);
597 Assert.assertEquals(Math.ceil(-0.5), -0.0d, 0.0);
598 Assert.assertEquals(Math.ceil(0.0), -0.0d, 0.0);
599 Assert.assertEquals(Math.ceil(+2.0), +2.0d, 0.0);
600 Assert.assertEquals(Math.ceil(+2.1), +3.0d, 0.0);
601 Assert.assertEquals(Math.ceil(+2.5), +3.0d, 0.0);
602 Assert.assertEquals(Math.ceil(+2.9), +3.0d, 0.0);
603 Assert.assertEquals(Math.ceil(+3.0), +3.0d, 0.0);
604 Assert.assertEquals(Math.ceil(-2.0), -2.0d, 0.0);
605 Assert.assertEquals(Math.ceil(-2.1), -2.0d, 0.0);
606 Assert.assertEquals(Math.ceil(-2.5), -2.0d, 0.0);
607 Assert.assertEquals(Math.ceil(-2.9), -2.0d, 0.0);
608 Assert.assertEquals(Math.ceil(-3.0), -3.0d, 0.0);
Chris Larsen82831092015-08-25 09:06:58 -0700609 // 2^52 - 1.5
610 Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0x432FFFFFFFFFFFFDl)),
611 Double.longBitsToDouble(0x432FFFFFFFFFFFFEl), 0.0);
612 // 2^52 - 0.5
613 Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0x432FFFFFFFFFFFFFl)),
614 Double.longBitsToDouble(0x4330000000000000l), 0.0);
615 // 2^52
616 Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0x4330000000000000l)),
617 Double.longBitsToDouble(0x4330000000000000l), 0.0);
618 // 2^53 - 1
619 Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0x433FFFFFFFFFFFFFl)),
620 Double.longBitsToDouble(0x433FFFFFFFFFFFFFl), 0.0);
621 // 2^53
622 Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0x4340000000000000l)),
623 Double.longBitsToDouble(0x4340000000000000l), 0.0);
624 // 2^63 - 2^10
625 Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0x43DFFFFFFFFFFFFFl)),
626 Double.longBitsToDouble(0x43DFFFFFFFFFFFFFl), 0.0);
627 // 2^63
628 Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0x43E0000000000000l)),
629 Double.longBitsToDouble(0x43E0000000000000l), 0.0);
630 // 2^64
631 Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0x43F0000000000000l)),
632 Double.longBitsToDouble(0x43F0000000000000l), 0.0);
633 // -(2^52 - 1.5)
634 Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0xC32FFFFFFFFFFFFDl)),
635 Double.longBitsToDouble(0xC32FFFFFFFFFFFFCl), 0.0);
636 // -(2^52 - 0.5)
637 Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0xC32FFFFFFFFFFFFFl)),
638 Double.longBitsToDouble(0xC32FFFFFFFFFFFFEl), 0.0);
639 // -2^52
640 Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0xC330000000000000l)),
641 Double.longBitsToDouble(0xC330000000000000l), 0.0);
642 // -(2^53 - 1)
643 Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0xC33FFFFFFFFFFFFFl)),
644 Double.longBitsToDouble(0xC33FFFFFFFFFFFFFl), 0.0);
645 // -2^53
646 Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0xC340000000000000l)),
647 Double.longBitsToDouble(0xC340000000000000l), 0.0);
648 // -(2^63 - 2^10)
649 Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0xC3DFFFFFFFFFFFFFl)),
650 Double.longBitsToDouble(0xC3DFFFFFFFFFFFFFl), 0.0);
651 // -2^63
652 Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0xC3E0000000000000l)),
653 Double.longBitsToDouble(0xC3E0000000000000l), 0.0);
654 // -2^64
655 Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0xC3F0000000000000l)),
656 Double.longBitsToDouble(0xC3F0000000000000l), 0.0);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100657 Assert.assertEquals(Math.ceil(Double.NaN), Double.NaN, 0.0);
658 Assert.assertEquals(Math.ceil(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
659 Assert.assertEquals(Math.ceil(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
660 }
661
662 public static void test_Math_floor() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800663 Math.floor(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100664 Assert.assertEquals(Math.floor(+0.0), +0.0d, 0.0);
665 Assert.assertEquals(Math.floor(-0.0), -0.0d, 0.0);
666 Assert.assertEquals(Math.floor(+2.0), +2.0d, 0.0);
667 Assert.assertEquals(Math.floor(+2.1), +2.0d, 0.0);
668 Assert.assertEquals(Math.floor(+2.5), +2.0d, 0.0);
669 Assert.assertEquals(Math.floor(+2.9), +2.0d, 0.0);
670 Assert.assertEquals(Math.floor(+3.0), +3.0d, 0.0);
671 Assert.assertEquals(Math.floor(-2.0), -2.0d, 0.0);
672 Assert.assertEquals(Math.floor(-2.1), -3.0d, 0.0);
673 Assert.assertEquals(Math.floor(-2.5), -3.0d, 0.0);
674 Assert.assertEquals(Math.floor(-2.9), -3.0d, 0.0);
675 Assert.assertEquals(Math.floor(-3.0), -3.0d, 0.0);
Chris Larsen82831092015-08-25 09:06:58 -0700676 // 2^52 - 1.5
677 Assert.assertEquals(Math.floor(Double.longBitsToDouble(0x432FFFFFFFFFFFFDl)),
678 Double.longBitsToDouble(0x432FFFFFFFFFFFFCl), 0.0);
679 // 2^52 - 0.5
680 Assert.assertEquals(Math.floor(Double.longBitsToDouble(0x432FFFFFFFFFFFFFl)),
681 Double.longBitsToDouble(0x432FFFFFFFFFFFFEl), 0.0);
682 // 2^52
683 Assert.assertEquals(Math.floor(Double.longBitsToDouble(0x4330000000000000l)),
684 Double.longBitsToDouble(0x4330000000000000l), 0.0);
685 // 2^53 - 1
686 Assert.assertEquals(Math.floor(Double.longBitsToDouble(0x433FFFFFFFFFFFFFl)),
687 Double.longBitsToDouble(0x433FFFFFFFFFFFFFl), 0.0);
688 // 2^53
689 Assert.assertEquals(Math.floor(Double.longBitsToDouble(0x4340000000000000l)),
690 Double.longBitsToDouble(0x4340000000000000l), 0.0);
691 // 2^63 - 2^10
692 Assert.assertEquals(Math.floor(Double.longBitsToDouble(0x43DFFFFFFFFFFFFFl)),
693 Double.longBitsToDouble(0x43DFFFFFFFFFFFFFl), 0.0);
694 // 2^63
695 Assert.assertEquals(Math.floor(Double.longBitsToDouble(0x43E0000000000000l)),
696 Double.longBitsToDouble(0x43E0000000000000l), 0.0);
697 // 2^64
698 Assert.assertEquals(Math.floor(Double.longBitsToDouble(0x43F0000000000000l)),
699 Double.longBitsToDouble(0x43F0000000000000l), 0.0);
700 // -(2^52 - 1.5)
701 Assert.assertEquals(Math.floor(Double.longBitsToDouble(0xC32FFFFFFFFFFFFDl)),
702 Double.longBitsToDouble(0xC32FFFFFFFFFFFFEl), 0.0);
703 // -(2^52 - 0.5)
704 Assert.assertEquals(Math.floor(Double.longBitsToDouble(0xC32FFFFFFFFFFFFFl)),
705 Double.longBitsToDouble(0xC330000000000000l), 0.0);
706 // -2^52
707 Assert.assertEquals(Math.floor(Double.longBitsToDouble(0xC330000000000000l)),
708 Double.longBitsToDouble(0xC330000000000000l), 0.0);
709 // -(2^53 - 1)
710 Assert.assertEquals(Math.floor(Double.longBitsToDouble(0xC33FFFFFFFFFFFFFl)),
711 Double.longBitsToDouble(0xC33FFFFFFFFFFFFFl), 0.0);
712 // -2^53
713 Assert.assertEquals(Math.floor(Double.longBitsToDouble(0xC340000000000000l)),
714 Double.longBitsToDouble(0xC340000000000000l), 0.0);
715 // -(2^63 - 2^10)
716 Assert.assertEquals(Math.floor(Double.longBitsToDouble(0xC3DFFFFFFFFFFFFFl)),
717 Double.longBitsToDouble(0xC3DFFFFFFFFFFFFFl), 0.0);
718 // -2^63
719 Assert.assertEquals(Math.floor(Double.longBitsToDouble(0xC3E0000000000000l)),
720 Double.longBitsToDouble(0xC3E0000000000000l), 0.0);
721 // -2^64
722 Assert.assertEquals(Math.floor(Double.longBitsToDouble(0xC3F0000000000000l)),
723 Double.longBitsToDouble(0xC3F0000000000000l), 0.0);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100724 Assert.assertEquals(Math.floor(Double.NaN), Double.NaN, 0.0);
725 Assert.assertEquals(Math.floor(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
726 Assert.assertEquals(Math.floor(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
727 }
728
729 public static void test_Math_rint() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800730 Math.rint(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100731 Assert.assertEquals(Math.rint(+0.0), +0.0d, 0.0);
732 Assert.assertEquals(Math.rint(-0.0), -0.0d, 0.0);
733 Assert.assertEquals(Math.rint(+2.0), +2.0d, 0.0);
734 Assert.assertEquals(Math.rint(+2.1), +2.0d, 0.0);
735 Assert.assertEquals(Math.rint(+2.5), +2.0d, 0.0);
736 Assert.assertEquals(Math.rint(+2.9), +3.0d, 0.0);
737 Assert.assertEquals(Math.rint(+3.0), +3.0d, 0.0);
738 Assert.assertEquals(Math.rint(-2.0), -2.0d, 0.0);
739 Assert.assertEquals(Math.rint(-2.1), -2.0d, 0.0);
740 Assert.assertEquals(Math.rint(-2.5), -2.0d, 0.0);
741 Assert.assertEquals(Math.rint(-2.9), -3.0d, 0.0);
742 Assert.assertEquals(Math.rint(-3.0), -3.0d, 0.0);
Chris Larsen82831092015-08-25 09:06:58 -0700743 // 2^52 - 1.5
744 Assert.assertEquals(Math.rint(Double.longBitsToDouble(0x432FFFFFFFFFFFFDl)),
745 Double.longBitsToDouble(0x432FFFFFFFFFFFFCl), 0.0);
746 // 2^52 - 0.5
747 Assert.assertEquals(Math.rint(Double.longBitsToDouble(0x432FFFFFFFFFFFFFl)),
748 Double.longBitsToDouble(0x4330000000000000l), 0.0);
749 // 2^52
750 Assert.assertEquals(Math.rint(Double.longBitsToDouble(0x4330000000000000l)),
751 Double.longBitsToDouble(0x4330000000000000l), 0.0);
752 // 2^53 - 1
753 Assert.assertEquals(Math.rint(Double.longBitsToDouble(0x433FFFFFFFFFFFFFl)),
754 Double.longBitsToDouble(0x433FFFFFFFFFFFFFl), 0.0);
755 // 2^53
756 Assert.assertEquals(Math.rint(Double.longBitsToDouble(0x4340000000000000l)),
757 Double.longBitsToDouble(0x4340000000000000l), 0.0);
758 // 2^63 - 2^10
759 Assert.assertEquals(Math.rint(Double.longBitsToDouble(0x43DFFFFFFFFFFFFFl)),
760 Double.longBitsToDouble(0x43DFFFFFFFFFFFFFl), 0.0);
761 // 2^63
762 Assert.assertEquals(Math.rint(Double.longBitsToDouble(0x43E0000000000000l)),
763 Double.longBitsToDouble(0x43E0000000000000l), 0.0);
764 // 2^64
765 Assert.assertEquals(Math.rint(Double.longBitsToDouble(0x43F0000000000000l)),
766 Double.longBitsToDouble(0x43F0000000000000l), 0.0);
767 // -(2^52 - 1.5)
768 Assert.assertEquals(Math.rint(Double.longBitsToDouble(0xC32FFFFFFFFFFFFDl)),
769 Double.longBitsToDouble(0xC32FFFFFFFFFFFFCl), 0.0);
770 // -(2^52 - 0.5)
771 Assert.assertEquals(Math.rint(Double.longBitsToDouble(0xC32FFFFFFFFFFFFFl)),
772 Double.longBitsToDouble(0xC330000000000000l), 0.0);
773 // -2^52
774 Assert.assertEquals(Math.rint(Double.longBitsToDouble(0xC330000000000000l)),
775 Double.longBitsToDouble(0xC330000000000000l), 0.0);
776 // -(2^53 - 1)
777 Assert.assertEquals(Math.rint(Double.longBitsToDouble(0xC33FFFFFFFFFFFFFl)),
778 Double.longBitsToDouble(0xC33FFFFFFFFFFFFFl), 0.0);
779 // -2^53
780 Assert.assertEquals(Math.rint(Double.longBitsToDouble(0xC340000000000000l)),
781 Double.longBitsToDouble(0xC340000000000000l), 0.0);
782 // -(2^63 - 2^10)
783 Assert.assertEquals(Math.rint(Double.longBitsToDouble(0xC3DFFFFFFFFFFFFFl)),
784 Double.longBitsToDouble(0xC3DFFFFFFFFFFFFFl), 0.0);
785 // -2^63
786 Assert.assertEquals(Math.rint(Double.longBitsToDouble(0xC3E0000000000000l)),
787 Double.longBitsToDouble(0xC3E0000000000000l), 0.0);
788 // -2^64
789 Assert.assertEquals(Math.rint(Double.longBitsToDouble(0xC3F0000000000000l)),
790 Double.longBitsToDouble(0xC3F0000000000000l), 0.0);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100791 Assert.assertEquals(Math.rint(Double.NaN), Double.NaN, 0.0);
792 Assert.assertEquals(Math.rint(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
793 Assert.assertEquals(Math.rint(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
794 }
795
796 public static void test_Math_round_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800797 Math.round(2.1d);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100798 Assert.assertEquals(Math.round(+0.0d), (long)+0.0);
799 Assert.assertEquals(Math.round(-0.0d), (long)+0.0);
800 Assert.assertEquals(Math.round(2.0d), 2l);
801 Assert.assertEquals(Math.round(2.1d), 2l);
802 Assert.assertEquals(Math.round(2.5d), 3l);
803 Assert.assertEquals(Math.round(2.9d), 3l);
804 Assert.assertEquals(Math.round(3.0d), 3l);
805 Assert.assertEquals(Math.round(-2.0d), -2l);
806 Assert.assertEquals(Math.round(-2.1d), -2l);
807 Assert.assertEquals(Math.round(-2.5d), -2l);
808 Assert.assertEquals(Math.round(-2.9d), -3l);
809 Assert.assertEquals(Math.round(-3.0d), -3l);
Yi Kong879ca672015-11-18 14:11:44 +0000810 Assert.assertEquals(Math.round(0.49999999999999994d), 0l);
Chris Larsen7adaab02016-04-21 14:49:20 -0700811 Assert.assertEquals(Math.round(4503599627370495.0d), 4503599627370495l); // 2^52 - 1
812 Assert.assertEquals(Math.round(4503599627370495.5d), 4503599627370496l); // 2^52 - 0.5
813 Assert.assertEquals(Math.round(4503599627370496.0d), 4503599627370496l); // 2^52
814 Assert.assertEquals(Math.round(-4503599627370495.0d), -4503599627370495l); // -(2^52 - 1)
815 Assert.assertEquals(Math.round(-4503599627370495.5d), -4503599627370495l); // -(2^52 - 0.5)
816 Assert.assertEquals(Math.round(-4503599627370496.0d), -4503599627370496l); // -2^52
Hans Boehm92d4f0e2016-02-17 12:14:03 -0800817 Assert.assertEquals(Math.round(9007199254740991.0d), 9007199254740991l); // 2^53 - 1
Chris Larsenf09d5322016-04-22 12:06:34 -0700818 Assert.assertEquals(Math.round(-9007199254740991.0d), -9007199254740991l); // -(2^53 - 1)
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100819 Assert.assertEquals(Math.round(Double.NaN), (long)+0.0d);
820 Assert.assertEquals(Math.round(Long.MAX_VALUE + 1.0d), Long.MAX_VALUE);
821 Assert.assertEquals(Math.round(Long.MIN_VALUE - 1.0d), Long.MIN_VALUE);
Chris Larsen7adaab02016-04-21 14:49:20 -0700822 Assert.assertEquals(Math.round(Double.longBitsToDouble(0x43F0000000000000l)),
823 Long.MAX_VALUE); // 2^64
824 Assert.assertEquals(Math.round(Double.longBitsToDouble(0xC3F0000000000000l)),
825 Long.MIN_VALUE); // -2^64
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100826 Assert.assertEquals(Math.round(Double.POSITIVE_INFINITY), Long.MAX_VALUE);
827 Assert.assertEquals(Math.round(Double.NEGATIVE_INFINITY), Long.MIN_VALUE);
828 }
829
830 public static void test_Math_round_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800831 Math.round(2.1f);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100832 Assert.assertEquals(Math.round(+0.0f), (int)+0.0);
833 Assert.assertEquals(Math.round(-0.0f), (int)+0.0);
834 Assert.assertEquals(Math.round(2.0f), 2);
835 Assert.assertEquals(Math.round(2.1f), 2);
836 Assert.assertEquals(Math.round(2.5f), 3);
837 Assert.assertEquals(Math.round(2.9f), 3);
838 Assert.assertEquals(Math.round(3.0f), 3);
839 Assert.assertEquals(Math.round(-2.0f), -2);
840 Assert.assertEquals(Math.round(-2.1f), -2);
841 Assert.assertEquals(Math.round(-2.5f), -2);
842 Assert.assertEquals(Math.round(-2.9f), -3);
843 Assert.assertEquals(Math.round(-3.0f), -3);
Chris Larsenb74353a2015-11-20 09:07:09 -0800844 // 0.4999999701976776123046875
845 Assert.assertEquals(Math.round(Float.intBitsToFloat(0x3EFFFFFF)), (int)+0.0f);
Chris Larsenf09d5322016-04-22 12:06:34 -0700846 Assert.assertEquals(Math.round(8388607.0f), 8388607); // 2^23 - 1
847 Assert.assertEquals(Math.round(8388607.5f), 8388608); // 2^23 - 0.5
848 Assert.assertEquals(Math.round(8388608.0f), 8388608); // 2^23
849 Assert.assertEquals(Math.round(-8388607.0f), -8388607); // -(2^23 - 1)
850 Assert.assertEquals(Math.round(-8388607.5f), -8388607); // -(2^23 - 0.5)
851 Assert.assertEquals(Math.round(-8388608.0f), -8388608); // -2^23
Hans Boehm92d4f0e2016-02-17 12:14:03 -0800852 Assert.assertEquals(Math.round(16777215.0f), 16777215); // 2^24 - 1
Chris Larsenf09d5322016-04-22 12:06:34 -0700853 Assert.assertEquals(Math.round(16777216.0f), 16777216); // 2^24
854 Assert.assertEquals(Math.round(-16777215.0f), -16777215); // -(2^24 - 1)
855 Assert.assertEquals(Math.round(-16777216.0f), -16777216); // -2^24
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100856 Assert.assertEquals(Math.round(Float.NaN), (int)+0.0f);
857 Assert.assertEquals(Math.round(Integer.MAX_VALUE + 1.0f), Integer.MAX_VALUE);
858 Assert.assertEquals(Math.round(Integer.MIN_VALUE - 1.0f), Integer.MIN_VALUE);
Chris Larsen7adaab02016-04-21 14:49:20 -0700859 Assert.assertEquals(Math.round(Float.intBitsToFloat(0x4F800000)),
860 Integer.MAX_VALUE); // 2^32
861 Assert.assertEquals(Math.round(Float.intBitsToFloat(0xCF800000)),
862 Integer.MIN_VALUE); // -2^32
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100863 Assert.assertEquals(Math.round(Float.POSITIVE_INFINITY), Integer.MAX_VALUE);
864 Assert.assertEquals(Math.round(Float.NEGATIVE_INFINITY), Integer.MIN_VALUE);
865 }
866
Chris Larsen2714fe62016-02-11 14:23:53 -0800867 public static void test_Math_isNaN_D() {
868 // Quiet NaN.
869 Assert.assertTrue(Double.isNaN(Double.longBitsToDouble(0x7FF4000000000000l)));
870 Assert.assertTrue(Double.isNaN(Double.longBitsToDouble(0xFFF4000000000000l)));
871 // Signaling NaN.
872 Assert.assertTrue(Double.isNaN(Double.longBitsToDouble(0x7FF8000000000000l)));
873 Assert.assertTrue(Double.isNaN(Double.longBitsToDouble(0xFFF8000000000000l)));
874 // Distinct from +/- infinity.
875 Assert.assertFalse(Double.isNaN(Double.longBitsToDouble(0x7FF0000000000000l)));
876 Assert.assertFalse(Double.isNaN(Double.longBitsToDouble(0xFFF0000000000000l)));
877 // Distinct from normal numbers.
878 Assert.assertFalse(Double.isNaN(Double.longBitsToDouble(0x7FE0000000000000l)));
879 Assert.assertFalse(Double.isNaN(Double.longBitsToDouble(0xFFE0000000000000l)));
880 Assert.assertFalse(Double.isNaN(Double.longBitsToDouble(0x0010000000000000l)));
881 Assert.assertFalse(Double.isNaN(Double.longBitsToDouble(0x8010000000000000l)));
882 // Distinct from +/- zero.
883 Assert.assertFalse(Double.isNaN(Double.longBitsToDouble(0x0000000000000000l)));
884 Assert.assertFalse(Double.isNaN(Double.longBitsToDouble(0x8000000000000000l)));
885 // Distinct from subnormal numbers.
886 Assert.assertFalse(Double.isNaN(Double.longBitsToDouble(0x0008000000000000l)));
887 Assert.assertFalse(Double.isNaN(Double.longBitsToDouble(0x8008000000000000l)));
888 Assert.assertFalse(Double.isNaN(Double.longBitsToDouble(0x0000000000000001l)));
889 Assert.assertFalse(Double.isNaN(Double.longBitsToDouble(0x8000000000000001l)));
890 }
891
892 public static void test_Math_isNaN_F() {
893 // Quiet NaN.
894 Assert.assertTrue(Float.isNaN(Float.intBitsToFloat(0x7FA00000)));
895 Assert.assertTrue(Float.isNaN(Float.intBitsToFloat(0xFFA00000)));
896 // Signaling NaN.
897 Assert.assertTrue(Float.isNaN(Float.intBitsToFloat(0x7FC00000)));
898 Assert.assertTrue(Float.isNaN(Float.intBitsToFloat(0xFFC00000)));
899 // Distinct from +/- infinity.
900 Assert.assertFalse(Float.isNaN(Float.intBitsToFloat(0x7F800000)));
901 Assert.assertFalse(Float.isNaN(Float.intBitsToFloat(0xFF800000)));
902 // Distinct from normal numbers.
903 Assert.assertFalse(Float.isNaN(Float.intBitsToFloat(0x7F000000)));
904 Assert.assertFalse(Float.isNaN(Float.intBitsToFloat(0xFF000000)));
905 Assert.assertFalse(Float.isNaN(Float.intBitsToFloat(0x00800000)));
906 Assert.assertFalse(Float.isNaN(Float.intBitsToFloat(0x80800000)));
907 // Distinct from +/- zero.
908 Assert.assertFalse(Float.isNaN(Float.intBitsToFloat(0x00000000)));
909 Assert.assertFalse(Float.isNaN(Float.intBitsToFloat(0x80000000)));
910 // Distinct from subnormal numbers.
911 Assert.assertFalse(Float.isNaN(Float.intBitsToFloat(0x00400000)));
912 Assert.assertFalse(Float.isNaN(Float.intBitsToFloat(0x80400000)));
913 Assert.assertFalse(Float.isNaN(Float.intBitsToFloat(0x00000001)));
914 Assert.assertFalse(Float.isNaN(Float.intBitsToFloat(0x80000001)));
915 }
916
917 public static void test_Math_isInfinite_D() {
918 // Distinct from Quiet NaN.
919 Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0x7FF4000000000000l)));
920 Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0xFFF4000000000000l)));
921 // Distinct from Signaling NaN.
922 Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0x7FF8000000000000l)));
923 Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0xFFF8000000000000l)));
924 // +/- infinity.
925 Assert.assertTrue(Double.isInfinite(Double.longBitsToDouble(0x7FF0000000000000l)));
926 Assert.assertTrue(Double.isInfinite(Double.longBitsToDouble(0xFFF0000000000000l)));
927 // Distinct from normal numbers.
928 Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0x7FE0000000000000l)));
929 Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0xFFE0000000000000l)));
930 Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0x0010000000000000l)));
931 Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0x8010000000000000l)));
932 // Distinct from +/- zero.
933 Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0x0000000000000000l)));
934 Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0x8000000000000000l)));
935 // Distinct from subnormal numbers.
936 Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0x0008000000000000l)));
937 Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0x8008000000000000l)));
938 Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0x0000000000000001l)));
939 Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0x8000000000000001l)));
940 }
941
942 public static void test_Math_isInfinite_F() {
943 // Distinct from Quiet NaN.
944 Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0x7FA00000)));
945 Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0xFFA00000)));
946 // Distinct from Signaling NaN.
947 Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0x7FC00000)));
948 Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0xFFC00000)));
949 // +/- infinity.
950 Assert.assertTrue(Float.isInfinite(Float.intBitsToFloat(0x7F800000)));
951 Assert.assertTrue(Float.isInfinite(Float.intBitsToFloat(0xFF800000)));
952 // Distinct from normal numbers.
953 Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0x7F000000)));
954 Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0xFF000000)));
955 Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0x00800000)));
956 Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0x80800000)));
957 // Distinct from +/- zero.
958 Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0x00000000)));
959 Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0x80000000)));
960 // Distinct from subnormal numbers.
961 Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0x00400000)));
962 Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0x80400000)));
963 Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0x00000001)));
964 Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0x80000001)));
965 }
966
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100967 public static void test_StrictMath_abs_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800968 StrictMath.abs(-1);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100969 Assert.assertEquals(StrictMath.abs(0), 0);
970 Assert.assertEquals(StrictMath.abs(123), 123);
971 Assert.assertEquals(StrictMath.abs(-123), 123);
972 Assert.assertEquals(StrictMath.abs(Integer.MAX_VALUE), Integer.MAX_VALUE);
973 Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE), Integer.MIN_VALUE);
974 Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE - 1), Integer.MAX_VALUE);
975 Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE + 1), Integer.MAX_VALUE);
976 }
977
978 public static void test_StrictMath_abs_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800979 StrictMath.abs(-1L);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100980 Assert.assertEquals(StrictMath.abs(0L), 0L);
981 Assert.assertEquals(StrictMath.abs(123L), 123L);
982 Assert.assertEquals(StrictMath.abs(-123L), 123L);
983 Assert.assertEquals(StrictMath.abs(Long.MAX_VALUE), Long.MAX_VALUE);
984 Assert.assertEquals(StrictMath.abs(Long.MIN_VALUE), Long.MIN_VALUE);
985 Assert.assertEquals(StrictMath.abs(Long.MIN_VALUE - 1), Long.MAX_VALUE);
986 }
987
Serban Constantinescu23abec92014-07-02 16:13:38 +0100988 public static void test_StrictMath_min_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800989 StrictMath.min(1, 0);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100990 Assert.assertEquals(StrictMath.min(0, 0), 0);
991 Assert.assertEquals(StrictMath.min(1, 0), 0);
992 Assert.assertEquals(StrictMath.min(0, 1), 0);
993 Assert.assertEquals(StrictMath.min(0, Integer.MAX_VALUE), 0);
994 Assert.assertEquals(StrictMath.min(Integer.MIN_VALUE, 0), Integer.MIN_VALUE);
995 Assert.assertEquals(StrictMath.min(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MIN_VALUE);
996 }
997
Serban Constantinescu23abec92014-07-02 16:13:38 +0100998 public static void test_StrictMath_max_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800999 StrictMath.max(1, 0);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +01001000 Assert.assertEquals(StrictMath.max(0, 0), 0);
1001 Assert.assertEquals(StrictMath.max(1, 0), 1);
1002 Assert.assertEquals(StrictMath.max(0, 1), 1);
1003 Assert.assertEquals(StrictMath.max(0, Integer.MAX_VALUE), Integer.MAX_VALUE);
1004 Assert.assertEquals(StrictMath.max(Integer.MIN_VALUE, 0), 0);
1005 Assert.assertEquals(StrictMath.max(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MAX_VALUE);
1006 }
1007
Serban Constantinescu23abec92014-07-02 16:13:38 +01001008 public static void test_StrictMath_min_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001009 StrictMath.min(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +01001010 Assert.assertEquals(StrictMath.min(0L, 0L), 0L);
1011 Assert.assertEquals(StrictMath.min(1L, 0L), 0L);
1012 Assert.assertEquals(StrictMath.min(0L, 1L), 0L);
1013 Assert.assertEquals(StrictMath.min(0L, Long.MAX_VALUE), 0L);
1014 Assert.assertEquals(StrictMath.min(Long.MIN_VALUE, 0L), Long.MIN_VALUE);
1015 Assert.assertEquals(StrictMath.min(Long.MIN_VALUE, Long.MAX_VALUE), Long.MIN_VALUE);
1016 }
1017
1018 public static void test_StrictMath_max_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001019 StrictMath.max(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +01001020 Assert.assertEquals(StrictMath.max(0L, 0L), 0L);
1021 Assert.assertEquals(StrictMath.max(1L, 0L), 1L);
1022 Assert.assertEquals(StrictMath.max(0L, 1L), 1L);
1023 Assert.assertEquals(StrictMath.max(0L, Long.MAX_VALUE), Long.MAX_VALUE);
1024 Assert.assertEquals(StrictMath.max(Long.MIN_VALUE, 0L), 0L);
1025 Assert.assertEquals(StrictMath.max(Long.MIN_VALUE, Long.MAX_VALUE), Long.MAX_VALUE);
1026 }
1027
1028 public static void test_StrictMath_min_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001029 StrictMath.min(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +07001030 Assert.assertTrue(Float.isNaN(StrictMath.min(1.0f, Float.NaN)));
1031 Assert.assertTrue(Float.isNaN(StrictMath.min(Float.NaN, 1.0f)));
1032 Assert.assertEquals(StrictMath.min(-0.0f, 0.0f), -0.0f);
1033 Assert.assertEquals(StrictMath.min(0.0f, -0.0f), -0.0f);
1034 Assert.assertEquals(StrictMath.min(-0.0f, -0.0f), -0.0f);
1035 Assert.assertEquals(StrictMath.min(0.0f, 0.0f), 0.0f);
1036 Assert.assertEquals(StrictMath.min(1.0f, 0.0f), 0.0f);
1037 Assert.assertEquals(StrictMath.min(0.0f, 1.0f), 0.0f);
1038 Assert.assertEquals(StrictMath.min(0.0f, Float.MAX_VALUE), 0.0f);
1039 Assert.assertEquals(StrictMath.min(Float.MIN_VALUE, 0.0f), 0.0f);
1040 Assert.assertEquals(StrictMath.min(Float.MIN_VALUE, Float.MAX_VALUE), Float.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +01001041 }
1042
1043 public static void test_StrictMath_max_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001044 StrictMath.max(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +07001045 Assert.assertTrue(Float.isNaN(StrictMath.max(1.0f, Float.NaN)));
1046 Assert.assertTrue(Float.isNaN(StrictMath.max(Float.NaN, 1.0f)));
1047 Assert.assertEquals(StrictMath.max(-0.0f, 0.0f), 0.0f);
1048 Assert.assertEquals(StrictMath.max(0.0f, -0.0f), 0.0f);
1049 Assert.assertEquals(StrictMath.max(-0.0f, -0.0f), -0.0f);
1050 Assert.assertEquals(StrictMath.max(0.0f, 0.0f), 0.0f);
1051 Assert.assertEquals(StrictMath.max(1.0f, 0.0f), 1.0f);
1052 Assert.assertEquals(StrictMath.max(0.0f, 1.0f), 1.0f);
1053 Assert.assertEquals(StrictMath.max(0.0f, Float.MAX_VALUE), Float.MAX_VALUE);
1054 Assert.assertEquals(StrictMath.max(Float.MIN_VALUE, 0.0f), Float.MIN_VALUE);
1055 Assert.assertEquals(StrictMath.max(Float.MIN_VALUE, Float.MAX_VALUE), Float.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +01001056 }
1057
1058 public static void test_StrictMath_min_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001059 StrictMath.min(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +07001060 Assert.assertTrue(Double.isNaN(StrictMath.min(1.0d, Double.NaN)));
1061 Assert.assertTrue(Double.isNaN(StrictMath.min(Double.NaN, 1.0d)));
1062 Assert.assertEquals(StrictMath.min(-0.0d, 0.0d), -0.0d);
1063 Assert.assertEquals(StrictMath.min(0.0d, -0.0d), -0.0d);
1064 Assert.assertEquals(StrictMath.min(-0.0d, -0.0d), -0.0d);
1065 Assert.assertEquals(StrictMath.min(0.0d, 0.0d), 0.0d);
1066 Assert.assertEquals(StrictMath.min(1.0d, 0.0d), 0.0d);
1067 Assert.assertEquals(StrictMath.min(0.0d, 1.0d), 0.0d);
1068 Assert.assertEquals(StrictMath.min(0.0d, Double.MAX_VALUE), 0.0d);
1069 Assert.assertEquals(StrictMath.min(Double.MIN_VALUE, 0.0d), 0.0d);
1070 Assert.assertEquals(StrictMath.min(Double.MIN_VALUE, Double.MAX_VALUE), Double.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +01001071 }
1072
1073 public static void test_StrictMath_max_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001074 StrictMath.max(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +07001075 Assert.assertTrue(Double.isNaN(StrictMath.max(1.0d, Double.NaN)));
1076 Assert.assertTrue(Double.isNaN(StrictMath.max(Double.NaN, 1.0d)));
1077 Assert.assertEquals(StrictMath.max(-0.0d, 0.0d), 0.0d);
1078 Assert.assertEquals(StrictMath.max(0.0d, -0.0d), 0.0d);
1079 Assert.assertEquals(StrictMath.max(-0.0d, -0.0d), -0.0d);
1080 Assert.assertEquals(StrictMath.max(0.0d, 0.0d), 0.0d);
1081 Assert.assertEquals(StrictMath.max(1.0d, 0.0d), 1.0d);
1082 Assert.assertEquals(StrictMath.max(0.0d, 1.0d), 1.0d);
1083 Assert.assertEquals(StrictMath.max(0.0d, Double.MAX_VALUE), Double.MAX_VALUE);
1084 Assert.assertEquals(StrictMath.max(Double.MIN_VALUE, 0.0d), Double.MIN_VALUE);
1085 Assert.assertEquals(StrictMath.max(Double.MIN_VALUE, Double.MAX_VALUE), Double.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +01001086 }
1087
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001088 public static void test_StrictMath_sqrt() {
1089 StrictMath.sqrt(+4.0);
1090 Assert.assertEquals(StrictMath.sqrt(+4.0), +2.0d, 0.0);
1091 Assert.assertEquals(StrictMath.sqrt(+49.0), +7.0d, 0.0);
1092 Assert.assertEquals(StrictMath.sqrt(+1.44), +1.2d, 0.0);
1093 }
1094
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +01001095 public static void test_StrictMath_ceil() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001096 StrictMath.ceil(-0.9);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +01001097 Assert.assertEquals(StrictMath.ceil(+0.0), +0.0d, 0.0);
1098 Assert.assertEquals(StrictMath.ceil(-0.0), -0.0d, 0.0);
1099 Assert.assertEquals(StrictMath.ceil(-0.9), -0.0d, 0.0);
1100 Assert.assertEquals(StrictMath.ceil(-0.5), -0.0d, 0.0);
1101 Assert.assertEquals(StrictMath.ceil(0.0), -0.0d, 0.0);
1102 Assert.assertEquals(StrictMath.ceil(+2.0), +2.0d, 0.0);
1103 Assert.assertEquals(StrictMath.ceil(+2.1), +3.0d, 0.0);
1104 Assert.assertEquals(StrictMath.ceil(+2.5), +3.0d, 0.0);
1105 Assert.assertEquals(StrictMath.ceil(+2.9), +3.0d, 0.0);
1106 Assert.assertEquals(StrictMath.ceil(+3.0), +3.0d, 0.0);
1107 Assert.assertEquals(StrictMath.ceil(-2.0), -2.0d, 0.0);
1108 Assert.assertEquals(StrictMath.ceil(-2.1), -2.0d, 0.0);
1109 Assert.assertEquals(StrictMath.ceil(-2.5), -2.0d, 0.0);
1110 Assert.assertEquals(StrictMath.ceil(-2.9), -2.0d, 0.0);
1111 Assert.assertEquals(StrictMath.ceil(-3.0), -3.0d, 0.0);
1112 Assert.assertEquals(StrictMath.ceil(Double.NaN), Double.NaN, 0.0);
1113 Assert.assertEquals(StrictMath.ceil(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
1114 Assert.assertEquals(StrictMath.ceil(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
1115 }
1116
1117 public static void test_StrictMath_floor() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001118 StrictMath.floor(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +01001119 Assert.assertEquals(StrictMath.floor(+0.0), +0.0d, 0.0);
1120 Assert.assertEquals(StrictMath.floor(-0.0), -0.0d, 0.0);
1121 Assert.assertEquals(StrictMath.floor(+2.0), +2.0d, 0.0);
1122 Assert.assertEquals(StrictMath.floor(+2.1), +2.0d, 0.0);
1123 Assert.assertEquals(StrictMath.floor(+2.5), +2.0d, 0.0);
1124 Assert.assertEquals(StrictMath.floor(+2.9), +2.0d, 0.0);
1125 Assert.assertEquals(StrictMath.floor(+3.0), +3.0d, 0.0);
1126 Assert.assertEquals(StrictMath.floor(-2.0), -2.0d, 0.0);
1127 Assert.assertEquals(StrictMath.floor(-2.1), -3.0d, 0.0);
1128 Assert.assertEquals(StrictMath.floor(-2.5), -3.0d, 0.0);
1129 Assert.assertEquals(StrictMath.floor(-2.9), -3.0d, 0.0);
1130 Assert.assertEquals(StrictMath.floor(-3.0), -3.0d, 0.0);
1131 Assert.assertEquals(StrictMath.floor(Double.NaN), Double.NaN, 0.0);
1132 Assert.assertEquals(StrictMath.floor(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
1133 Assert.assertEquals(StrictMath.floor(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
1134 }
1135
1136 public static void test_StrictMath_rint() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001137 StrictMath.rint(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +01001138 Assert.assertEquals(StrictMath.rint(+0.0), +0.0d, 0.0);
1139 Assert.assertEquals(StrictMath.rint(-0.0), -0.0d, 0.0);
1140 Assert.assertEquals(StrictMath.rint(+2.0), +2.0d, 0.0);
1141 Assert.assertEquals(StrictMath.rint(+2.1), +2.0d, 0.0);
1142 Assert.assertEquals(StrictMath.rint(+2.5), +2.0d, 0.0);
1143 Assert.assertEquals(StrictMath.rint(+2.9), +3.0d, 0.0);
1144 Assert.assertEquals(StrictMath.rint(+3.0), +3.0d, 0.0);
1145 Assert.assertEquals(StrictMath.rint(-2.0), -2.0d, 0.0);
1146 Assert.assertEquals(StrictMath.rint(-2.1), -2.0d, 0.0);
1147 Assert.assertEquals(StrictMath.rint(-2.5), -2.0d, 0.0);
1148 Assert.assertEquals(StrictMath.rint(-2.9), -3.0d, 0.0);
1149 Assert.assertEquals(StrictMath.rint(-3.0), -3.0d, 0.0);
1150 Assert.assertEquals(StrictMath.rint(Double.NaN), Double.NaN, 0.0);
1151 Assert.assertEquals(StrictMath.rint(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
1152 Assert.assertEquals(StrictMath.rint(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
1153 }
1154
1155 public static void test_StrictMath_round_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001156 StrictMath.round(2.1d);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +01001157 Assert.assertEquals(StrictMath.round(+0.0d), (long)+0.0);
1158 Assert.assertEquals(StrictMath.round(-0.0d), (long)+0.0);
1159 Assert.assertEquals(StrictMath.round(2.0d), 2l);
1160 Assert.assertEquals(StrictMath.round(2.1d), 2l);
1161 Assert.assertEquals(StrictMath.round(2.5d), 3l);
1162 Assert.assertEquals(StrictMath.round(2.9d), 3l);
1163 Assert.assertEquals(StrictMath.round(3.0d), 3l);
1164 Assert.assertEquals(StrictMath.round(-2.0d), -2l);
1165 Assert.assertEquals(StrictMath.round(-2.1d), -2l);
1166 Assert.assertEquals(StrictMath.round(-2.5d), -2l);
1167 Assert.assertEquals(StrictMath.round(-2.9d), -3l);
1168 Assert.assertEquals(StrictMath.round(-3.0d), -3l);
Yi Kong879ca672015-11-18 14:11:44 +00001169 Assert.assertEquals(StrictMath.round(0.49999999999999994d), 0l);
Chris Larsen7adaab02016-04-21 14:49:20 -07001170 Assert.assertEquals(StrictMath.round(4503599627370495.0d), 4503599627370495l); // 2^52 - 1
1171 Assert.assertEquals(StrictMath.round(4503599627370495.5d), 4503599627370496l); // 2^52 - 0.5
1172 Assert.assertEquals(StrictMath.round(4503599627370496.0d), 4503599627370496l); // 2^52
1173 Assert.assertEquals(StrictMath.round(-4503599627370495.0d), -4503599627370495l); // -(2^52 - 1)
1174 Assert.assertEquals(StrictMath.round(-4503599627370495.5d), -4503599627370495l); // -(2^52 - 0.5)
1175 Assert.assertEquals(StrictMath.round(-4503599627370496.0d), -4503599627370496l); // -2^52
Vladimir Marko9c1c06a2016-02-25 17:50:41 +00001176 Assert.assertEquals(StrictMath.round(9007199254740991.0d), 9007199254740991l); // 2^53 - 1
Chris Larsenf09d5322016-04-22 12:06:34 -07001177 Assert.assertEquals(StrictMath.round(-9007199254740991.0d), -9007199254740991l); // -(2^53 - 1)
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +01001178 Assert.assertEquals(StrictMath.round(Double.NaN), (long)+0.0d);
1179 Assert.assertEquals(StrictMath.round(Long.MAX_VALUE + 1.0d), Long.MAX_VALUE);
1180 Assert.assertEquals(StrictMath.round(Long.MIN_VALUE - 1.0d), Long.MIN_VALUE);
Chris Larsen7adaab02016-04-21 14:49:20 -07001181 Assert.assertEquals(StrictMath.round(Double.longBitsToDouble(0x43F0000000000000l)),
1182 Long.MAX_VALUE); // 2^64
1183 Assert.assertEquals(StrictMath.round(Double.longBitsToDouble(0xC3F0000000000000l)),
1184 Long.MIN_VALUE); // -2^64
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +01001185 Assert.assertEquals(StrictMath.round(Double.POSITIVE_INFINITY), Long.MAX_VALUE);
1186 Assert.assertEquals(StrictMath.round(Double.NEGATIVE_INFINITY), Long.MIN_VALUE);
1187 }
1188
1189 public static void test_StrictMath_round_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001190 StrictMath.round(2.1f);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +01001191 Assert.assertEquals(StrictMath.round(+0.0f), (int)+0.0);
1192 Assert.assertEquals(StrictMath.round(-0.0f), (int)+0.0);
1193 Assert.assertEquals(StrictMath.round(2.0f), 2);
1194 Assert.assertEquals(StrictMath.round(2.1f), 2);
1195 Assert.assertEquals(StrictMath.round(2.5f), 3);
1196 Assert.assertEquals(StrictMath.round(2.9f), 3);
1197 Assert.assertEquals(StrictMath.round(3.0f), 3);
1198 Assert.assertEquals(StrictMath.round(-2.0f), -2);
1199 Assert.assertEquals(StrictMath.round(-2.1f), -2);
1200 Assert.assertEquals(StrictMath.round(-2.5f), -2);
1201 Assert.assertEquals(StrictMath.round(-2.9f), -3);
1202 Assert.assertEquals(StrictMath.round(-3.0f), -3);
Chris Larsenb74353a2015-11-20 09:07:09 -08001203 // 0.4999999701976776123046875
1204 Assert.assertEquals(StrictMath.round(Float.intBitsToFloat(0x3EFFFFFF)), (int)+0.0f);
Chris Larsenf09d5322016-04-22 12:06:34 -07001205 Assert.assertEquals(StrictMath.round(8388607.0f), 8388607); // 2^23 - 1
1206 Assert.assertEquals(StrictMath.round(8388607.5f), 8388608); // 2^23 - 0.5
1207 Assert.assertEquals(StrictMath.round(8388608.0f), 8388608); // 2^23
1208 Assert.assertEquals(StrictMath.round(-8388607.0f), -8388607); // -(2^23 - 1)
1209 Assert.assertEquals(StrictMath.round(-8388607.5f), -8388607); // -(2^23 - 0.5)
1210 Assert.assertEquals(StrictMath.round(-8388608.0f), -8388608); // -2^23
Vladimir Marko9c1c06a2016-02-25 17:50:41 +00001211 Assert.assertEquals(StrictMath.round(16777215.0f), 16777215); // 2^24 - 1
Chris Larsenf09d5322016-04-22 12:06:34 -07001212 Assert.assertEquals(StrictMath.round(16777216.0f), 16777216); // 2^24
1213 Assert.assertEquals(StrictMath.round(-16777215.0f), -16777215); // -(2^24 - 1)
1214 Assert.assertEquals(StrictMath.round(-16777216.0f), -16777216); // -2^24
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +01001215 Assert.assertEquals(StrictMath.round(Float.NaN), (int)+0.0f);
1216 Assert.assertEquals(StrictMath.round(Integer.MAX_VALUE + 1.0f), Integer.MAX_VALUE);
1217 Assert.assertEquals(StrictMath.round(Integer.MIN_VALUE - 1.0f), Integer.MIN_VALUE);
Chris Larsen7adaab02016-04-21 14:49:20 -07001218 Assert.assertEquals(StrictMath.round(Float.intBitsToFloat(0x4F800000)),
1219 Integer.MAX_VALUE); // 2^32
1220 Assert.assertEquals(StrictMath.round(Float.intBitsToFloat(0xCF800000)),
1221 Integer.MIN_VALUE); // -2^32
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +01001222 Assert.assertEquals(StrictMath.round(Float.POSITIVE_INFINITY), Integer.MAX_VALUE);
1223 Assert.assertEquals(StrictMath.round(Float.NEGATIVE_INFINITY), Integer.MIN_VALUE);
1224 }
1225
Elliott Hughes28c384b2012-06-15 16:46:25 -07001226 public static void test_Float_floatToRawIntBits() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001227 Float.floatToRawIntBits(-1.0f);
Elliott Hughes28c384b2012-06-15 16:46:25 -07001228 Assert.assertEquals(Float.floatToRawIntBits(-1.0f), 0xbf800000);
1229 Assert.assertEquals(Float.floatToRawIntBits(0.0f), 0);
1230 Assert.assertEquals(Float.floatToRawIntBits(1.0f), 0x3f800000);
1231 Assert.assertEquals(Float.floatToRawIntBits(Float.NaN), 0x7fc00000);
1232 Assert.assertEquals(Float.floatToRawIntBits(Float.POSITIVE_INFINITY), 0x7f800000);
1233 Assert.assertEquals(Float.floatToRawIntBits(Float.NEGATIVE_INFINITY), 0xff800000);
1234 }
1235
1236 public static void test_Float_intBitsToFloat() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001237 Float.intBitsToFloat(0xbf800000);
Elliott Hughes28c384b2012-06-15 16:46:25 -07001238 Assert.assertEquals(Float.intBitsToFloat(0xbf800000), -1.0f);
1239 Assert.assertEquals(Float.intBitsToFloat(0x00000000), 0.0f);
1240 Assert.assertEquals(Float.intBitsToFloat(0x3f800000), 1.0f);
1241 Assert.assertEquals(Float.intBitsToFloat(0x7fc00000), Float.NaN);
1242 Assert.assertEquals(Float.intBitsToFloat(0x7f800000), Float.POSITIVE_INFINITY);
1243 Assert.assertEquals(Float.intBitsToFloat(0xff800000), Float.NEGATIVE_INFINITY);
1244 }
1245
1246 public static void test_Double_doubleToRawLongBits() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001247 Double.doubleToRawLongBits(-1.0);
Elliott Hughes28c384b2012-06-15 16:46:25 -07001248 Assert.assertEquals(Double.doubleToRawLongBits(-1.0), 0xbff0000000000000L);
1249 Assert.assertEquals(Double.doubleToRawLongBits(0.0), 0x0000000000000000L);
1250 Assert.assertEquals(Double.doubleToRawLongBits(1.0), 0x3ff0000000000000L);
1251 Assert.assertEquals(Double.doubleToRawLongBits(Double.NaN), 0x7ff8000000000000L);
1252 Assert.assertEquals(Double.doubleToRawLongBits(Double.POSITIVE_INFINITY), 0x7ff0000000000000L);
1253 Assert.assertEquals(Double.doubleToRawLongBits(Double.NEGATIVE_INFINITY), 0xfff0000000000000L);
1254 }
1255
1256 public static void test_Double_longBitsToDouble() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001257 Double.longBitsToDouble(0xbff0000000000000L);
Elliott Hughes28c384b2012-06-15 16:46:25 -07001258 Assert.assertEquals(Double.longBitsToDouble(0xbff0000000000000L), -1.0);
1259 Assert.assertEquals(Double.longBitsToDouble(0x0000000000000000L), 0.0);
1260 Assert.assertEquals(Double.longBitsToDouble(0x3ff0000000000000L), 1.0);
1261 Assert.assertEquals(Double.longBitsToDouble(0x7ff8000000000000L), Double.NaN);
1262 Assert.assertEquals(Double.longBitsToDouble(0x7ff0000000000000L), Double.POSITIVE_INFINITY);
1263 Assert.assertEquals(Double.longBitsToDouble(0xfff0000000000000L), Double.NEGATIVE_INFINITY);
1264 }
Serban Constantinescu23abec92014-07-02 16:13:38 +01001265
Zheng Xua3fe7422014-07-09 14:03:15 +08001266 public static void test_Short_reverseBytes() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001267 Short.reverseBytes((short)0x1357);
Zheng Xua3fe7422014-07-09 14:03:15 +08001268 Assert.assertEquals(Short.reverseBytes((short)0x0000), (short)0x0000);
1269 Assert.assertEquals(Short.reverseBytes((short)0xffff), (short)0xffff);
1270 Assert.assertEquals(Short.reverseBytes((short)0x8000), (short)0x0080);
1271 Assert.assertEquals(Short.reverseBytes((short)0x0080), (short)0x8000);
1272 Assert.assertEquals(Short.reverseBytes((short)0x0123), (short)0x2301);
1273 Assert.assertEquals(Short.reverseBytes((short)0x4567), (short)0x6745);
1274 Assert.assertEquals(Short.reverseBytes((short)0x89ab), (short)0xab89);
1275 Assert.assertEquals(Short.reverseBytes((short)0xcdef), (short)0xefcd);
1276 }
1277
1278 public static void test_Integer_reverseBytes() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001279 Integer.reverseBytes(0x13579bdf);
Zheng Xua3fe7422014-07-09 14:03:15 +08001280 Assert.assertEquals(Integer.reverseBytes(0x00000000), 0x00000000);
1281 Assert.assertEquals(Integer.reverseBytes(0xffffffff), 0xffffffff);
1282 Assert.assertEquals(Integer.reverseBytes(0x80000000), 0x00000080);
1283 Assert.assertEquals(Integer.reverseBytes(0x00000080), 0x80000000);
1284 Assert.assertEquals(Integer.reverseBytes(0x01234567), 0x67452301);
1285 Assert.assertEquals(Integer.reverseBytes(0x89abcdef), 0xefcdab89);
1286 }
1287
1288 public static void test_Long_reverseBytes() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001289 Long.reverseBytes(0x13579bdf2468ace0L);
Zheng Xua3fe7422014-07-09 14:03:15 +08001290 Assert.assertEquals(Long.reverseBytes(0x0000000000000000L), 0x0000000000000000L);
1291 Assert.assertEquals(Long.reverseBytes(0xffffffffffffffffL), 0xffffffffffffffffL);
1292 Assert.assertEquals(Long.reverseBytes(0x8000000000000000L), 0x0000000000000080L);
1293 Assert.assertEquals(Long.reverseBytes(0x0000000000000080L), 0x8000000000000000L);
1294 Assert.assertEquals(Long.reverseBytes(0x0123456789abcdefL), 0xefcdab8967452301L);
1295 }
1296
Serban Constantinescu23abec92014-07-02 16:13:38 +01001297 public static void test_Integer_reverse() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001298 Integer.reverse(0x12345678);
Serban Constantinescu23abec92014-07-02 16:13:38 +01001299 Assert.assertEquals(Integer.reverse(1), 0x80000000);
1300 Assert.assertEquals(Integer.reverse(-1), 0xffffffff);
1301 Assert.assertEquals(Integer.reverse(0), 0);
1302 Assert.assertEquals(Integer.reverse(0x12345678), 0x1e6a2c48);
1303 Assert.assertEquals(Integer.reverse(0x87654321), 0x84c2a6e1);
1304 Assert.assertEquals(Integer.reverse(Integer.MAX_VALUE), 0xfffffffe);
1305 Assert.assertEquals(Integer.reverse(Integer.MIN_VALUE), 1);
1306 }
1307
1308 public static void test_Long_reverse() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001309 Long.reverse(0x1234567812345678L);
Serban Constantinescu23abec92014-07-02 16:13:38 +01001310 Assert.assertEquals(Long.reverse(1L), 0x8000000000000000L);
1311 Assert.assertEquals(Long.reverse(-1L), 0xffffffffffffffffL);
1312 Assert.assertEquals(Long.reverse(0L), 0L);
Zheng Xua3fe7422014-07-09 14:03:15 +08001313 Assert.assertEquals(Long.reverse(0x1234567812345678L), 0x1e6a2c481e6a2c48L);
1314 Assert.assertEquals(Long.reverse(0x8765432187654321L), 0x84c2a6e184c2a6e1L);
1315 Assert.assertEquals(Long.reverse(Long.MAX_VALUE), 0xfffffffffffffffeL);
Serban Constantinescu23abec92014-07-02 16:13:38 +01001316 Assert.assertEquals(Long.reverse(Long.MIN_VALUE), 1L);
Andreas Gampe575422f2015-07-07 13:25:58 -07001317
1318 Assert.assertEquals(test_Long_reverse_b22324327(0xaaaaaaaaaaaaaaaaL, 0x5555555555555555L),
1319 157472205507277347L);
1320 }
1321
1322 // A bit more complicated than the above. Use local variables to stress register allocation.
1323 private static long test_Long_reverse_b22324327(long l1, long l2) {
1324 // A couple of local integers. Use them in a loop, so they get promoted.
1325 int i1 = 0, i2 = 1, i3 = 2, i4 = 3, i5 = 4, i6 = 5, i7 = 6, i8 = 7;
1326 for (int k = 0; k < 10; k++) {
1327 i1 += 1;
1328 i2 += 2;
1329 i3 += 3;
1330 i4 += 4;
1331 i5 += 5;
1332 i6 += 6;
1333 i7 += 7;
1334 i8 += 8;
1335 }
1336
1337 // Do the Long.reverse() calls, save the results.
1338 long r1 = Long.reverse(l1);
1339 long r2 = Long.reverse(l2);
1340
1341 // Some more looping with the ints.
1342 for (int k = 0; k < 10; k++) {
1343 i1 += 1;
1344 i2 += 2;
1345 i3 += 3;
1346 i4 += 4;
1347 i5 += 5;
1348 i6 += 6;
1349 i7 += 7;
1350 i8 += 8;
1351 }
1352
1353 // Include everything in the result, so things are kept live. Try to be a little bit clever to
1354 // avoid things being folded somewhere.
1355 return (r1 / i1) + (r2 / i2) + i3 + i4 + i5 + i6 + i7 + i8;
Serban Constantinescu23abec92014-07-02 16:13:38 +01001356 }
1357
Mark Mendelld5897672015-08-12 21:16:41 -04001358 public static boolean doThrow = false;
1359
1360 public static int $noinline$return_int_zero() {
1361 if (doThrow) {
1362 throw new Error();
1363 }
1364 return 0;
1365 }
1366
Scott Wakeling611d3392015-07-10 11:42:06 +01001367 public static void test_Integer_numberOfLeadingZeros() {
1368 Assert.assertEquals(Integer.numberOfLeadingZeros(0), Integer.SIZE);
Mark Mendelld5897672015-08-12 21:16:41 -04001369 Assert.assertEquals(Integer.numberOfLeadingZeros(1), Integer.SIZE - 1);
1370 Assert.assertEquals(Integer.numberOfLeadingZeros(1 << (Integer.SIZE-1)), 0);
1371 Assert.assertEquals(Integer.numberOfLeadingZeros($noinline$return_int_zero()), Integer.SIZE);
Scott Wakeling611d3392015-07-10 11:42:06 +01001372 for (int i = 0; i < Integer.SIZE; i++) {
1373 Assert.assertEquals(Integer.numberOfLeadingZeros(1 << i), Integer.SIZE - 1 - i);
1374 Assert.assertEquals(Integer.numberOfLeadingZeros((1 << i) | 1), Integer.SIZE - 1 - i);
1375 Assert.assertEquals(Integer.numberOfLeadingZeros(0xFFFFFFFF >>> i), i);
1376 }
1377 }
1378
Mark Mendelld5897672015-08-12 21:16:41 -04001379 public static long $noinline$return_long_zero() {
1380 if (doThrow) {
1381 throw new Error();
1382 }
1383 return 0;
1384 }
1385
Scott Wakeling611d3392015-07-10 11:42:06 +01001386 public static void test_Long_numberOfLeadingZeros() {
1387 Assert.assertEquals(Long.numberOfLeadingZeros(0L), Long.SIZE);
Mark Mendelld5897672015-08-12 21:16:41 -04001388 Assert.assertEquals(Long.numberOfLeadingZeros(1L), Long.SIZE - 1);
1389 Assert.assertEquals(Long.numberOfLeadingZeros(1L << ((Long.SIZE/2)-1)), Long.SIZE/2);
1390 Assert.assertEquals(Long.numberOfLeadingZeros(1L << (Long.SIZE-1)), 0);
1391 Assert.assertEquals(Long.numberOfLeadingZeros($noinline$return_long_zero()), Long.SIZE);
Scott Wakeling611d3392015-07-10 11:42:06 +01001392 for (int i = 0; i < Long.SIZE; i++) {
1393 Assert.assertEquals(Long.numberOfLeadingZeros(1L << i), Long.SIZE - 1 - i);
1394 Assert.assertEquals(Long.numberOfLeadingZeros((1L << i) | 1L), Long.SIZE - 1 - i);
1395 Assert.assertEquals(Long.numberOfLeadingZeros(0xFFFFFFFFFFFFFFFFL >>> i), i);
1396 }
1397 }
1398
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001399 static Object runtime;
1400 static Method address_of;
Zuo Wangf37a88b2014-07-10 04:26:41 -07001401 static Method new_non_movable_array;
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001402 static Method peek_byte;
1403 static Method peek_short;
1404 static Method peek_int;
1405 static Method peek_long;
1406 static Method poke_byte;
1407 static Method poke_short;
1408 static Method poke_int;
1409 static Method poke_long;
1410
1411 public static void initSupportMethodsForPeekPoke() throws Exception {
1412 Class<?> vm_runtime = Class.forName("dalvik.system.VMRuntime");
1413 Method get_runtime = vm_runtime.getDeclaredMethod("getRuntime");
1414 runtime = get_runtime.invoke(null);
1415 address_of = vm_runtime.getDeclaredMethod("addressOf", Object.class);
Zuo Wangf37a88b2014-07-10 04:26:41 -07001416 new_non_movable_array = vm_runtime.getDeclaredMethod("newNonMovableArray", Class.class, Integer.TYPE);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001417
1418 Class<?> io_memory = Class.forName("libcore.io.Memory");
1419 peek_byte = io_memory.getDeclaredMethod("peekByte", Long.TYPE);
1420 peek_int = io_memory.getDeclaredMethod("peekInt", Long.TYPE, Boolean.TYPE);
1421 peek_short = io_memory.getDeclaredMethod("peekShort", Long.TYPE, Boolean.TYPE);
1422 peek_long = io_memory.getDeclaredMethod("peekLong", Long.TYPE, Boolean.TYPE);
1423 poke_byte = io_memory.getDeclaredMethod("pokeByte", Long.TYPE, Byte.TYPE);
1424 poke_short = io_memory.getDeclaredMethod("pokeShort", Long.TYPE, Short.TYPE, Boolean.TYPE);
1425 poke_int = io_memory.getDeclaredMethod("pokeInt", Long.TYPE, Integer.TYPE, Boolean.TYPE);
1426 poke_long = io_memory.getDeclaredMethod("pokeLong", Long.TYPE, Long.TYPE, Boolean.TYPE);
1427 }
1428
1429 public static void test_Memory_peekByte() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -07001430 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 2);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001431 b[0] = 0x12;
1432 b[1] = 0x11;
1433 long address = (long)address_of.invoke(runtime, b);
1434 Assert.assertEquals((byte)peek_byte.invoke(null, address), 0x12);
1435 Assert.assertEquals((byte)peek_byte.invoke(null, address + 1), 0x11);
1436 }
1437
1438 public static void test_Memory_peekShort() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -07001439 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 3);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001440 b[0] = 0x13;
1441 b[1] = 0x12;
1442 b[2] = 0x11;
1443 long address = (long)address_of.invoke(runtime, b);
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001444 peek_short.invoke(null, address, false);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001445 Assert.assertEquals((short)peek_short.invoke(null, address, false), 0x1213); // Aligned read
1446 Assert.assertEquals((short)peek_short.invoke(null, address + 1, false), 0x1112); // Unaligned read
1447 }
1448
1449 public static void test_Memory_peekInt() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -07001450 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 5);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001451 b[0] = 0x15;
1452 b[1] = 0x14;
1453 b[2] = 0x13;
1454 b[3] = 0x12;
1455 b[4] = 0x11;
1456 long address = (long)address_of.invoke(runtime, b);
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001457 peek_int.invoke(null, address, false);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001458 Assert.assertEquals((int)peek_int.invoke(null, address, false), 0x12131415);
1459 Assert.assertEquals((int)peek_int.invoke(null, address + 1, false), 0x11121314);
1460 }
1461
1462 public static void test_Memory_peekLong() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -07001463 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 9);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001464 b[0] = 0x19;
1465 b[1] = 0x18;
1466 b[2] = 0x17;
1467 b[3] = 0x16;
1468 b[4] = 0x15;
1469 b[5] = 0x14;
1470 b[6] = 0x13;
1471 b[7] = 0x12;
1472 b[8] = 0x11;
1473 long address = (long)address_of.invoke(runtime, b);
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001474 peek_long.invoke(null, address, false);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001475 Assert.assertEquals((long)peek_long.invoke(null, address, false), 0x1213141516171819L);
1476 Assert.assertEquals((long)peek_long.invoke(null, address + 1, false), 0x1112131415161718L);
1477 }
1478
1479 public static void test_Memory_pokeByte() throws Exception {
1480 byte[] r = {0x11, 0x12};
Zuo Wangf37a88b2014-07-10 04:26:41 -07001481 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 2);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001482 long address = (long)address_of.invoke(runtime, b);
1483 poke_byte.invoke(null, address, (byte)0x11);
1484 poke_byte.invoke(null, address + 1, (byte)0x12);
1485 Assert.assertTrue(Arrays.equals(r, b));
1486 }
1487
1488 public static void test_Memory_pokeShort() throws Exception {
1489 byte[] ra = {0x12, 0x11, 0x13};
1490 byte[] ru = {0x12, 0x22, 0x21};
Zuo Wangf37a88b2014-07-10 04:26:41 -07001491 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 3);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001492 long address = (long)address_of.invoke(runtime, b);
1493
1494 // Aligned write
1495 b[2] = 0x13;
1496 poke_short.invoke(null, address, (short)0x1112, false);
1497 Assert.assertTrue(Arrays.equals(ra, b));
1498
1499 // Unaligned write
1500 poke_short.invoke(null, address + 1, (short)0x2122, false);
1501 Assert.assertTrue(Arrays.equals(ru, b));
1502 }
1503
1504 public static void test_Memory_pokeInt() throws Exception {
1505 byte[] ra = {0x14, 0x13, 0x12, 0x11, 0x15};
1506 byte[] ru = {0x14, 0x24, 0x23, 0x22, 0x21};
Zuo Wangf37a88b2014-07-10 04:26:41 -07001507 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 5);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001508 long address = (long)address_of.invoke(runtime, b);
1509
1510 b[4] = 0x15;
1511 poke_int.invoke(null, address, (int)0x11121314, false);
1512 Assert.assertTrue(Arrays.equals(ra, b));
1513
1514 poke_int.invoke(null, address + 1, (int)0x21222324, false);
1515 Assert.assertTrue(Arrays.equals(ru, b));
1516 }
1517
1518 public static void test_Memory_pokeLong() throws Exception {
1519 byte[] ra = {0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x19};
1520 byte[] ru = {0x18, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21};
Zuo Wangf37a88b2014-07-10 04:26:41 -07001521 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 9);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001522 long address = (long)address_of.invoke(runtime, b);
1523
1524 b[8] = 0x19;
1525 poke_long.invoke(null, address, (long)0x1112131415161718L, false);
1526 Assert.assertTrue(Arrays.equals(ra, b));
1527
1528 poke_long.invoke(null, address + 1, (long)0x2122232425262728L, false);
1529 Assert.assertTrue(Arrays.equals(ru, b));
1530 }
Scott Wakeling9ee23f42015-07-23 10:44:35 +01001531
1532 public static void test_Integer_numberOfTrailingZeros() {
1533 Assert.assertEquals(Integer.numberOfTrailingZeros(0), Integer.SIZE);
1534 for (int i = 0; i < Integer.SIZE; i++) {
1535 Assert.assertEquals(
1536 Integer.numberOfTrailingZeros(0x80000000 >> i),
1537 Integer.SIZE - 1 - i);
1538 Assert.assertEquals(
1539 Integer.numberOfTrailingZeros((0x80000000 >> i) | 0x80000000),
1540 Integer.SIZE - 1 - i);
1541 Assert.assertEquals(Integer.numberOfTrailingZeros(1 << i), i);
1542 }
1543 }
1544
1545 public static void test_Long_numberOfTrailingZeros() {
1546 Assert.assertEquals(Long.numberOfTrailingZeros(0), Long.SIZE);
1547 for (int i = 0; i < Long.SIZE; i++) {
1548 Assert.assertEquals(
1549 Long.numberOfTrailingZeros(0x8000000000000000L >> i),
1550 Long.SIZE - 1 - i);
1551 Assert.assertEquals(
1552 Long.numberOfTrailingZeros((0x8000000000000000L >> i) | 0x8000000000000000L),
1553 Long.SIZE - 1 - i);
1554 Assert.assertEquals(Long.numberOfTrailingZeros(1L << i), i);
1555 }
1556 }
1557
1558 public static void test_Integer_rotateRight() throws Exception {
1559 Assert.assertEquals(Integer.rotateRight(0x11, 0), 0x11);
1560
1561 Assert.assertEquals(Integer.rotateRight(0x11, 1), 0x80000008);
1562 Assert.assertEquals(Integer.rotateRight(0x11, Integer.SIZE - 1), 0x22);
1563 Assert.assertEquals(Integer.rotateRight(0x11, Integer.SIZE), 0x11);
1564 Assert.assertEquals(Integer.rotateRight(0x11, Integer.SIZE + 1), 0x80000008);
1565
1566 Assert.assertEquals(Integer.rotateRight(0x11, -1), 0x22);
1567 Assert.assertEquals(Integer.rotateRight(0x11, -(Integer.SIZE - 1)), 0x80000008);
1568 Assert.assertEquals(Integer.rotateRight(0x11, -Integer.SIZE), 0x11);
1569 Assert.assertEquals(Integer.rotateRight(0x11, -(Integer.SIZE + 1)), 0x22);
1570
1571 Assert.assertEquals(Integer.rotateRight(0x80000000, 1), 0x40000000);
1572
1573 for (int i = 0; i < Integer.SIZE; i++) {
1574 Assert.assertEquals(
1575 Integer.rotateRight(0xBBAAAADD, i),
1576 (0xBBAAAADD >>> i) | (0xBBAAAADD << (Integer.SIZE - i)));
1577 }
1578 }
1579
1580 public static void test_Long_rotateRight() throws Exception {
1581 Assert.assertEquals(Long.rotateRight(0x11, 0), 0x11);
1582
1583 Assert.assertEquals(Long.rotateRight(0x11, 1), 0x8000000000000008L);
1584 Assert.assertEquals(Long.rotateRight(0x11, Long.SIZE - 1), 0x22);
1585 Assert.assertEquals(Long.rotateRight(0x11, Long.SIZE), 0x11);
1586 Assert.assertEquals(Long.rotateRight(0x11, Long.SIZE + 1), 0x8000000000000008L);
1587
1588 Assert.assertEquals(Long.rotateRight(0x11, -1), 0x22);
1589 Assert.assertEquals(Long.rotateRight(0x11, -(Long.SIZE - 1)), 0x8000000000000008L);
1590 Assert.assertEquals(Long.rotateRight(0x11, -Long.SIZE), 0x11);
1591 Assert.assertEquals(Long.rotateRight(0x11, -(Long.SIZE + 1)), 0x22);
1592
1593 Assert.assertEquals(Long.rotateRight(0x8000000000000000L, 1), 0x4000000000000000L);
1594
1595 for (int i = 0; i < Long.SIZE; i++) {
1596 Assert.assertEquals(
1597 Long.rotateRight(0xBBAAAADDFF0000DDL, i),
1598 (0xBBAAAADDFF0000DDL >>> i) | (0xBBAAAADDFF0000DDL << (Long.SIZE - i)));
1599 }
1600 }
1601
1602 public static void test_Integer_rotateLeft() throws Exception {
1603 Assert.assertEquals(Integer.rotateLeft(0x11, 0), 0x11);
1604
1605 Assert.assertEquals(Integer.rotateLeft(0x11, 1), 0x22);
1606 Assert.assertEquals(Integer.rotateLeft(0x11, Integer.SIZE - 1), 0x80000008);
1607 Assert.assertEquals(Integer.rotateLeft(0x11, Integer.SIZE), 0x11);
1608 Assert.assertEquals(Integer.rotateLeft(0x11, Integer.SIZE + 1), 0x22);
1609
1610 Assert.assertEquals(Integer.rotateLeft(0x11, -1), 0x80000008);
1611 Assert.assertEquals(Integer.rotateLeft(0x11, -(Integer.SIZE - 1)), 0x22);
1612 Assert.assertEquals(Integer.rotateLeft(0x11, -Integer.SIZE), 0x11);
1613 Assert.assertEquals(Integer.rotateLeft(0x11, -(Integer.SIZE + 1)), 0x80000008);
1614
1615 Assert.assertEquals(Integer.rotateLeft(0xC0000000, 1), 0x80000001);
1616
1617 for (int i = 0; i < Integer.SIZE; i++) {
1618 Assert.assertEquals(
1619 Integer.rotateLeft(0xBBAAAADD, i),
1620 (0xBBAAAADD << i) | (0xBBAAAADD >>> (Integer.SIZE - i)));
1621 }
1622 }
1623
1624 public static void test_Long_rotateLeft() throws Exception {
1625 Assert.assertEquals(Long.rotateLeft(0x11, 0), 0x11);
1626
1627 Assert.assertEquals(Long.rotateLeft(0x11, 1), 0x22);
1628 Assert.assertEquals(Long.rotateLeft(0x11, Long.SIZE - 1), 0x8000000000000008L);
1629 Assert.assertEquals(Long.rotateLeft(0x11, Long.SIZE), 0x11);
1630 Assert.assertEquals(Long.rotateLeft(0x11, Long.SIZE + 1), 0x22);
1631
1632 Assert.assertEquals(Long.rotateLeft(0x11, -1), 0x8000000000000008L);
1633 Assert.assertEquals(Long.rotateLeft(0x11, -(Long.SIZE - 1)), 0x22);
1634 Assert.assertEquals(Long.rotateLeft(0x11, -Long.SIZE), 0x11);
1635 Assert.assertEquals(Long.rotateLeft(0x11, -(Long.SIZE + 1)), 0x8000000000000008L);
1636
1637 Assert.assertEquals(Long.rotateLeft(0xC000000000000000L, 1), 0x8000000000000001L);
1638
1639 for (int i = 0; i < Long.SIZE; i++) {
1640 Assert.assertEquals(
1641 Long.rotateLeft(0xBBAAAADDFF0000DDL, i),
1642 (0xBBAAAADDFF0000DDL << i) | (0xBBAAAADDFF0000DDL >>> (Long.SIZE - i)));
1643 }
1644 }
1645
1646 public static void test_Integer_rotateRightLeft() throws Exception {
1647 for (int i = 0; i < Integer.SIZE * 2; i++) {
1648 Assert.assertEquals(Integer.rotateLeft(0xBBAAAADD, i),
1649 Integer.rotateRight(0xBBAAAADD, -i));
1650 Assert.assertEquals(Integer.rotateLeft(0xBBAAAADD, -i),
1651 Integer.rotateRight(0xBBAAAADD, i));
1652 }
1653 }
1654
1655 public static void test_Long_rotateRightLeft() throws Exception {
1656 for (int i = 0; i < Long.SIZE * 2; i++) {
1657 Assert.assertEquals(Long.rotateLeft(0xBBAAAADDFF0000DDL, i),
1658 Long.rotateRight(0xBBAAAADDFF0000DDL, -i));
1659 Assert.assertEquals(Long.rotateLeft(0xBBAAAADDFF0000DDL, -i),
1660 Long.rotateRight(0xBBAAAADDFF0000DDL, i));
1661 }
1662 }
jeffhao5d1ac922011-09-29 17:41:15 -07001663}