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