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