1 /*
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 
17 import junit.framework.Assert;
18 import java.util.Arrays;
19 import java.lang.reflect.Method;
20 
21 public class Main {
main(String args[])22   public static void main(String args[]) throws Exception {
23     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();
29     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();
37     test_Math_sqrt();
38     test_Math_ceil();
39     test_Math_floor();
40     test_Math_rint();
41     test_Math_round_D();
42     test_Math_round_F();
43     test_Math_isNaN_D();
44     test_Math_isNaN_F();
45     test_Math_isInfinite_D();
46     test_Math_isInfinite_F();
47     test_Short_reverseBytes();
48     test_Integer_reverseBytes();
49     test_Long_reverseBytes();
50     test_Integer_reverse();
51     test_Long_reverse();
52     test_Integer_numberOfLeadingZeros();
53     test_Long_numberOfLeadingZeros();
54     test_StrictMath_abs_I();
55     test_StrictMath_abs_J();
56     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();
64     test_StrictMath_sqrt();
65     test_StrictMath_ceil();
66     test_StrictMath_floor();
67     test_StrictMath_rint();
68     test_StrictMath_round_D();
69     test_StrictMath_round_F();
70     test_String_charAt();
71     test_String_compareTo();
72     test_String_indexOf();
73     test_String_isEmpty();
74     test_String_length();
75     test_Thread_currentThread();
76     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();
85     test_Integer_divideUnsigned();
86     test_Integer_numberOfTrailingZeros();
87     test_Long_numberOfTrailingZeros();
88     test_Integer_rotateRight();
89     test_Long_rotateRight();
90     test_Integer_rotateLeft();
91     test_Long_rotateLeft();
92     test_Integer_rotateRightLeft();
93     test_Long_rotateRightLeft();
94   }
95 
96   /**
97    * Will test inlining Thread.currentThread().
98    */
test_Thread_currentThread()99   public static void test_Thread_currentThread() {
100     // 1. Do not use result.
101     Thread.currentThread();
102 
103     // 2. Result should not be null.
104     Assert.assertNotNull(Thread.currentThread());
105   }
106 
test_String_length()107   public static void test_String_length() {
108     String str0 = "";
109     String str1 = "x";
110     String str80 = "01234567890123456789012345678901234567890123456789012345678901234567890123456789";
111 
112     Assert.assertEquals(str0.length(), 0);
113     Assert.assertEquals(str1.length(), 1);
114     Assert.assertEquals(str80.length(), 80);
115 
116     String strNull = null;
117     try {
118       strNull.length();
119       Assert.fail();
120     } catch (NullPointerException expected) {
121     }
122   }
123 
test_String_isEmpty()124   public static void test_String_isEmpty() {
125     String str0 = "";
126     String str1 = "x";
127 
128     Assert.assertTrue(str0.isEmpty());
129     Assert.assertFalse(str1.isEmpty());
130 
131     String strNull = null;
132     try {
133       strNull.isEmpty();
134       Assert.fail();
135     } catch (NullPointerException expected) {
136     }
137   }
138 
139   // Break up the charAt tests. The optimizing compiler doesn't optimize methods with try-catch yet,
140   // so we need to separate out the tests that are expected to throw exception
141 
test_String_charAt()142   public static void test_String_charAt() {
143     String testStr = "Now is the time to test some stuff";
144 
145     Assert.assertEquals(testStr.length() - 1, 33);  // 33 = testStr.length()-1 as a constant.
146     Assert.assertEquals('f', testStr.charAt(33));
147 
148     test_String_charAt(testStr, 'N', 'o', ' ', 'f');
149     test_String_charAt(testStr.substring(3,15), ' ', 'i', 'm', 'e');
150   }
test_String_charAt(String testStr, char a, char b, char c, char d)151   public static void test_String_charAt(String testStr, char a, char b, char c, char d) {
152     Assert.assertEquals(a, testStr.charAt(0));
153     Assert.assertEquals(b, testStr.charAt(1));
154     Assert.assertEquals(c, testStr.charAt(10));
155     Assert.assertEquals(d, testStr.charAt(testStr.length()-1));
156 
157     test_String_charAtExc(testStr);
158     test_String_charAtExc2(testStr);
159   }
160 
test_String_charAtExc(String testStr)161   private static void test_String_charAtExc(String testStr) {
162     try {
163       testStr.charAt(-1);
164       Assert.fail();
165     } catch (StringIndexOutOfBoundsException expected) {
166     }
167     try {
168       testStr.charAt(80);
169       Assert.fail();
170     } catch (StringIndexOutOfBoundsException expected) {
171     }
172     try {
173       if (testStr.length() == 34) {
174           testStr.charAt(34);  // 34 = "Now is the time to test some stuff".length()
175       } else {
176           Assert.assertEquals(testStr.length(), 12);  // 12 = " is the time".length()
177           testStr.charAt(12);
178       }
179       Assert.fail();
180     } catch (StringIndexOutOfBoundsException expected) {
181     }
182     try {
183       test_String_charAt_inner(testStr, -1);
184       Assert.fail();
185     } catch (StringIndexOutOfBoundsException expected) {
186     }
187     try {
188       test_String_charAt_inner(testStr, 80);
189       Assert.fail();
190     } catch (StringIndexOutOfBoundsException expected) {
191     }
192     try {
193       if (testStr.length() == 34) {
194         // 34 = "Now is the time to test some stuff".length()
195         test_String_charAt_inner(testStr, 34);
196       } else {
197         Assert.assertEquals(testStr.length(), 12);  // 12 = " is the time".length()
198         test_String_charAt_inner(testStr, 12);
199       }
200       Assert.fail();
201     } catch (StringIndexOutOfBoundsException expected) {
202     }
203 
204     String strEmpty = "";
205     try {
206       strEmpty.charAt(0);
207       Assert.fail();
208     } catch (StringIndexOutOfBoundsException expected) {
209     }
210 
211     String strNull = null;
212     try {
213       strNull.charAt(0);
214       Assert.fail();
215     } catch (NullPointerException expected) {
216     }
217   }
218 
test_String_charAt_inner(String s, int index)219   private static char test_String_charAt_inner(String s, int index) {
220     // Using non-constant index here (assuming that this method wasn't inlined).
221     return s.charAt(index);
222   }
223 
test_String_charAtExc2(String testStr)224   private static void test_String_charAtExc2(String testStr) {
225     try {
226       test_String_charAtExc3(testStr);
227       Assert.fail();
228     } catch (StringIndexOutOfBoundsException expected) {
229     }
230     try {
231       test_String_charAtExc4(testStr);
232       Assert.fail();
233     } catch (StringIndexOutOfBoundsException expected) {
234     }
235   }
236 
test_String_charAtExc3(String testStr)237   private static void test_String_charAtExc3(String testStr) {
238     Assert.assertEquals('N', testStr.charAt(-1));
239   }
240 
test_String_charAtExc4(String testStr)241   private static void test_String_charAtExc4(String testStr) {
242     Assert.assertEquals('N', testStr.charAt(100));
243   }
244 
245   static int start;
246   private static int[] negIndex = { -100000 };
test_String_indexOf()247   public static void test_String_indexOf() {
248     String str0 = "";
249     String str1 = "/";
250     String str3 = "abc";
251     String str10 = "abcdefghij";
252     String str40 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabc";
253 
254     Assert.assertEquals(str0.indexOf('a'), -1);
255     Assert.assertEquals(str3.indexOf('a'), 0);
256     Assert.assertEquals(str3.indexOf('b'), 1);
257     Assert.assertEquals(str3.indexOf('c'), 2);
258     Assert.assertEquals(str10.indexOf('j'), 9);
259     Assert.assertEquals(str40.indexOf('a'), 0);
260     Assert.assertEquals(str40.indexOf('b'), 38);
261     Assert.assertEquals(str40.indexOf('c'), 39);
262     Assert.assertEquals(str0.indexOf('a',20), -1);
263     Assert.assertEquals(str0.indexOf('a',0), -1);
264     Assert.assertEquals(str0.indexOf('a',-1), -1);
265     Assert.assertEquals(str1.indexOf('/',++start), -1);
266     Assert.assertEquals(str1.indexOf('a',negIndex[0]), -1);
267     Assert.assertEquals(str3.indexOf('a',0), 0);
268     Assert.assertEquals(str3.indexOf('a',1), -1);
269     Assert.assertEquals(str3.indexOf('a',1234), -1);
270     Assert.assertEquals(str3.indexOf('b',0), 1);
271     Assert.assertEquals(str3.indexOf('b',1), 1);
272     Assert.assertEquals(str3.indexOf('c',2), 2);
273     Assert.assertEquals(str10.indexOf('j',5), 9);
274     Assert.assertEquals(str10.indexOf('j',9), 9);
275     Assert.assertEquals(str40.indexOf('a',10), 10);
276     Assert.assertEquals(str40.indexOf('b',40), -1);
277 
278     testIndexOfNull();
279 
280     // Same data as above, but stored so it's not a literal in the next test. -2 stands for
281     // indexOf(I) instead of indexOf(II).
282     start--;
283     int[][] searchData = {
284         { 'a', -2, -1 },
285         { 'a', -2, 0 },
286         { 'b', -2, 1 },
287         { 'c', -2, 2 },
288         { 'j', -2, 9 },
289         { 'a', -2, 0 },
290         { 'b', -2, 38 },
291         { 'c', -2, 39 },
292         { 'a', 20, -1 },
293         { 'a', 0, -1 },
294         { 'a', -1, -1 },
295         { '/', ++start, -1 },
296         { 'a', negIndex[0], -1 },
297         { 'a', 0, 0 },
298         { 'a', 1, -1 },
299         { 'a', 1234, -1 },
300         { 'b', 0, 1 },
301         { 'b', 1, 1 },
302         { 'c', 2, 2 },
303         { 'j', 5, 9 },
304         { 'j', 9, 9 },
305         { 'a', 10, 10 },
306         { 'b', 40, -1 },
307     };
308     testStringIndexOfChars(searchData);
309 
310     testSurrogateIndexOf();
311   }
312 
testStringIndexOfChars(int[][] searchData)313   private static void testStringIndexOfChars(int[][] searchData) {
314     // Use a try-catch to avoid inlining.
315     try {
316       testStringIndexOfCharsImpl(searchData);
317     } catch (Exception e) {
318       System.out.println("Unexpected exception");
319     }
320   }
321 
testStringIndexOfCharsImpl(int[][] searchData)322   private static void testStringIndexOfCharsImpl(int[][] searchData) {
323     String str0 = "";
324     String str1 = "/";
325     String str3 = "abc";
326     String str10 = "abcdefghij";
327     String str40 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabc";
328 
329     Assert.assertEquals(str0.indexOf(searchData[0][0]), searchData[0][2]);
330     Assert.assertEquals(str3.indexOf(searchData[1][0]), searchData[1][2]);
331     Assert.assertEquals(str3.indexOf(searchData[2][0]), searchData[2][2]);
332     Assert.assertEquals(str3.indexOf(searchData[3][0]), searchData[3][2]);
333     Assert.assertEquals(str10.indexOf(searchData[4][0]), searchData[4][2]);
334     Assert.assertEquals(str40.indexOf(searchData[5][0]), searchData[5][2]);
335     Assert.assertEquals(str40.indexOf(searchData[6][0]), searchData[6][2]);
336     Assert.assertEquals(str40.indexOf(searchData[7][0]), searchData[7][2]);
337     Assert.assertEquals(str0.indexOf(searchData[8][0], searchData[8][1]), searchData[8][2]);
338     Assert.assertEquals(str0.indexOf(searchData[9][0], searchData[9][1]), searchData[9][2]);
339     Assert.assertEquals(str0.indexOf(searchData[10][0], searchData[10][1]), searchData[10][2]);
340     Assert.assertEquals(str1.indexOf(searchData[11][0], searchData[11][1]), searchData[11][2]);
341     Assert.assertEquals(str1.indexOf(searchData[12][0], searchData[12][1]), searchData[12][2]);
342     Assert.assertEquals(str3.indexOf(searchData[13][0], searchData[13][1]), searchData[13][2]);
343     Assert.assertEquals(str3.indexOf(searchData[14][0], searchData[14][1]), searchData[14][2]);
344     Assert.assertEquals(str3.indexOf(searchData[15][0], searchData[15][1]), searchData[15][2]);
345     Assert.assertEquals(str3.indexOf(searchData[16][0], searchData[16][1]), searchData[16][2]);
346     Assert.assertEquals(str3.indexOf(searchData[17][0], searchData[17][1]), searchData[17][2]);
347     Assert.assertEquals(str3.indexOf(searchData[18][0], searchData[18][1]), searchData[18][2]);
348     Assert.assertEquals(str10.indexOf(searchData[19][0], searchData[19][1]), searchData[19][2]);
349     Assert.assertEquals(str10.indexOf(searchData[20][0], searchData[20][1]), searchData[20][2]);
350     Assert.assertEquals(str40.indexOf(searchData[21][0], searchData[21][1]), searchData[21][2]);
351     Assert.assertEquals(str40.indexOf(searchData[22][0], searchData[22][1]), searchData[22][2]);
352   }
353 
testSurrogateIndexOf()354   private static void testSurrogateIndexOf() {
355     int supplementaryChar = 0x20b9f;
356     String surrogatePair = "\ud842\udf9f";
357     String stringWithSurrogates = "hello " + surrogatePair + " world";
358 
359     Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar), "hello ".length());
360     Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 2), "hello ".length());
361     Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 6), 6);
362     Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 7), -1);
363 
364     Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar - 0x10000), -1);
365     Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar | 0x80000000), -1);
366   }
367 
testIndexOfNull()368   private static void testIndexOfNull() {
369     String strNull = null;
370     try {
371       testNullIndex(strNull, 'a');
372       Assert.fail();
373     } catch (NullPointerException expected) {
374     }
375     try {
376       testNullIndex(strNull, 'a', 0);
377       Assert.fail();
378     } catch (NullPointerException expected) {
379     }
380     try {
381         testNullIndex(strNull, 'a', -1);
382       Assert.fail();
383     } catch (NullPointerException expected) {
384     }
385   }
386 
testNullIndex(String strNull, int c)387   private static int testNullIndex(String strNull, int c) {
388     return strNull.indexOf(c);
389   }
390 
testNullIndex(String strNull, int c, int startIndex)391   private static int testNullIndex(String strNull, int c, int startIndex) {
392     return strNull.indexOf(c, startIndex);
393   }
394 
test_String_compareTo()395   public static void test_String_compareTo() {
396     String test = "0123456789";
397     String test1 = new String("0123456789");    // different object
398     String test2 = new String("0123456780");    // different value
399     String offset = new String("xxx0123456789yyy");
400     String sub = offset.substring(3, 13);
401     String str32 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
402     String str33 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxy";
403     String lc = "abcdefg";
404     String uc = "ABCDEFG";
405     Object blah = new Object();
406 
407     Assert.assertTrue(lc.toUpperCase().equals(uc));
408 
409     Assert.assertEquals(str32.compareTo(str33), -1);
410     Assert.assertEquals(str33.compareTo(str32), 1);
411 
412     Assert.assertTrue(test.equals(test));
413     Assert.assertTrue(test.equals(test1));
414     Assert.assertFalse(test.equals(test2));
415 
416     Assert.assertEquals(test.compareTo(test1), 0);
417     Assert.assertTrue(test1.compareTo(test2) > 0);
418     Assert.assertTrue(test2.compareTo(test1) < 0);
419 
420     // Compare string with a nonzero offset, in left/right side.
421     Assert.assertEquals(test.compareTo(sub), 0);
422     Assert.assertEquals(sub.compareTo(test), 0);
423     Assert.assertTrue(test.equals(sub));
424     Assert.assertTrue(sub.equals(test));
425     // Same base, one is a substring.
426     Assert.assertFalse(offset.equals(sub));
427     Assert.assertFalse(sub.equals(offset));
428     // Wrong class.
429     Assert.assertFalse(test.equals(blah));
430 
431     // Null lhs - throw.
432     try {
433       test.compareTo(null);
434       Assert.fail("didn't get expected npe");
435     } catch (NullPointerException npe) {
436     }
437     // Null rhs - okay.
438     Assert.assertFalse(test.equals(null));
439 
440     test = test.substring(1);
441     Assert.assertTrue(test.equals("123456789"));
442     Assert.assertFalse(test.equals(test1));
443 
444     test = test.substring(1);
445     Assert.assertTrue(test.equals("23456789"));
446 
447     test = test.substring(1);
448     Assert.assertTrue(test.equals("3456789"));
449 
450     test = test.substring(1);
451     Assert.assertTrue(test.equals("456789"));
452 
453     test = test.substring(3,5);
454     Assert.assertTrue(test.equals("78"));
455 
456     test = "this/is/a/path";
457     String[] strings = test.split("/");
458     Assert.assertEquals(4, strings.length);
459 
460     Assert.assertEquals("this is a path", test.replaceAll("/", " "));
461     Assert.assertEquals("this is a path", test.replace("/", " "));
462   }
463 
464   public static void test_Math_abs_I() {
465     Math.abs(-1);
466     Assert.assertEquals(Math.abs(0), 0);
467     Assert.assertEquals(Math.abs(123), 123);
468     Assert.assertEquals(Math.abs(-123), 123);
469     Assert.assertEquals(Math.abs(Integer.MAX_VALUE), Integer.MAX_VALUE);
470     Assert.assertEquals(Math.abs(Integer.MIN_VALUE), Integer.MIN_VALUE);
471     Assert.assertEquals(Math.abs(Integer.MIN_VALUE - 1), Integer.MAX_VALUE);
472     Assert.assertEquals(Math.abs(Integer.MIN_VALUE + 1), Integer.MAX_VALUE);
473   }
474 
475   public static void test_Math_abs_J() {
476     Math.abs(-1L);
477     Assert.assertEquals(Math.abs(0L), 0L);
478     Assert.assertEquals(Math.abs(123L), 123L);
479     Assert.assertEquals(Math.abs(-123L), 123L);
480     Assert.assertEquals(Math.abs(Long.MAX_VALUE), Long.MAX_VALUE);
481     Assert.assertEquals(Math.abs(Long.MIN_VALUE), Long.MIN_VALUE);
482     Assert.assertEquals(Math.abs(Long.MIN_VALUE - 1), Long.MAX_VALUE);
483     Assert.assertEquals(Math.abs(2147483648L), 2147483648L);
484   }
485 
486   public static void test_Math_min_I() {
487     Math.min(1, 0);
488     Assert.assertEquals(Math.min(0, 0), 0);
489     Assert.assertEquals(Math.min(1, 0), 0);
490     Assert.assertEquals(Math.min(0, 1), 0);
491     Assert.assertEquals(Math.min(0, Integer.MAX_VALUE), 0);
492     Assert.assertEquals(Math.min(Integer.MIN_VALUE, 0), Integer.MIN_VALUE);
493     Assert.assertEquals(Math.min(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MIN_VALUE);
494   }
495 
496   public static void test_Math_max_I() {
497     Math.max(1, 0);
498     Assert.assertEquals(Math.max(0, 0), 0);
499     Assert.assertEquals(Math.max(1, 0), 1);
500     Assert.assertEquals(Math.max(0, 1), 1);
501     Assert.assertEquals(Math.max(0, Integer.MAX_VALUE), Integer.MAX_VALUE);
502     Assert.assertEquals(Math.max(Integer.MIN_VALUE, 0), 0);
503     Assert.assertEquals(Math.max(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MAX_VALUE);
504   }
505 
506   public static void test_Math_min_J() {
507     Math.min(1L, 0L);
508     Assert.assertEquals(Math.min(0L, 0L), 0L);
509     Assert.assertEquals(Math.min(1L, 0L), 0L);
510     Assert.assertEquals(Math.min(0L, 1L), 0L);
511     Assert.assertEquals(Math.min(0L, Long.MAX_VALUE), 0L);
512     Assert.assertEquals(Math.min(Long.MIN_VALUE, 0L), Long.MIN_VALUE);
513     Assert.assertEquals(Math.min(Long.MIN_VALUE, Long.MAX_VALUE), Long.MIN_VALUE);
514   }
515 
516   public static void test_Math_max_J() {
517     Math.max(1L, 0L);
518     Assert.assertEquals(Math.max(0L, 0L), 0L);
519     Assert.assertEquals(Math.max(1L, 0L), 1L);
520     Assert.assertEquals(Math.max(0L, 1L), 1L);
521     Assert.assertEquals(Math.max(0L, Long.MAX_VALUE), Long.MAX_VALUE);
522     Assert.assertEquals(Math.max(Long.MIN_VALUE, 0L), 0L);
523     Assert.assertEquals(Math.max(Long.MIN_VALUE, Long.MAX_VALUE), Long.MAX_VALUE);
524   }
525 
526   public static void test_Math_min_F() {
527     Math.min(1.0f, Float.NaN);
528     Assert.assertTrue(Float.isNaN(Math.min(1.0f, Float.NaN)));
529     Assert.assertTrue(Float.isNaN(Math.min(Float.NaN, 1.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(0.0f, 0.0f), 0.0f);
534     Assert.assertEquals(Math.min(1.0f, 0.0f), 0.0f);
535     Assert.assertEquals(Math.min(0.0f, 1.0f), 0.0f);
536     Assert.assertEquals(Math.min(0.0f, Float.MAX_VALUE), 0.0f);
537     Assert.assertEquals(Math.min(Float.MIN_VALUE, 0.0f), 0.0f);
538     Assert.assertEquals(Math.min(Float.MIN_VALUE, Float.MAX_VALUE), Float.MIN_VALUE);
539     // Should not have flush-to-zero behavior.
540     Assert.assertEquals(Math.min(Float.MIN_VALUE, Float.MIN_VALUE), Float.MIN_VALUE);
541   }
542 
543   public static void test_Math_max_F() {
544     Math.max(1.0f, Float.NaN);
545     Assert.assertTrue(Float.isNaN(Math.max(1.0f, Float.NaN)));
546     Assert.assertTrue(Float.isNaN(Math.max(Float.NaN, 1.0f)));
547     Assert.assertEquals(Math.max(-0.0f, 0.0f), 0.0f);
548     Assert.assertEquals(Math.max(0.0f, -0.0f), 0.0f);
549     Assert.assertEquals(Math.max(-0.0f, -0.0f), -0.0f);
550     Assert.assertEquals(Math.max(0.0f, 0.0f), 0.0f);
551     Assert.assertEquals(Math.max(1.0f, 0.0f), 1.0f);
552     Assert.assertEquals(Math.max(0.0f, 1.0f), 1.0f);
553     Assert.assertEquals(Math.max(0.0f, Float.MAX_VALUE), Float.MAX_VALUE);
554     Assert.assertEquals(Math.max(Float.MIN_VALUE, Float.MAX_VALUE), Float.MAX_VALUE);
555     // Should not have flush-to-zero behavior.
556     Assert.assertEquals(Math.max(Float.MIN_VALUE, 0.0f), Float.MIN_VALUE);
557     Assert.assertEquals(Math.max(Float.MIN_VALUE, Float.MIN_VALUE), Float.MIN_VALUE);
558   }
559 
560   public static void test_Math_min_D() {
561     Math.min(1.0d, Double.NaN);
562     Assert.assertTrue(Double.isNaN(Math.min(1.0d, Double.NaN)));
563     Assert.assertTrue(Double.isNaN(Math.min(Double.NaN, 1.0d)));
564     Assert.assertEquals(Math.min(-0.0d, 0.0d), -0.0d);
565     Assert.assertEquals(Math.min(0.0d, -0.0d), -0.0d);
566     Assert.assertEquals(Math.min(-0.0d, -0.0d), -0.0d);
567     Assert.assertEquals(Math.min(0.0d, 0.0d), 0.0d);
568     Assert.assertEquals(Math.min(1.0d, 0.0d), 0.0d);
569     Assert.assertEquals(Math.min(0.0d, 1.0d), 0.0d);
570     Assert.assertEquals(Math.min(0.0d, Double.MAX_VALUE), 0.0d);
571     Assert.assertEquals(Math.min(Double.MIN_VALUE, 0.0d), 0.0d);
572     Assert.assertEquals(Math.min(Double.MIN_VALUE, Double.MAX_VALUE), Double.MIN_VALUE);
573     // Should not have flush-to-zero behavior.
574     Assert.assertEquals(Math.min(Double.MIN_VALUE, Double.MIN_VALUE), Double.MIN_VALUE);
575   }
576 
577   public static void test_Math_max_D() {
578     Math.max(1.0d, Double.NaN);
579     Assert.assertTrue(Double.isNaN(Math.max(1.0d, Double.NaN)));
580     Assert.assertTrue(Double.isNaN(Math.max(Double.NaN, 1.0d)));
581     Assert.assertEquals(Math.max(-0.0d, 0.0d), 0.0d);
582     Assert.assertEquals(Math.max(0.0d, -0.0d), 0.0d);
583     Assert.assertEquals(Math.max(-0.0d, -0.0d), -0.0d);
584     Assert.assertEquals(Math.max(0.0d, 0.0d), 0.0d);
585     Assert.assertEquals(Math.max(1.0d, 0.0d), 1.0d);
586     Assert.assertEquals(Math.max(0.0d, 1.0d), 1.0d);
587     Assert.assertEquals(Math.max(0.0d, Double.MAX_VALUE), Double.MAX_VALUE);
588     Assert.assertEquals(Math.max(Double.MIN_VALUE, 0.0d), Double.MIN_VALUE);
589     Assert.assertEquals(Math.max(Double.MIN_VALUE, Double.MAX_VALUE), Double.MAX_VALUE);
590     // Should not have flush-to-zero behavior.
591     Assert.assertEquals(Math.max(Double.MIN_VALUE, 0.0d), Double.MIN_VALUE);
592     Assert.assertEquals(Math.max(Double.MIN_VALUE, Double.MIN_VALUE), Double.MIN_VALUE);
593   }
594 
595   public static void test_Math_sqrt() {
596     Math.sqrt(+4.0);
597     Assert.assertEquals(Math.sqrt(+4.0), +2.0d, 0.0);
598     Assert.assertEquals(Math.sqrt(+49.0), +7.0d, 0.0);
599     Assert.assertEquals(Math.sqrt(+1.44), +1.2d, 0.0);
600   }
601 
602   public static void test_Math_ceil() {
603     Math.ceil(-0.9);
604     Assert.assertEquals(Math.ceil(+0.0), +0.0d, 0.0);
605     Assert.assertEquals(Math.ceil(-0.0), -0.0d, 0.0);
606     Assert.assertEquals(Math.ceil(-0.9), -0.0d, 0.0);
607     Assert.assertEquals(Math.ceil(-0.5), -0.0d, 0.0);
608     Assert.assertEquals(Math.ceil(0.0), -0.0d, 0.0);
609     Assert.assertEquals(Math.ceil(+2.0), +2.0d, 0.0);
610     Assert.assertEquals(Math.ceil(+2.1), +3.0d, 0.0);
611     Assert.assertEquals(Math.ceil(+2.5), +3.0d, 0.0);
612     Assert.assertEquals(Math.ceil(+2.9), +3.0d, 0.0);
613     Assert.assertEquals(Math.ceil(+3.0), +3.0d, 0.0);
614     Assert.assertEquals(Math.ceil(-2.0), -2.0d, 0.0);
615     Assert.assertEquals(Math.ceil(-2.1), -2.0d, 0.0);
616     Assert.assertEquals(Math.ceil(-2.5), -2.0d, 0.0);
617     Assert.assertEquals(Math.ceil(-2.9), -2.0d, 0.0);
618     Assert.assertEquals(Math.ceil(-3.0), -3.0d, 0.0);
619     // 2^52 - 1.5
620     Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0x432FFFFFFFFFFFFDl)),
621                         Double.longBitsToDouble(0x432FFFFFFFFFFFFEl), 0.0);
622     // 2^52 - 0.5
623     Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0x432FFFFFFFFFFFFFl)),
624                         Double.longBitsToDouble(0x4330000000000000l), 0.0);
625     // 2^52
626     Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0x4330000000000000l)),
627                         Double.longBitsToDouble(0x4330000000000000l), 0.0);
628     // 2^53 - 1
629     Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0x433FFFFFFFFFFFFFl)),
630                         Double.longBitsToDouble(0x433FFFFFFFFFFFFFl), 0.0);
631     // 2^53
632     Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0x4340000000000000l)),
633                         Double.longBitsToDouble(0x4340000000000000l), 0.0);
634     // 2^63 - 2^10
635     Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0x43DFFFFFFFFFFFFFl)),
636                         Double.longBitsToDouble(0x43DFFFFFFFFFFFFFl), 0.0);
637     // 2^63
638     Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0x43E0000000000000l)),
639                         Double.longBitsToDouble(0x43E0000000000000l), 0.0);
640     // 2^64
641     Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0x43F0000000000000l)),
642                         Double.longBitsToDouble(0x43F0000000000000l), 0.0);
643     // -(2^52 - 1.5)
644     Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0xC32FFFFFFFFFFFFDl)),
645                         Double.longBitsToDouble(0xC32FFFFFFFFFFFFCl), 0.0);
646     // -(2^52 - 0.5)
647     Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0xC32FFFFFFFFFFFFFl)),
648                         Double.longBitsToDouble(0xC32FFFFFFFFFFFFEl), 0.0);
649     // -2^52
650     Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0xC330000000000000l)),
651                         Double.longBitsToDouble(0xC330000000000000l), 0.0);
652     // -(2^53 - 1)
653     Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0xC33FFFFFFFFFFFFFl)),
654                         Double.longBitsToDouble(0xC33FFFFFFFFFFFFFl), 0.0);
655     // -2^53
656     Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0xC340000000000000l)),
657                         Double.longBitsToDouble(0xC340000000000000l), 0.0);
658     // -(2^63 - 2^10)
659     Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0xC3DFFFFFFFFFFFFFl)),
660                         Double.longBitsToDouble(0xC3DFFFFFFFFFFFFFl), 0.0);
661     // -2^63
662     Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0xC3E0000000000000l)),
663                         Double.longBitsToDouble(0xC3E0000000000000l), 0.0);
664     // -2^64
665     Assert.assertEquals(Math.ceil(Double.longBitsToDouble(0xC3F0000000000000l)),
666                         Double.longBitsToDouble(0xC3F0000000000000l), 0.0);
667     Assert.assertEquals(Math.ceil(Double.NaN), Double.NaN, 0.0);
668     Assert.assertEquals(Math.ceil(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
669     Assert.assertEquals(Math.ceil(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
670   }
671 
672   public static void test_Math_floor() {
673     Math.floor(+2.1);
674     Assert.assertEquals(Math.floor(+0.0), +0.0d, 0.0);
675     Assert.assertEquals(Math.floor(-0.0), -0.0d, 0.0);
676     Assert.assertEquals(Math.floor(+2.0), +2.0d, 0.0);
677     Assert.assertEquals(Math.floor(+2.1), +2.0d, 0.0);
678     Assert.assertEquals(Math.floor(+2.5), +2.0d, 0.0);
679     Assert.assertEquals(Math.floor(+2.9), +2.0d, 0.0);
680     Assert.assertEquals(Math.floor(+3.0), +3.0d, 0.0);
681     Assert.assertEquals(Math.floor(-2.0), -2.0d, 0.0);
682     Assert.assertEquals(Math.floor(-2.1), -3.0d, 0.0);
683     Assert.assertEquals(Math.floor(-2.5), -3.0d, 0.0);
684     Assert.assertEquals(Math.floor(-2.9), -3.0d, 0.0);
685     Assert.assertEquals(Math.floor(-3.0), -3.0d, 0.0);
686     // 2^52 - 1.5
687     Assert.assertEquals(Math.floor(Double.longBitsToDouble(0x432FFFFFFFFFFFFDl)),
688                         Double.longBitsToDouble(0x432FFFFFFFFFFFFCl), 0.0);
689     // 2^52 - 0.5
690     Assert.assertEquals(Math.floor(Double.longBitsToDouble(0x432FFFFFFFFFFFFFl)),
691                         Double.longBitsToDouble(0x432FFFFFFFFFFFFEl), 0.0);
692     // 2^52
693     Assert.assertEquals(Math.floor(Double.longBitsToDouble(0x4330000000000000l)),
694                         Double.longBitsToDouble(0x4330000000000000l), 0.0);
695     // 2^53 - 1
696     Assert.assertEquals(Math.floor(Double.longBitsToDouble(0x433FFFFFFFFFFFFFl)),
697                         Double.longBitsToDouble(0x433FFFFFFFFFFFFFl), 0.0);
698     // 2^53
699     Assert.assertEquals(Math.floor(Double.longBitsToDouble(0x4340000000000000l)),
700                         Double.longBitsToDouble(0x4340000000000000l), 0.0);
701     // 2^63 - 2^10
702     Assert.assertEquals(Math.floor(Double.longBitsToDouble(0x43DFFFFFFFFFFFFFl)),
703                         Double.longBitsToDouble(0x43DFFFFFFFFFFFFFl), 0.0);
704     // 2^63
705     Assert.assertEquals(Math.floor(Double.longBitsToDouble(0x43E0000000000000l)),
706                         Double.longBitsToDouble(0x43E0000000000000l), 0.0);
707     // 2^64
708     Assert.assertEquals(Math.floor(Double.longBitsToDouble(0x43F0000000000000l)),
709                         Double.longBitsToDouble(0x43F0000000000000l), 0.0);
710     // -(2^52 - 1.5)
711     Assert.assertEquals(Math.floor(Double.longBitsToDouble(0xC32FFFFFFFFFFFFDl)),
712                         Double.longBitsToDouble(0xC32FFFFFFFFFFFFEl), 0.0);
713     // -(2^52 - 0.5)
714     Assert.assertEquals(Math.floor(Double.longBitsToDouble(0xC32FFFFFFFFFFFFFl)),
715                         Double.longBitsToDouble(0xC330000000000000l), 0.0);
716     // -2^52
717     Assert.assertEquals(Math.floor(Double.longBitsToDouble(0xC330000000000000l)),
718                         Double.longBitsToDouble(0xC330000000000000l), 0.0);
719     // -(2^53 - 1)
720     Assert.assertEquals(Math.floor(Double.longBitsToDouble(0xC33FFFFFFFFFFFFFl)),
721                         Double.longBitsToDouble(0xC33FFFFFFFFFFFFFl), 0.0);
722     // -2^53
723     Assert.assertEquals(Math.floor(Double.longBitsToDouble(0xC340000000000000l)),
724                         Double.longBitsToDouble(0xC340000000000000l), 0.0);
725     // -(2^63 - 2^10)
726     Assert.assertEquals(Math.floor(Double.longBitsToDouble(0xC3DFFFFFFFFFFFFFl)),
727                         Double.longBitsToDouble(0xC3DFFFFFFFFFFFFFl), 0.0);
728     // -2^63
729     Assert.assertEquals(Math.floor(Double.longBitsToDouble(0xC3E0000000000000l)),
730                         Double.longBitsToDouble(0xC3E0000000000000l), 0.0);
731     // -2^64
732     Assert.assertEquals(Math.floor(Double.longBitsToDouble(0xC3F0000000000000l)),
733                         Double.longBitsToDouble(0xC3F0000000000000l), 0.0);
734     Assert.assertEquals(Math.floor(Double.NaN), Double.NaN, 0.0);
735     Assert.assertEquals(Math.floor(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
736     Assert.assertEquals(Math.floor(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
737   }
738 
739   public static void test_Math_rint() {
740     Math.rint(+2.1);
741     Assert.assertEquals(Math.rint(+0.0), +0.0d, 0.0);
742     Assert.assertEquals(Math.rint(-0.0), -0.0d, 0.0);
743     Assert.assertEquals(Math.rint(+0.5), +0.0d, 0.0);  // expects tie-to-even
744     Assert.assertEquals(Math.rint(+2.0), +2.0d, 0.0);
745     Assert.assertEquals(Math.rint(+2.1), +2.0d, 0.0);
746     Assert.assertEquals(Math.rint(+2.5), +2.0d, 0.0);  // expects tie-to-even
747     Assert.assertEquals(Math.rint(+2.9), +3.0d, 0.0);
748     Assert.assertEquals(Math.rint(+3.0), +3.0d, 0.0);
749     Assert.assertEquals(Math.rint(+3.5), +4.0d, 0.0);  // expects tie-to-even
750     Assert.assertEquals(Math.rint(-2.0), -2.0d, 0.0);
751     Assert.assertEquals(Math.rint(-2.1), -2.0d, 0.0);
752     Assert.assertEquals(Math.rint(-2.5), -2.0d, 0.0);  // expects tie-to-even
753     Assert.assertEquals(Math.rint(-2.9), -3.0d, 0.0);
754     Assert.assertEquals(Math.rint(-3.0), -3.0d, 0.0);
755     Assert.assertEquals(Math.rint(-3.5), -4.0d, 0.0);  // expects tie-to-even
756     // 2^52 - 1.5
757     Assert.assertEquals(Math.rint(Double.longBitsToDouble(0x432FFFFFFFFFFFFDl)),
758                         Double.longBitsToDouble(0x432FFFFFFFFFFFFCl), 0.0);
759     // 2^52 - 0.5
760     Assert.assertEquals(Math.rint(Double.longBitsToDouble(0x432FFFFFFFFFFFFFl)),
761                         Double.longBitsToDouble(0x4330000000000000l), 0.0);
762     // 2^52
763     Assert.assertEquals(Math.rint(Double.longBitsToDouble(0x4330000000000000l)),
764                         Double.longBitsToDouble(0x4330000000000000l), 0.0);
765     // 2^53 - 1
766     Assert.assertEquals(Math.rint(Double.longBitsToDouble(0x433FFFFFFFFFFFFFl)),
767                         Double.longBitsToDouble(0x433FFFFFFFFFFFFFl), 0.0);
768     // 2^53
769     Assert.assertEquals(Math.rint(Double.longBitsToDouble(0x4340000000000000l)),
770                         Double.longBitsToDouble(0x4340000000000000l), 0.0);
771     // 2^63 - 2^10
772     Assert.assertEquals(Math.rint(Double.longBitsToDouble(0x43DFFFFFFFFFFFFFl)),
773                         Double.longBitsToDouble(0x43DFFFFFFFFFFFFFl), 0.0);
774     // 2^63
775     Assert.assertEquals(Math.rint(Double.longBitsToDouble(0x43E0000000000000l)),
776                         Double.longBitsToDouble(0x43E0000000000000l), 0.0);
777     // 2^64
778     Assert.assertEquals(Math.rint(Double.longBitsToDouble(0x43F0000000000000l)),
779                         Double.longBitsToDouble(0x43F0000000000000l), 0.0);
780     // -(2^52 - 1.5)
781     Assert.assertEquals(Math.rint(Double.longBitsToDouble(0xC32FFFFFFFFFFFFDl)),
782                         Double.longBitsToDouble(0xC32FFFFFFFFFFFFCl), 0.0);
783     // -(2^52 - 0.5)
784     Assert.assertEquals(Math.rint(Double.longBitsToDouble(0xC32FFFFFFFFFFFFFl)),
785                         Double.longBitsToDouble(0xC330000000000000l), 0.0);
786     // -2^52
787     Assert.assertEquals(Math.rint(Double.longBitsToDouble(0xC330000000000000l)),
788                         Double.longBitsToDouble(0xC330000000000000l), 0.0);
789     // -(2^53 - 1)
790     Assert.assertEquals(Math.rint(Double.longBitsToDouble(0xC33FFFFFFFFFFFFFl)),
791                         Double.longBitsToDouble(0xC33FFFFFFFFFFFFFl), 0.0);
792     // -2^53
793     Assert.assertEquals(Math.rint(Double.longBitsToDouble(0xC340000000000000l)),
794                         Double.longBitsToDouble(0xC340000000000000l), 0.0);
795     // -(2^63 - 2^10)
796     Assert.assertEquals(Math.rint(Double.longBitsToDouble(0xC3DFFFFFFFFFFFFFl)),
797                         Double.longBitsToDouble(0xC3DFFFFFFFFFFFFFl), 0.0);
798     // -2^63
799     Assert.assertEquals(Math.rint(Double.longBitsToDouble(0xC3E0000000000000l)),
800                         Double.longBitsToDouble(0xC3E0000000000000l), 0.0);
801     // -2^64
802     Assert.assertEquals(Math.rint(Double.longBitsToDouble(0xC3F0000000000000l)),
803                         Double.longBitsToDouble(0xC3F0000000000000l), 0.0);
804     Assert.assertEquals(Math.rint(Double.NaN), Double.NaN, 0.0);
805     Assert.assertEquals(Math.rint(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
806     Assert.assertEquals(Math.rint(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
807   }
808 
809   public static void test_Math_round_D() {
810     Math.round(2.1d);
811     Assert.assertEquals(Math.round(+0.0d), (long)+0.0);
812     Assert.assertEquals(Math.round(-0.0d), (long)+0.0);
813     Assert.assertEquals(Math.round(2.0d), 2l);
814     Assert.assertEquals(Math.round(2.1d), 2l);
815     Assert.assertEquals(Math.round(2.5d), 3l);
816     Assert.assertEquals(Math.round(2.9d), 3l);
817     Assert.assertEquals(Math.round(3.0d), 3l);
818     Assert.assertEquals(Math.round(-2.0d), -2l);
819     Assert.assertEquals(Math.round(-2.1d), -2l);
820     Assert.assertEquals(Math.round(-2.5d), -2l);
821     Assert.assertEquals(Math.round(-2.9d), -3l);
822     Assert.assertEquals(Math.round(-3.0d), -3l);
823     Assert.assertEquals(Math.round(0.49999999999999994d), 0l);
824     Assert.assertEquals(Math.round(4503599627370495.0d), 4503599627370495l);  // 2^52 - 1
825     Assert.assertEquals(Math.round(4503599627370495.5d), 4503599627370496l);  // 2^52 - 0.5
826     Assert.assertEquals(Math.round(4503599627370496.0d), 4503599627370496l);  // 2^52
827     Assert.assertEquals(Math.round(-4503599627370495.0d), -4503599627370495l);  // -(2^52 - 1)
828     Assert.assertEquals(Math.round(-4503599627370495.5d), -4503599627370495l);  // -(2^52 - 0.5)
829     Assert.assertEquals(Math.round(-4503599627370496.0d), -4503599627370496l);  // -2^52
830     Assert.assertEquals(Math.round(9007199254740991.0d), 9007199254740991l);  // 2^53 - 1
831     Assert.assertEquals(Math.round(-9007199254740991.0d), -9007199254740991l);  // -(2^53 - 1)
832     Assert.assertEquals(Math.round(Double.NaN), (long)+0.0d);
833     Assert.assertEquals(Math.round(Long.MAX_VALUE + 1.0d), Long.MAX_VALUE);
834     Assert.assertEquals(Math.round(Long.MIN_VALUE - 1.0d), Long.MIN_VALUE);
835     Assert.assertEquals(Math.round(Double.longBitsToDouble(0x43F0000000000000l)),
836                         Long.MAX_VALUE); // 2^64
837     Assert.assertEquals(Math.round(Double.longBitsToDouble(0xC3F0000000000000l)),
838                         Long.MIN_VALUE); // -2^64
839     Assert.assertEquals(Math.round(Double.POSITIVE_INFINITY), Long.MAX_VALUE);
840     Assert.assertEquals(Math.round(Double.NEGATIVE_INFINITY), Long.MIN_VALUE);
841   }
842 
843   public static void test_Math_round_F() {
844     Math.round(2.1f);
845     Assert.assertEquals(Math.round(+0.0f), (int)+0.0);
846     Assert.assertEquals(Math.round(-0.0f), (int)+0.0);
847     Assert.assertEquals(Math.round(2.0f), 2);
848     Assert.assertEquals(Math.round(2.1f), 2);
849     Assert.assertEquals(Math.round(2.5f), 3);
850     Assert.assertEquals(Math.round(2.9f), 3);
851     Assert.assertEquals(Math.round(3.0f), 3);
852     Assert.assertEquals(Math.round(-2.0f), -2);
853     Assert.assertEquals(Math.round(-2.1f), -2);
854     Assert.assertEquals(Math.round(-2.5f), -2);
855     Assert.assertEquals(Math.round(-2.9f), -3);
856     Assert.assertEquals(Math.round(-3.0f), -3);
857     // 0.4999999701976776123046875
858     Assert.assertEquals(Math.round(Float.intBitsToFloat(0x3EFFFFFF)), (int)+0.0f);
859     Assert.assertEquals(Math.round(8388607.0f), 8388607);  // 2^23 - 1
860     Assert.assertEquals(Math.round(8388607.5f), 8388608);  // 2^23 - 0.5
861     Assert.assertEquals(Math.round(8388608.0f), 8388608);  // 2^23
862     Assert.assertEquals(Math.round(-8388607.0f), -8388607);  // -(2^23 - 1)
863     Assert.assertEquals(Math.round(-8388607.5f), -8388607);  // -(2^23 - 0.5)
864     Assert.assertEquals(Math.round(-8388608.0f), -8388608);  // -2^23
865     Assert.assertEquals(Math.round(16777215.0f), 16777215);  // 2^24 - 1
866     Assert.assertEquals(Math.round(16777216.0f), 16777216);  // 2^24
867     Assert.assertEquals(Math.round(-16777215.0f), -16777215);  // -(2^24 - 1)
868     Assert.assertEquals(Math.round(-16777216.0f), -16777216);  // -2^24
869     Assert.assertEquals(Math.round(Float.NaN), (int)+0.0f);
870     Assert.assertEquals(Math.round(Integer.MAX_VALUE + 1.0f), Integer.MAX_VALUE);
871     Assert.assertEquals(Math.round(Integer.MIN_VALUE - 1.0f), Integer.MIN_VALUE);
872     Assert.assertEquals(Math.round(Float.intBitsToFloat(0x4F800000)),
873                         Integer.MAX_VALUE); // 2^32
874     Assert.assertEquals(Math.round(Float.intBitsToFloat(0xCF800000)),
875                         Integer.MIN_VALUE); // -2^32
876     Assert.assertEquals(Math.round(Float.POSITIVE_INFINITY), Integer.MAX_VALUE);
877     Assert.assertEquals(Math.round(Float.NEGATIVE_INFINITY), Integer.MIN_VALUE);
878   }
879 
880   public static void test_Math_isNaN_D() {
881     // Quiet NaN.
882     Assert.assertTrue(Double.isNaN(Double.longBitsToDouble(0x7FF4000000000000l)));
883     Assert.assertTrue(Double.isNaN(Double.longBitsToDouble(0xFFF4000000000000l)));
884     // Signaling NaN.
885     Assert.assertTrue(Double.isNaN(Double.longBitsToDouble(0x7FF8000000000000l)));
886     Assert.assertTrue(Double.isNaN(Double.longBitsToDouble(0xFFF8000000000000l)));
887     // Distinct from +/- infinity.
888     Assert.assertFalse(Double.isNaN(Double.longBitsToDouble(0x7FF0000000000000l)));
889     Assert.assertFalse(Double.isNaN(Double.longBitsToDouble(0xFFF0000000000000l)));
890     // Distinct from normal numbers.
891     Assert.assertFalse(Double.isNaN(Double.longBitsToDouble(0x7FE0000000000000l)));
892     Assert.assertFalse(Double.isNaN(Double.longBitsToDouble(0xFFE0000000000000l)));
893     Assert.assertFalse(Double.isNaN(Double.longBitsToDouble(0x0010000000000000l)));
894     Assert.assertFalse(Double.isNaN(Double.longBitsToDouble(0x8010000000000000l)));
895     // Distinct from +/- zero.
896     Assert.assertFalse(Double.isNaN(Double.longBitsToDouble(0x0000000000000000l)));
897     Assert.assertFalse(Double.isNaN(Double.longBitsToDouble(0x8000000000000000l)));
898     // Distinct from subnormal numbers.
899     Assert.assertFalse(Double.isNaN(Double.longBitsToDouble(0x0008000000000000l)));
900     Assert.assertFalse(Double.isNaN(Double.longBitsToDouble(0x8008000000000000l)));
901     Assert.assertFalse(Double.isNaN(Double.longBitsToDouble(0x0000000000000001l)));
902     Assert.assertFalse(Double.isNaN(Double.longBitsToDouble(0x8000000000000001l)));
903   }
904 
905   public static void test_Math_isNaN_F() {
906     // Quiet NaN.
907     Assert.assertTrue(Float.isNaN(Float.intBitsToFloat(0x7FA00000)));
908     Assert.assertTrue(Float.isNaN(Float.intBitsToFloat(0xFFA00000)));
909     // Signaling NaN.
910     Assert.assertTrue(Float.isNaN(Float.intBitsToFloat(0x7FC00000)));
911     Assert.assertTrue(Float.isNaN(Float.intBitsToFloat(0xFFC00000)));
912     // Distinct from +/- infinity.
913     Assert.assertFalse(Float.isNaN(Float.intBitsToFloat(0x7F800000)));
914     Assert.assertFalse(Float.isNaN(Float.intBitsToFloat(0xFF800000)));
915     // Distinct from normal numbers.
916     Assert.assertFalse(Float.isNaN(Float.intBitsToFloat(0x7F000000)));
917     Assert.assertFalse(Float.isNaN(Float.intBitsToFloat(0xFF000000)));
918     Assert.assertFalse(Float.isNaN(Float.intBitsToFloat(0x00800000)));
919     Assert.assertFalse(Float.isNaN(Float.intBitsToFloat(0x80800000)));
920     // Distinct from +/- zero.
921     Assert.assertFalse(Float.isNaN(Float.intBitsToFloat(0x00000000)));
922     Assert.assertFalse(Float.isNaN(Float.intBitsToFloat(0x80000000)));
923     // Distinct from subnormal numbers.
924     Assert.assertFalse(Float.isNaN(Float.intBitsToFloat(0x00400000)));
925     Assert.assertFalse(Float.isNaN(Float.intBitsToFloat(0x80400000)));
926     Assert.assertFalse(Float.isNaN(Float.intBitsToFloat(0x00000001)));
927     Assert.assertFalse(Float.isNaN(Float.intBitsToFloat(0x80000001)));
928   }
929 
930   public static void test_Math_isInfinite_D() {
931     // Distinct from Quiet NaN.
932     Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0x7FF4000000000000l)));
933     Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0xFFF4000000000000l)));
934     // Distinct from Signaling NaN.
935     Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0x7FF8000000000000l)));
936     Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0xFFF8000000000000l)));
937     // +/- infinity.
938     Assert.assertTrue(Double.isInfinite(Double.longBitsToDouble(0x7FF0000000000000l)));
939     Assert.assertTrue(Double.isInfinite(Double.longBitsToDouble(0xFFF0000000000000l)));
940     // Distinct from normal numbers.
941     Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0x7FE0000000000000l)));
942     Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0xFFE0000000000000l)));
943     Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0x0010000000000000l)));
944     Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0x8010000000000000l)));
945     // Distinct from +/- zero.
946     Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0x0000000000000000l)));
947     Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0x8000000000000000l)));
948     // Distinct from subnormal numbers.
949     Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0x0008000000000000l)));
950     Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0x8008000000000000l)));
951     Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0x0000000000000001l)));
952     Assert.assertFalse(Double.isInfinite(Double.longBitsToDouble(0x8000000000000001l)));
953   }
954 
955   public static void test_Math_isInfinite_F() {
956     // Distinct from Quiet NaN.
957     Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0x7FA00000)));
958     Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0xFFA00000)));
959     // Distinct from Signaling NaN.
960     Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0x7FC00000)));
961     Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0xFFC00000)));
962     // +/- infinity.
963     Assert.assertTrue(Float.isInfinite(Float.intBitsToFloat(0x7F800000)));
964     Assert.assertTrue(Float.isInfinite(Float.intBitsToFloat(0xFF800000)));
965     // Distinct from normal numbers.
966     Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0x7F000000)));
967     Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0xFF000000)));
968     Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0x00800000)));
969     Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0x80800000)));
970     // Distinct from +/- zero.
971     Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0x00000000)));
972     Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0x80000000)));
973     // Distinct from subnormal numbers.
974     Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0x00400000)));
975     Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0x80400000)));
976     Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0x00000001)));
977     Assert.assertFalse(Float.isInfinite(Float.intBitsToFloat(0x80000001)));
978   }
979 
980   public static void test_StrictMath_abs_I() {
981     StrictMath.abs(-1);
982     Assert.assertEquals(StrictMath.abs(0), 0);
983     Assert.assertEquals(StrictMath.abs(123), 123);
984     Assert.assertEquals(StrictMath.abs(-123), 123);
985     Assert.assertEquals(StrictMath.abs(Integer.MAX_VALUE), Integer.MAX_VALUE);
986     Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE), Integer.MIN_VALUE);
987     Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE - 1), Integer.MAX_VALUE);
988     Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE + 1), Integer.MAX_VALUE);
989   }
990 
991   public static void test_StrictMath_abs_J() {
992     StrictMath.abs(-1L);
993     Assert.assertEquals(StrictMath.abs(0L), 0L);
994     Assert.assertEquals(StrictMath.abs(123L), 123L);
995     Assert.assertEquals(StrictMath.abs(-123L), 123L);
996     Assert.assertEquals(StrictMath.abs(Long.MAX_VALUE), Long.MAX_VALUE);
997     Assert.assertEquals(StrictMath.abs(Long.MIN_VALUE), Long.MIN_VALUE);
998     Assert.assertEquals(StrictMath.abs(Long.MIN_VALUE - 1), Long.MAX_VALUE);
999   }
1000 
1001   public static void test_StrictMath_min_I() {
1002     StrictMath.min(1, 0);
1003     Assert.assertEquals(StrictMath.min(0, 0), 0);
1004     Assert.assertEquals(StrictMath.min(1, 0), 0);
1005     Assert.assertEquals(StrictMath.min(0, 1), 0);
1006     Assert.assertEquals(StrictMath.min(0, Integer.MAX_VALUE), 0);
1007     Assert.assertEquals(StrictMath.min(Integer.MIN_VALUE, 0), Integer.MIN_VALUE);
1008     Assert.assertEquals(StrictMath.min(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MIN_VALUE);
1009   }
1010 
1011   public static void test_StrictMath_max_I() {
1012     StrictMath.max(1, 0);
1013     Assert.assertEquals(StrictMath.max(0, 0), 0);
1014     Assert.assertEquals(StrictMath.max(1, 0), 1);
1015     Assert.assertEquals(StrictMath.max(0, 1), 1);
1016     Assert.assertEquals(StrictMath.max(0, Integer.MAX_VALUE), Integer.MAX_VALUE);
1017     Assert.assertEquals(StrictMath.max(Integer.MIN_VALUE, 0), 0);
1018     Assert.assertEquals(StrictMath.max(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MAX_VALUE);
1019   }
1020 
1021   public static void test_StrictMath_min_J() {
1022     StrictMath.min(1L, 0L);
1023     Assert.assertEquals(StrictMath.min(0L, 0L), 0L);
1024     Assert.assertEquals(StrictMath.min(1L, 0L), 0L);
1025     Assert.assertEquals(StrictMath.min(0L, 1L), 0L);
1026     Assert.assertEquals(StrictMath.min(0L, Long.MAX_VALUE), 0L);
1027     Assert.assertEquals(StrictMath.min(Long.MIN_VALUE, 0L), Long.MIN_VALUE);
1028     Assert.assertEquals(StrictMath.min(Long.MIN_VALUE, Long.MAX_VALUE), Long.MIN_VALUE);
1029   }
1030 
1031   public static void test_StrictMath_max_J() {
1032     StrictMath.max(1L, 0L);
1033     Assert.assertEquals(StrictMath.max(0L, 0L), 0L);
1034     Assert.assertEquals(StrictMath.max(1L, 0L), 1L);
1035     Assert.assertEquals(StrictMath.max(0L, 1L), 1L);
1036     Assert.assertEquals(StrictMath.max(0L, Long.MAX_VALUE), Long.MAX_VALUE);
1037     Assert.assertEquals(StrictMath.max(Long.MIN_VALUE, 0L), 0L);
1038     Assert.assertEquals(StrictMath.max(Long.MIN_VALUE, Long.MAX_VALUE), Long.MAX_VALUE);
1039   }
1040 
1041   public static void test_StrictMath_min_F() {
1042     StrictMath.min(1.0f, Float.NaN);
1043     Assert.assertTrue(Float.isNaN(StrictMath.min(1.0f, Float.NaN)));
1044     Assert.assertTrue(Float.isNaN(StrictMath.min(Float.NaN, 1.0f)));
1045     Assert.assertEquals(StrictMath.min(-0.0f, 0.0f), -0.0f);
1046     Assert.assertEquals(StrictMath.min(0.0f, -0.0f), -0.0f);
1047     Assert.assertEquals(StrictMath.min(-0.0f, -0.0f), -0.0f);
1048     Assert.assertEquals(StrictMath.min(0.0f, 0.0f), 0.0f);
1049     Assert.assertEquals(StrictMath.min(1.0f, 0.0f), 0.0f);
1050     Assert.assertEquals(StrictMath.min(0.0f, 1.0f), 0.0f);
1051     Assert.assertEquals(StrictMath.min(0.0f, Float.MAX_VALUE), 0.0f);
1052     Assert.assertEquals(StrictMath.min(Float.MIN_VALUE, 0.0f), 0.0f);
1053     Assert.assertEquals(StrictMath.min(Float.MIN_VALUE, Float.MAX_VALUE), Float.MIN_VALUE);
1054   }
1055 
1056   public static void test_StrictMath_max_F() {
1057     StrictMath.max(1.0f, Float.NaN);
1058     Assert.assertTrue(Float.isNaN(StrictMath.max(1.0f, Float.NaN)));
1059     Assert.assertTrue(Float.isNaN(StrictMath.max(Float.NaN, 1.0f)));
1060     Assert.assertEquals(StrictMath.max(-0.0f, 0.0f), 0.0f);
1061     Assert.assertEquals(StrictMath.max(0.0f, -0.0f), 0.0f);
1062     Assert.assertEquals(StrictMath.max(-0.0f, -0.0f), -0.0f);
1063     Assert.assertEquals(StrictMath.max(0.0f, 0.0f), 0.0f);
1064     Assert.assertEquals(StrictMath.max(1.0f, 0.0f), 1.0f);
1065     Assert.assertEquals(StrictMath.max(0.0f, 1.0f), 1.0f);
1066     Assert.assertEquals(StrictMath.max(0.0f, Float.MAX_VALUE), Float.MAX_VALUE);
1067     Assert.assertEquals(StrictMath.max(Float.MIN_VALUE, 0.0f), Float.MIN_VALUE);
1068     Assert.assertEquals(StrictMath.max(Float.MIN_VALUE, Float.MAX_VALUE), Float.MAX_VALUE);
1069   }
1070 
1071   public static void test_StrictMath_min_D() {
1072     StrictMath.min(1.0d, Double.NaN);
1073     Assert.assertTrue(Double.isNaN(StrictMath.min(1.0d, Double.NaN)));
1074     Assert.assertTrue(Double.isNaN(StrictMath.min(Double.NaN, 1.0d)));
1075     Assert.assertEquals(StrictMath.min(-0.0d, 0.0d), -0.0d);
1076     Assert.assertEquals(StrictMath.min(0.0d, -0.0d), -0.0d);
1077     Assert.assertEquals(StrictMath.min(-0.0d, -0.0d), -0.0d);
1078     Assert.assertEquals(StrictMath.min(0.0d, 0.0d), 0.0d);
1079     Assert.assertEquals(StrictMath.min(1.0d, 0.0d), 0.0d);
1080     Assert.assertEquals(StrictMath.min(0.0d, 1.0d), 0.0d);
1081     Assert.assertEquals(StrictMath.min(0.0d, Double.MAX_VALUE), 0.0d);
1082     Assert.assertEquals(StrictMath.min(Double.MIN_VALUE, 0.0d), 0.0d);
1083     Assert.assertEquals(StrictMath.min(Double.MIN_VALUE, Double.MAX_VALUE), Double.MIN_VALUE);
1084   }
1085 
1086   public static void test_StrictMath_max_D() {
1087     StrictMath.max(1.0d, Double.NaN);
1088     Assert.assertTrue(Double.isNaN(StrictMath.max(1.0d, Double.NaN)));
1089     Assert.assertTrue(Double.isNaN(StrictMath.max(Double.NaN, 1.0d)));
1090     Assert.assertEquals(StrictMath.max(-0.0d, 0.0d), 0.0d);
1091     Assert.assertEquals(StrictMath.max(0.0d, -0.0d), 0.0d);
1092     Assert.assertEquals(StrictMath.max(-0.0d, -0.0d), -0.0d);
1093     Assert.assertEquals(StrictMath.max(0.0d, 0.0d), 0.0d);
1094     Assert.assertEquals(StrictMath.max(1.0d, 0.0d), 1.0d);
1095     Assert.assertEquals(StrictMath.max(0.0d, 1.0d), 1.0d);
1096     Assert.assertEquals(StrictMath.max(0.0d, Double.MAX_VALUE), Double.MAX_VALUE);
1097     Assert.assertEquals(StrictMath.max(Double.MIN_VALUE, 0.0d), Double.MIN_VALUE);
1098     Assert.assertEquals(StrictMath.max(Double.MIN_VALUE, Double.MAX_VALUE), Double.MAX_VALUE);
1099   }
1100 
1101   public static void test_StrictMath_sqrt() {
1102     StrictMath.sqrt(+4.0);
1103     Assert.assertEquals(StrictMath.sqrt(+4.0), +2.0d, 0.0);
1104     Assert.assertEquals(StrictMath.sqrt(+49.0), +7.0d, 0.0);
1105     Assert.assertEquals(StrictMath.sqrt(+1.44), +1.2d, 0.0);
1106   }
1107 
1108   public static void test_StrictMath_ceil() {
1109     StrictMath.ceil(-0.9);
1110     Assert.assertEquals(StrictMath.ceil(+0.0), +0.0d, 0.0);
1111     Assert.assertEquals(StrictMath.ceil(-0.0), -0.0d, 0.0);
1112     Assert.assertEquals(StrictMath.ceil(-0.9), -0.0d, 0.0);
1113     Assert.assertEquals(StrictMath.ceil(-0.5), -0.0d, 0.0);
1114     Assert.assertEquals(StrictMath.ceil(0.0), -0.0d, 0.0);
1115     Assert.assertEquals(StrictMath.ceil(+2.0), +2.0d, 0.0);
1116     Assert.assertEquals(StrictMath.ceil(+2.1), +3.0d, 0.0);
1117     Assert.assertEquals(StrictMath.ceil(+2.5), +3.0d, 0.0);
1118     Assert.assertEquals(StrictMath.ceil(+2.9), +3.0d, 0.0);
1119     Assert.assertEquals(StrictMath.ceil(+3.0), +3.0d, 0.0);
1120     Assert.assertEquals(StrictMath.ceil(-2.0), -2.0d, 0.0);
1121     Assert.assertEquals(StrictMath.ceil(-2.1), -2.0d, 0.0);
1122     Assert.assertEquals(StrictMath.ceil(-2.5), -2.0d, 0.0);
1123     Assert.assertEquals(StrictMath.ceil(-2.9), -2.0d, 0.0);
1124     Assert.assertEquals(StrictMath.ceil(-3.0), -3.0d, 0.0);
1125     Assert.assertEquals(StrictMath.ceil(Double.NaN), Double.NaN, 0.0);
1126     Assert.assertEquals(StrictMath.ceil(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
1127     Assert.assertEquals(StrictMath.ceil(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
1128   }
1129 
1130   public static void test_StrictMath_floor() {
1131     StrictMath.floor(+2.1);
1132     Assert.assertEquals(StrictMath.floor(+0.0), +0.0d, 0.0);
1133     Assert.assertEquals(StrictMath.floor(-0.0), -0.0d, 0.0);
1134     Assert.assertEquals(StrictMath.floor(+2.0), +2.0d, 0.0);
1135     Assert.assertEquals(StrictMath.floor(+2.1), +2.0d, 0.0);
1136     Assert.assertEquals(StrictMath.floor(+2.5), +2.0d, 0.0);
1137     Assert.assertEquals(StrictMath.floor(+2.9), +2.0d, 0.0);
1138     Assert.assertEquals(StrictMath.floor(+3.0), +3.0d, 0.0);
1139     Assert.assertEquals(StrictMath.floor(-2.0), -2.0d, 0.0);
1140     Assert.assertEquals(StrictMath.floor(-2.1), -3.0d, 0.0);
1141     Assert.assertEquals(StrictMath.floor(-2.5), -3.0d, 0.0);
1142     Assert.assertEquals(StrictMath.floor(-2.9), -3.0d, 0.0);
1143     Assert.assertEquals(StrictMath.floor(-3.0), -3.0d, 0.0);
1144     Assert.assertEquals(StrictMath.floor(Double.NaN), Double.NaN, 0.0);
1145     Assert.assertEquals(StrictMath.floor(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
1146     Assert.assertEquals(StrictMath.floor(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
1147   }
1148 
1149   public static void test_StrictMath_rint() {
1150     StrictMath.rint(+2.1);
1151     Assert.assertEquals(StrictMath.rint(+0.0), +0.0d, 0.0);
1152     Assert.assertEquals(StrictMath.rint(-0.0), -0.0d, 0.0);
1153     Assert.assertEquals(StrictMath.rint(+2.0), +2.0d, 0.0);
1154     Assert.assertEquals(StrictMath.rint(+2.1), +2.0d, 0.0);
1155     Assert.assertEquals(StrictMath.rint(+2.5), +2.0d, 0.0);
1156     Assert.assertEquals(StrictMath.rint(+2.9), +3.0d, 0.0);
1157     Assert.assertEquals(StrictMath.rint(+3.0), +3.0d, 0.0);
1158     Assert.assertEquals(StrictMath.rint(-2.0), -2.0d, 0.0);
1159     Assert.assertEquals(StrictMath.rint(-2.1), -2.0d, 0.0);
1160     Assert.assertEquals(StrictMath.rint(-2.5), -2.0d, 0.0);
1161     Assert.assertEquals(StrictMath.rint(-2.9), -3.0d, 0.0);
1162     Assert.assertEquals(StrictMath.rint(-3.0), -3.0d, 0.0);
1163     Assert.assertEquals(StrictMath.rint(Double.NaN), Double.NaN, 0.0);
1164     Assert.assertEquals(StrictMath.rint(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
1165     Assert.assertEquals(StrictMath.rint(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
1166   }
1167 
1168   public static void test_StrictMath_round_D() {
1169     StrictMath.round(2.1d);
1170     Assert.assertEquals(StrictMath.round(+0.0d), (long)+0.0);
1171     Assert.assertEquals(StrictMath.round(-0.0d), (long)+0.0);
1172     Assert.assertEquals(StrictMath.round(2.0d), 2l);
1173     Assert.assertEquals(StrictMath.round(2.1d), 2l);
1174     Assert.assertEquals(StrictMath.round(2.5d), 3l);
1175     Assert.assertEquals(StrictMath.round(2.9d), 3l);
1176     Assert.assertEquals(StrictMath.round(3.0d), 3l);
1177     Assert.assertEquals(StrictMath.round(-2.0d), -2l);
1178     Assert.assertEquals(StrictMath.round(-2.1d), -2l);
1179     Assert.assertEquals(StrictMath.round(-2.5d), -2l);
1180     Assert.assertEquals(StrictMath.round(-2.9d), -3l);
1181     Assert.assertEquals(StrictMath.round(-3.0d), -3l);
1182     Assert.assertEquals(StrictMath.round(0.49999999999999994d), 0l);
1183     Assert.assertEquals(StrictMath.round(4503599627370495.0d), 4503599627370495l);  // 2^52 - 1
1184     Assert.assertEquals(StrictMath.round(4503599627370495.5d), 4503599627370496l);  // 2^52 - 0.5
1185     Assert.assertEquals(StrictMath.round(4503599627370496.0d), 4503599627370496l);  // 2^52
1186     Assert.assertEquals(StrictMath.round(-4503599627370495.0d), -4503599627370495l);  // -(2^52 - 1)
1187     Assert.assertEquals(StrictMath.round(-4503599627370495.5d), -4503599627370495l);  // -(2^52 - 0.5)
1188     Assert.assertEquals(StrictMath.round(-4503599627370496.0d), -4503599627370496l);  // -2^52
1189     Assert.assertEquals(StrictMath.round(9007199254740991.0d), 9007199254740991l);  // 2^53 - 1
1190     Assert.assertEquals(StrictMath.round(-9007199254740991.0d), -9007199254740991l);  // -(2^53 - 1)
1191     Assert.assertEquals(StrictMath.round(Double.NaN), (long)+0.0d);
1192     Assert.assertEquals(StrictMath.round(Long.MAX_VALUE + 1.0d), Long.MAX_VALUE);
1193     Assert.assertEquals(StrictMath.round(Long.MIN_VALUE - 1.0d), Long.MIN_VALUE);
1194     Assert.assertEquals(StrictMath.round(Double.longBitsToDouble(0x43F0000000000000l)),
1195                         Long.MAX_VALUE); // 2^64
1196     Assert.assertEquals(StrictMath.round(Double.longBitsToDouble(0xC3F0000000000000l)),
1197                         Long.MIN_VALUE); // -2^64
1198     Assert.assertEquals(StrictMath.round(Double.POSITIVE_INFINITY), Long.MAX_VALUE);
1199     Assert.assertEquals(StrictMath.round(Double.NEGATIVE_INFINITY), Long.MIN_VALUE);
1200   }
1201 
1202   public static void test_StrictMath_round_F() {
1203     StrictMath.round(2.1f);
1204     Assert.assertEquals(StrictMath.round(+0.0f), (int)+0.0);
1205     Assert.assertEquals(StrictMath.round(-0.0f), (int)+0.0);
1206     Assert.assertEquals(StrictMath.round(2.0f), 2);
1207     Assert.assertEquals(StrictMath.round(2.1f), 2);
1208     Assert.assertEquals(StrictMath.round(2.5f), 3);
1209     Assert.assertEquals(StrictMath.round(2.9f), 3);
1210     Assert.assertEquals(StrictMath.round(3.0f), 3);
1211     Assert.assertEquals(StrictMath.round(-2.0f), -2);
1212     Assert.assertEquals(StrictMath.round(-2.1f), -2);
1213     Assert.assertEquals(StrictMath.round(-2.5f), -2);
1214     Assert.assertEquals(StrictMath.round(-2.9f), -3);
1215     Assert.assertEquals(StrictMath.round(-3.0f), -3);
1216     // 0.4999999701976776123046875
1217     Assert.assertEquals(StrictMath.round(Float.intBitsToFloat(0x3EFFFFFF)), (int)+0.0f);
1218     Assert.assertEquals(StrictMath.round(8388607.0f), 8388607);  // 2^23 - 1
1219     Assert.assertEquals(StrictMath.round(8388607.5f), 8388608);  // 2^23 - 0.5
1220     Assert.assertEquals(StrictMath.round(8388608.0f), 8388608);  // 2^23
1221     Assert.assertEquals(StrictMath.round(-8388607.0f), -8388607);  // -(2^23 - 1)
1222     Assert.assertEquals(StrictMath.round(-8388607.5f), -8388607);  // -(2^23 - 0.5)
1223     Assert.assertEquals(StrictMath.round(-8388608.0f), -8388608);  // -2^23
1224     Assert.assertEquals(StrictMath.round(16777215.0f), 16777215);  // 2^24 - 1
1225     Assert.assertEquals(StrictMath.round(16777216.0f), 16777216);  // 2^24
1226     Assert.assertEquals(StrictMath.round(-16777215.0f), -16777215);  // -(2^24 - 1)
1227     Assert.assertEquals(StrictMath.round(-16777216.0f), -16777216);  // -2^24
1228     Assert.assertEquals(StrictMath.round(Float.NaN), (int)+0.0f);
1229     Assert.assertEquals(StrictMath.round(Integer.MAX_VALUE + 1.0f), Integer.MAX_VALUE);
1230     Assert.assertEquals(StrictMath.round(Integer.MIN_VALUE - 1.0f), Integer.MIN_VALUE);
1231     Assert.assertEquals(StrictMath.round(Float.intBitsToFloat(0x4F800000)),
1232                         Integer.MAX_VALUE); // 2^32
1233     Assert.assertEquals(StrictMath.round(Float.intBitsToFloat(0xCF800000)),
1234                         Integer.MIN_VALUE); // -2^32
1235     Assert.assertEquals(StrictMath.round(Float.POSITIVE_INFINITY), Integer.MAX_VALUE);
1236     Assert.assertEquals(StrictMath.round(Float.NEGATIVE_INFINITY), Integer.MIN_VALUE);
1237   }
1238 
1239   public static void test_Float_floatToRawIntBits() {
1240     Float.floatToRawIntBits(-1.0f);
1241     Assert.assertEquals(Float.floatToRawIntBits(-1.0f), 0xbf800000);
1242     Assert.assertEquals(Float.floatToRawIntBits(0.0f), 0);
1243     Assert.assertEquals(Float.floatToRawIntBits(1.0f), 0x3f800000);
1244     Assert.assertEquals(Float.floatToRawIntBits(Float.NaN), 0x7fc00000);
1245     Assert.assertEquals(Float.floatToRawIntBits(Float.POSITIVE_INFINITY), 0x7f800000);
1246     Assert.assertEquals(Float.floatToRawIntBits(Float.NEGATIVE_INFINITY), 0xff800000);
1247   }
1248 
1249   public static void test_Float_intBitsToFloat() {
1250     Float.intBitsToFloat(0xbf800000);
1251     Assert.assertEquals(Float.intBitsToFloat(0xbf800000), -1.0f);
1252     Assert.assertEquals(Float.intBitsToFloat(0x00000000), 0.0f);
1253     Assert.assertEquals(Float.intBitsToFloat(0x3f800000), 1.0f);
1254     Assert.assertEquals(Float.intBitsToFloat(0x7fc00000), Float.NaN);
1255     Assert.assertEquals(Float.intBitsToFloat(0x7f800000), Float.POSITIVE_INFINITY);
1256     Assert.assertEquals(Float.intBitsToFloat(0xff800000), Float.NEGATIVE_INFINITY);
1257   }
1258 
1259   public static void test_Double_doubleToRawLongBits() {
1260     Double.doubleToRawLongBits(-1.0);
1261     Assert.assertEquals(Double.doubleToRawLongBits(-1.0), 0xbff0000000000000L);
1262     Assert.assertEquals(Double.doubleToRawLongBits(0.0), 0x0000000000000000L);
1263     Assert.assertEquals(Double.doubleToRawLongBits(1.0), 0x3ff0000000000000L);
1264     Assert.assertEquals(Double.doubleToRawLongBits(Double.NaN), 0x7ff8000000000000L);
1265     Assert.assertEquals(Double.doubleToRawLongBits(Double.POSITIVE_INFINITY), 0x7ff0000000000000L);
1266     Assert.assertEquals(Double.doubleToRawLongBits(Double.NEGATIVE_INFINITY), 0xfff0000000000000L);
1267   }
1268 
1269   public static void test_Double_longBitsToDouble() {
1270     Double.longBitsToDouble(0xbff0000000000000L);
1271     Assert.assertEquals(Double.longBitsToDouble(0xbff0000000000000L), -1.0);
1272     Assert.assertEquals(Double.longBitsToDouble(0x0000000000000000L), 0.0);
1273     Assert.assertEquals(Double.longBitsToDouble(0x3ff0000000000000L), 1.0);
1274     Assert.assertEquals(Double.longBitsToDouble(0x7ff8000000000000L), Double.NaN);
1275     Assert.assertEquals(Double.longBitsToDouble(0x7ff0000000000000L), Double.POSITIVE_INFINITY);
1276     Assert.assertEquals(Double.longBitsToDouble(0xfff0000000000000L), Double.NEGATIVE_INFINITY);
1277   }
1278 
1279   public static void test_Short_reverseBytes() {
1280       Short.reverseBytes((short)0x1357);
1281       Assert.assertEquals(Short.reverseBytes((short)0x0000), (short)0x0000);
1282       Assert.assertEquals(Short.reverseBytes((short)0xffff), (short)0xffff);
1283       Assert.assertEquals(Short.reverseBytes((short)0x8000), (short)0x0080);
1284       Assert.assertEquals(Short.reverseBytes((short)0x0080), (short)0x8000);
1285       Assert.assertEquals(Short.reverseBytes((short)0x0123), (short)0x2301);
1286       Assert.assertEquals(Short.reverseBytes((short)0x4567), (short)0x6745);
1287       Assert.assertEquals(Short.reverseBytes((short)0x89ab), (short)0xab89);
1288       Assert.assertEquals(Short.reverseBytes((short)0xcdef), (short)0xefcd);
1289   }
1290 
1291   public static void test_Integer_reverseBytes() {
1292       Integer.reverseBytes(0x13579bdf);
1293       Assert.assertEquals(Integer.reverseBytes(0x00000000), 0x00000000);
1294       Assert.assertEquals(Integer.reverseBytes(0xffffffff), 0xffffffff);
1295       Assert.assertEquals(Integer.reverseBytes(0x80000000), 0x00000080);
1296       Assert.assertEquals(Integer.reverseBytes(0x00000080), 0x80000000);
1297       Assert.assertEquals(Integer.reverseBytes(0x01234567), 0x67452301);
1298       Assert.assertEquals(Integer.reverseBytes(0x89abcdef), 0xefcdab89);
1299   }
1300 
1301   public static void test_Long_reverseBytes() {
1302       Long.reverseBytes(0x13579bdf2468ace0L);
1303       Assert.assertEquals(Long.reverseBytes(0x0000000000000000L), 0x0000000000000000L);
1304       Assert.assertEquals(Long.reverseBytes(0xffffffffffffffffL), 0xffffffffffffffffL);
1305       Assert.assertEquals(Long.reverseBytes(0x8000000000000000L), 0x0000000000000080L);
1306       Assert.assertEquals(Long.reverseBytes(0x0000000000000080L), 0x8000000000000000L);
1307       Assert.assertEquals(Long.reverseBytes(0x0123456789abcdefL), 0xefcdab8967452301L);
1308   }
1309 
1310   public static void test_Integer_reverse() {
1311     Integer.reverse(0x12345678);
1312     Assert.assertEquals(Integer.reverse(1), 0x80000000);
1313     Assert.assertEquals(Integer.reverse(-1), 0xffffffff);
1314     Assert.assertEquals(Integer.reverse(0), 0);
1315     Assert.assertEquals(Integer.reverse(0x12345678), 0x1e6a2c48);
1316     Assert.assertEquals(Integer.reverse(0x87654321), 0x84c2a6e1);
1317     Assert.assertEquals(Integer.reverse(Integer.MAX_VALUE), 0xfffffffe);
1318     Assert.assertEquals(Integer.reverse(Integer.MIN_VALUE), 1);
1319   }
1320 
1321   public static void test_Long_reverse() {
1322     Long.reverse(0x1234567812345678L);
1323     Assert.assertEquals(Long.reverse(1L), 0x8000000000000000L);
1324     Assert.assertEquals(Long.reverse(-1L), 0xffffffffffffffffL);
1325     Assert.assertEquals(Long.reverse(0L), 0L);
1326     Assert.assertEquals(Long.reverse(0x1234567812345678L), 0x1e6a2c481e6a2c48L);
1327     Assert.assertEquals(Long.reverse(0x8765432187654321L), 0x84c2a6e184c2a6e1L);
1328     Assert.assertEquals(Long.reverse(Long.MAX_VALUE), 0xfffffffffffffffeL);
1329     Assert.assertEquals(Long.reverse(Long.MIN_VALUE), 1L);
1330 
1331     Assert.assertEquals(test_Long_reverse_b22324327(0xaaaaaaaaaaaaaaaaL, 0x5555555555555555L),
1332             157472205507277347L);
1333   }
1334 
1335   // A bit more complicated than the above. Use local variables to stress register allocation.
1336   private static long test_Long_reverse_b22324327(long l1, long l2) {
1337     // A couple of local integers. Use them in a loop, so they get promoted.
1338     int i1 = 0, i2 = 1, i3 = 2, i4 = 3, i5 = 4, i6 = 5, i7 = 6, i8 = 7;
1339     for (int k = 0; k < 10; k++) {
1340       i1 += 1;
1341       i2 += 2;
1342       i3 += 3;
1343       i4 += 4;
1344       i5 += 5;
1345       i6 += 6;
1346       i7 += 7;
1347       i8 += 8;
1348     }
1349 
1350     // Do the Long.reverse() calls, save the results.
1351     long r1 = Long.reverse(l1);
1352     long r2 = Long.reverse(l2);
1353 
1354     // Some more looping with the ints.
1355     for (int k = 0; k < 10; k++) {
1356       i1 += 1;
1357       i2 += 2;
1358       i3 += 3;
1359       i4 += 4;
1360       i5 += 5;
1361       i6 += 6;
1362       i7 += 7;
1363       i8 += 8;
1364     }
1365 
1366     // Include everything in the result, so things are kept live. Try to be a little bit clever to
1367     // avoid things being folded somewhere.
1368     return (r1 / i1) + (r2 / i2) + i3 + i4 + i5 + i6 + i7 + i8;
1369   }
1370 
1371   public static boolean doThrow = false;
1372 
1373   public static int $noinline$return_int_zero() {
1374     if (doThrow) {
1375       throw new Error();
1376     }
1377     return 0;
1378   }
1379 
1380   public static void test_Integer_divideUnsigned() {
1381     Assert.assertEquals(Integer.divideUnsigned(100, 10), 10);
1382     Assert.assertEquals(Integer.divideUnsigned(100, 1), 100);
1383     Assert.assertEquals(Integer.divideUnsigned(1024, 128), 8);
1384     Assert.assertEquals(Integer.divideUnsigned(12345678, 264), 46763);
1385     Assert.assertEquals(Integer.divideUnsigned(13, 5), 2);
1386     Assert.assertEquals(Integer.divideUnsigned(-2, 2), Integer.MAX_VALUE);
1387     Assert.assertEquals(Integer.divideUnsigned(-1, 2), Integer.MAX_VALUE);
1388     Assert.assertEquals(Integer.divideUnsigned(100000, -1), 0);
1389     Assert.assertEquals(Integer.divideUnsigned(Integer.MAX_VALUE, -1), 0);
1390     Assert.assertEquals(Integer.divideUnsigned(-2, -1), 0);
1391     Assert.assertEquals(Integer.divideUnsigned(-173448, 13), 330368757);
1392     Assert.assertEquals(Integer.divideUnsigned(Integer.MIN_VALUE, 2), (1 << 30));
1393     Assert.assertEquals(Integer.divideUnsigned(-1, Integer.MIN_VALUE), 1);
1394     Assert.assertEquals(Integer.divideUnsigned(Integer.MAX_VALUE, Integer.MIN_VALUE), 0);
1395     Assert.assertEquals(Integer.divideUnsigned(Integer.MIN_VALUE, Integer.MAX_VALUE), 1);
1396 
1397     try {
1398       Integer.divideUnsigned(1, 0);
1399       Assert.fail("Unreachable");
1400     } catch (ArithmeticException expected) {
1401     }
1402   }
1403 
1404   public static void test_Integer_numberOfLeadingZeros() {
1405     Assert.assertEquals(Integer.numberOfLeadingZeros(0), Integer.SIZE);
1406     Assert.assertEquals(Integer.numberOfLeadingZeros(1), Integer.SIZE - 1);
1407     Assert.assertEquals(Integer.numberOfLeadingZeros(1 << (Integer.SIZE-1)), 0);
1408     Assert.assertEquals(Integer.numberOfLeadingZeros($noinline$return_int_zero()), Integer.SIZE);
1409     for (int i = 0; i < Integer.SIZE; i++) {
1410         Assert.assertEquals(Integer.numberOfLeadingZeros(1 << i), Integer.SIZE - 1 - i);
1411         Assert.assertEquals(Integer.numberOfLeadingZeros((1 << i) | 1), Integer.SIZE - 1 - i);
1412         Assert.assertEquals(Integer.numberOfLeadingZeros(0xFFFFFFFF >>> i), i);
1413     }
1414   }
1415 
1416   public static long $noinline$return_long_zero() {
1417     if (doThrow) {
1418       throw new Error();
1419     }
1420     return 0;
1421   }
1422 
1423   public static void test_Long_numberOfLeadingZeros() {
1424     Assert.assertEquals(Long.numberOfLeadingZeros(0L), Long.SIZE);
1425     Assert.assertEquals(Long.numberOfLeadingZeros(1L), Long.SIZE - 1);
1426     Assert.assertEquals(Long.numberOfLeadingZeros(1L << ((Long.SIZE/2)-1)), Long.SIZE/2);
1427     Assert.assertEquals(Long.numberOfLeadingZeros(1L << (Long.SIZE-1)), 0);
1428     Assert.assertEquals(Long.numberOfLeadingZeros($noinline$return_long_zero()), Long.SIZE);
1429     for (int i = 0; i < Long.SIZE; i++) {
1430         Assert.assertEquals(Long.numberOfLeadingZeros(1L << i), Long.SIZE - 1 - i);
1431         Assert.assertEquals(Long.numberOfLeadingZeros((1L << i) | 1L), Long.SIZE - 1 - i);
1432         Assert.assertEquals(Long.numberOfLeadingZeros(0xFFFFFFFFFFFFFFFFL >>> i), i);
1433     }
1434   }
1435 
1436   static Object runtime;
1437   static Method address_of;
1438   static Method new_non_movable_array;
1439   static Method peek_byte;
1440   static Method peek_short;
1441   static Method peek_int;
1442   static Method peek_long;
1443   static Method poke_byte;
1444   static Method poke_short;
1445   static Method poke_int;
1446   static Method poke_long;
1447 
1448   public static void initSupportMethodsForPeekPoke() throws Exception {
1449     Class<?> vm_runtime = Class.forName("dalvik.system.VMRuntime");
1450     Method get_runtime = vm_runtime.getDeclaredMethod("getRuntime");
1451     runtime = get_runtime.invoke(null);
1452     address_of = vm_runtime.getDeclaredMethod("addressOf", Object.class);
1453     new_non_movable_array = vm_runtime.getDeclaredMethod("newNonMovableArray", Class.class, Integer.TYPE);
1454 
1455     Class<?> io_memory = Class.forName("libcore.io.Memory");
1456     peek_byte = io_memory.getDeclaredMethod("peekByte", Long.TYPE);
1457     peek_int = io_memory.getDeclaredMethod("peekInt", Long.TYPE, Boolean.TYPE);
1458     peek_short = io_memory.getDeclaredMethod("peekShort", Long.TYPE, Boolean.TYPE);
1459     peek_long = io_memory.getDeclaredMethod("peekLong", Long.TYPE, Boolean.TYPE);
1460     poke_byte = io_memory.getDeclaredMethod("pokeByte", Long.TYPE, Byte.TYPE);
1461     poke_short = io_memory.getDeclaredMethod("pokeShort", Long.TYPE, Short.TYPE, Boolean.TYPE);
1462     poke_int = io_memory.getDeclaredMethod("pokeInt", Long.TYPE, Integer.TYPE, Boolean.TYPE);
1463     poke_long = io_memory.getDeclaredMethod("pokeLong", Long.TYPE, Long.TYPE, Boolean.TYPE);
1464   }
1465 
1466   public static void test_Memory_peekByte() throws Exception {
1467     byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 2);
1468     b[0] = 0x12;
1469     b[1] = 0x11;
1470     long address = (long)address_of.invoke(runtime, b);
1471     Assert.assertEquals((byte)peek_byte.invoke(null, address), 0x12);
1472     Assert.assertEquals((byte)peek_byte.invoke(null, address + 1), 0x11);
1473   }
1474 
1475   public static void test_Memory_peekShort() throws Exception {
1476     byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 3);
1477     b[0] = 0x13;
1478     b[1] = 0x12;
1479     b[2] = 0x11;
1480     long address = (long)address_of.invoke(runtime, b);
1481     peek_short.invoke(null, address, false);
1482     Assert.assertEquals((short)peek_short.invoke(null, address, false), 0x1213);  // Aligned read
1483     Assert.assertEquals((short)peek_short.invoke(null, address + 1, false), 0x1112);  // Unaligned read
1484   }
1485 
1486   public static void test_Memory_peekInt() throws Exception {
1487     byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 5);
1488     b[0] = 0x15;
1489     b[1] = 0x14;
1490     b[2] = 0x13;
1491     b[3] = 0x12;
1492     b[4] = 0x11;
1493     long address = (long)address_of.invoke(runtime, b);
1494     peek_int.invoke(null, address, false);
1495     Assert.assertEquals((int)peek_int.invoke(null, address, false), 0x12131415);
1496     Assert.assertEquals((int)peek_int.invoke(null, address + 1, false), 0x11121314);
1497   }
1498 
1499   public static void test_Memory_peekLong() throws Exception {
1500     byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 9);
1501     b[0] = 0x19;
1502     b[1] = 0x18;
1503     b[2] = 0x17;
1504     b[3] = 0x16;
1505     b[4] = 0x15;
1506     b[5] = 0x14;
1507     b[6] = 0x13;
1508     b[7] = 0x12;
1509     b[8] = 0x11;
1510     long address = (long)address_of.invoke(runtime, b);
1511     peek_long.invoke(null, address, false);
1512     Assert.assertEquals((long)peek_long.invoke(null, address, false), 0x1213141516171819L);
1513     Assert.assertEquals((long)peek_long.invoke(null, address + 1, false), 0x1112131415161718L);
1514   }
1515 
1516   public static void test_Memory_pokeByte() throws Exception {
1517     byte[] r = {0x11, 0x12};
1518     byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 2);
1519     long address = (long)address_of.invoke(runtime, b);
1520     poke_byte.invoke(null, address, (byte)0x11);
1521     poke_byte.invoke(null, address + 1, (byte)0x12);
1522     Assert.assertTrue(Arrays.equals(r, b));
1523   }
1524 
1525   public static void test_Memory_pokeShort() throws Exception {
1526     byte[] ra = {0x12, 0x11, 0x13};
1527     byte[] ru = {0x12, 0x22, 0x21};
1528     byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 3);
1529     long address = (long)address_of.invoke(runtime, b);
1530 
1531     // Aligned write
1532     b[2] = 0x13;
1533     poke_short.invoke(null, address, (short)0x1112, false);
1534     Assert.assertTrue(Arrays.equals(ra, b));
1535 
1536     // Unaligned write
1537     poke_short.invoke(null, address + 1, (short)0x2122, false);
1538     Assert.assertTrue(Arrays.equals(ru, b));
1539   }
1540 
1541   public static void test_Memory_pokeInt() throws Exception {
1542     byte[] ra = {0x14, 0x13, 0x12, 0x11, 0x15};
1543     byte[] ru = {0x14, 0x24, 0x23, 0x22, 0x21};
1544     byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 5);
1545     long address = (long)address_of.invoke(runtime, b);
1546 
1547     b[4] = 0x15;
1548     poke_int.invoke(null, address, (int)0x11121314, false);
1549     Assert.assertTrue(Arrays.equals(ra, b));
1550 
1551     poke_int.invoke(null, address + 1, (int)0x21222324, false);
1552     Assert.assertTrue(Arrays.equals(ru, b));
1553   }
1554 
1555   public static void test_Memory_pokeLong() throws Exception {
1556     byte[] ra = {0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x19};
1557     byte[] ru = {0x18, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21};
1558     byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 9);
1559     long address = (long)address_of.invoke(runtime, b);
1560 
1561     b[8] = 0x19;
1562     poke_long.invoke(null, address, (long)0x1112131415161718L, false);
1563     Assert.assertTrue(Arrays.equals(ra, b));
1564 
1565     poke_long.invoke(null, address + 1, (long)0x2122232425262728L, false);
1566     Assert.assertTrue(Arrays.equals(ru, b));
1567   }
1568 
1569   public static void test_Integer_numberOfTrailingZeros() {
1570     Assert.assertEquals(Integer.numberOfTrailingZeros(0), Integer.SIZE);
1571     for (int i = 0; i < Integer.SIZE; i++) {
1572       Assert.assertEquals(
1573         Integer.numberOfTrailingZeros(0x80000000 >> i),
1574         Integer.SIZE - 1 - i);
1575       Assert.assertEquals(
1576         Integer.numberOfTrailingZeros((0x80000000 >> i) | 0x80000000),
1577         Integer.SIZE - 1 - i);
1578       Assert.assertEquals(Integer.numberOfTrailingZeros(1 << i), i);
1579     }
1580   }
1581 
1582   public static void test_Long_numberOfTrailingZeros() {
1583     Assert.assertEquals(Long.numberOfTrailingZeros(0), Long.SIZE);
1584     for (int i = 0; i < Long.SIZE; i++) {
1585       Assert.assertEquals(
1586         Long.numberOfTrailingZeros(0x8000000000000000L >> i),
1587         Long.SIZE - 1 - i);
1588       Assert.assertEquals(
1589         Long.numberOfTrailingZeros((0x8000000000000000L >> i) | 0x8000000000000000L),
1590         Long.SIZE - 1 - i);
1591       Assert.assertEquals(Long.numberOfTrailingZeros(1L << i), i);
1592     }
1593   }
1594 
1595   public static void test_Integer_rotateRight() throws Exception {
1596     Assert.assertEquals(Integer.rotateRight(0x11, 0), 0x11);
1597 
1598     Assert.assertEquals(Integer.rotateRight(0x11, 1), 0x80000008);
1599     Assert.assertEquals(Integer.rotateRight(0x11, Integer.SIZE - 1), 0x22);
1600     Assert.assertEquals(Integer.rotateRight(0x11, Integer.SIZE), 0x11);
1601     Assert.assertEquals(Integer.rotateRight(0x11, Integer.SIZE + 1), 0x80000008);
1602 
1603     Assert.assertEquals(Integer.rotateRight(0x11, -1), 0x22);
1604     Assert.assertEquals(Integer.rotateRight(0x11, -(Integer.SIZE - 1)), 0x80000008);
1605     Assert.assertEquals(Integer.rotateRight(0x11, -Integer.SIZE), 0x11);
1606     Assert.assertEquals(Integer.rotateRight(0x11, -(Integer.SIZE + 1)), 0x22);
1607 
1608     Assert.assertEquals(Integer.rotateRight(0x80000000, 1), 0x40000000);
1609 
1610     for (int i = 0; i < Integer.SIZE; i++) {
1611       Assert.assertEquals(
1612         Integer.rotateRight(0xBBAAAADD, i),
1613         (0xBBAAAADD >>> i) | (0xBBAAAADD << (Integer.SIZE - i)));
1614     }
1615   }
1616 
1617   public static void test_Long_rotateRight() throws Exception {
1618     Assert.assertEquals(Long.rotateRight(0x11, 0), 0x11);
1619 
1620     Assert.assertEquals(Long.rotateRight(0x11, 1), 0x8000000000000008L);
1621     Assert.assertEquals(Long.rotateRight(0x11, Long.SIZE - 1), 0x22);
1622     Assert.assertEquals(Long.rotateRight(0x11, Long.SIZE), 0x11);
1623     Assert.assertEquals(Long.rotateRight(0x11, Long.SIZE + 1), 0x8000000000000008L);
1624 
1625     Assert.assertEquals(Long.rotateRight(0x11, -1), 0x22);
1626     Assert.assertEquals(Long.rotateRight(0x11, -(Long.SIZE - 1)), 0x8000000000000008L);
1627     Assert.assertEquals(Long.rotateRight(0x11, -Long.SIZE), 0x11);
1628     Assert.assertEquals(Long.rotateRight(0x11, -(Long.SIZE + 1)), 0x22);
1629 
1630     Assert.assertEquals(Long.rotateRight(0x8000000000000000L, 1), 0x4000000000000000L);
1631 
1632     for (int i = 0; i < Long.SIZE; i++) {
1633       Assert.assertEquals(
1634         Long.rotateRight(0xBBAAAADDFF0000DDL, i),
1635         (0xBBAAAADDFF0000DDL >>> i) | (0xBBAAAADDFF0000DDL << (Long.SIZE - i)));
1636     }
1637   }
1638 
1639   public static void test_Integer_rotateLeft() throws Exception {
1640     Assert.assertEquals(Integer.rotateLeft(0x11, 0), 0x11);
1641 
1642     Assert.assertEquals(Integer.rotateLeft(0x11, 1), 0x22);
1643     Assert.assertEquals(Integer.rotateLeft(0x11, Integer.SIZE - 1), 0x80000008);
1644     Assert.assertEquals(Integer.rotateLeft(0x11, Integer.SIZE), 0x11);
1645     Assert.assertEquals(Integer.rotateLeft(0x11, Integer.SIZE + 1), 0x22);
1646 
1647     Assert.assertEquals(Integer.rotateLeft(0x11, -1), 0x80000008);
1648     Assert.assertEquals(Integer.rotateLeft(0x11, -(Integer.SIZE - 1)), 0x22);
1649     Assert.assertEquals(Integer.rotateLeft(0x11, -Integer.SIZE), 0x11);
1650     Assert.assertEquals(Integer.rotateLeft(0x11, -(Integer.SIZE + 1)), 0x80000008);
1651 
1652     Assert.assertEquals(Integer.rotateLeft(0xC0000000, 1), 0x80000001);
1653 
1654     for (int i = 0; i < Integer.SIZE; i++) {
1655       Assert.assertEquals(
1656         Integer.rotateLeft(0xBBAAAADD, i),
1657         (0xBBAAAADD << i) | (0xBBAAAADD >>> (Integer.SIZE - i)));
1658     }
1659   }
1660 
1661   public static void test_Long_rotateLeft() throws Exception {
1662     Assert.assertEquals(Long.rotateLeft(0x11, 0), 0x11);
1663 
1664     Assert.assertEquals(Long.rotateLeft(0x11, 1), 0x22);
1665     Assert.assertEquals(Long.rotateLeft(0x11, Long.SIZE - 1), 0x8000000000000008L);
1666     Assert.assertEquals(Long.rotateLeft(0x11, Long.SIZE), 0x11);
1667     Assert.assertEquals(Long.rotateLeft(0x11, Long.SIZE + 1), 0x22);
1668 
1669     Assert.assertEquals(Long.rotateLeft(0x11, -1), 0x8000000000000008L);
1670     Assert.assertEquals(Long.rotateLeft(0x11, -(Long.SIZE - 1)), 0x22);
1671     Assert.assertEquals(Long.rotateLeft(0x11, -Long.SIZE), 0x11);
1672     Assert.assertEquals(Long.rotateLeft(0x11, -(Long.SIZE + 1)), 0x8000000000000008L);
1673 
1674     Assert.assertEquals(Long.rotateLeft(0xC000000000000000L, 1), 0x8000000000000001L);
1675 
1676     for (int i = 0; i < Long.SIZE; i++) {
1677       Assert.assertEquals(
1678         Long.rotateLeft(0xBBAAAADDFF0000DDL, i),
1679         (0xBBAAAADDFF0000DDL << i) | (0xBBAAAADDFF0000DDL >>> (Long.SIZE - i)));
1680     }
1681   }
1682 
1683   public static void test_Integer_rotateRightLeft() throws Exception {
1684     for (int i = 0; i < Integer.SIZE * 2; i++) {
1685       Assert.assertEquals(Integer.rotateLeft(0xBBAAAADD, i),
1686                           Integer.rotateRight(0xBBAAAADD, -i));
1687       Assert.assertEquals(Integer.rotateLeft(0xBBAAAADD, -i),
1688                           Integer.rotateRight(0xBBAAAADD, i));
1689     }
1690   }
1691 
1692   public static void test_Long_rotateRightLeft() throws Exception {
1693     for (int i = 0; i < Long.SIZE * 2; i++) {
1694       Assert.assertEquals(Long.rotateLeft(0xBBAAAADDFF0000DDL, i),
1695                           Long.rotateRight(0xBBAAAADDFF0000DDL, -i));
1696       Assert.assertEquals(Long.rotateLeft(0xBBAAAADDFF0000DDL, -i),
1697                           Long.rotateRight(0xBBAAAADDFF0000DDL, i));
1698     }
1699   }
1700 }
1701