Home | History | Annotate | Download | only in lang
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 
     18 package org.apache.harmony.luni.tests.java.lang;
     19 
     20 public class MathTest extends junit.framework.TestCase {
     21 
     22 	double HYP = Math.sqrt(2.0);
     23 
     24 	double OPP = 1.0;
     25 
     26 	double ADJ = 1.0;
     27 
     28 	/* Required to make previous preprocessor flags work - do not remove */
     29 	int unused = 0;
     30 
     31 	/**
     32 	 * @tests java.lang.Math#abs(double)
     33 	 */
     34 	public void test_absD() {
     35 		// Test for method double java.lang.Math.abs(double)
     36 
     37 		assertTrue("Incorrect double abs value",
     38 				(Math.abs(-1908.8976) == 1908.8976));
     39 		assertTrue("Incorrect double abs value",
     40 				(Math.abs(1908.8976) == 1908.8976));
     41 	}
     42 
     43 	/**
     44 	 * @tests java.lang.Math#abs(float)
     45 	 */
     46 	public void test_absF() {
     47 		// Test for method float java.lang.Math.abs(float)
     48 		assertTrue("Incorrect float abs value",
     49 				(Math.abs(-1908.8976f) == 1908.8976f));
     50 		assertTrue("Incorrect float abs value",
     51 				(Math.abs(1908.8976f) == 1908.8976f));
     52 	}
     53 
     54 	/**
     55 	 * @tests java.lang.Math#abs(int)
     56 	 */
     57 	public void test_absI() {
     58 		// Test for method int java.lang.Math.abs(int)
     59 		assertTrue("Incorrect int abs value", (Math.abs(-1908897) == 1908897));
     60 		assertTrue("Incorrect int abs value", (Math.abs(1908897) == 1908897));
     61 	}
     62 
     63 	/**
     64 	 * @tests java.lang.Math#abs(long)
     65 	 */
     66 	public void test_absJ() {
     67 		// Test for method long java.lang.Math.abs(long)
     68 		assertTrue("Incorrect long abs value",
     69 				(Math.abs(-19088976000089L) == 19088976000089L));
     70 		assertTrue("Incorrect long abs value",
     71 				(Math.abs(19088976000089L) == 19088976000089L));
     72 	}
     73 
     74 	/**
     75 	 * @tests java.lang.Math#acos(double)
     76 	 */
     77 	public void test_acosD() {
     78 		// Test for method double java.lang.Math.acos(double)
     79 		double r = Math.cos(Math.acos(ADJ / HYP));
     80 		long lr = Double.doubleToLongBits(r);
     81 		long t = Double.doubleToLongBits(ADJ / HYP);
     82 		assertTrue("Returned incorrect arc cosine", lr == t || (lr + 1) == t
     83 				|| (lr - 1) == t);
     84 	}
     85 
     86 	/**
     87 	 * @tests java.lang.Math#asin(double)
     88 	 */
     89 	public void test_asinD() {
     90 		// Test for method double java.lang.Math.asin(double)
     91 		double r = Math.sin(Math.asin(OPP / HYP));
     92 		long lr = Double.doubleToLongBits(r);
     93 		long t = Double.doubleToLongBits(OPP / HYP);
     94 		assertTrue("Returned incorrect arc sine", lr == t || (lr + 1) == t
     95 				|| (lr - 1) == t);
     96 	}
     97 
     98 	/**
     99 	 * @tests java.lang.Math#atan(double)
    100 	 */
    101 	public void test_atanD() {
    102 		// Test for method double java.lang.Math.atan(double)
    103 		double answer = Math.tan(Math.atan(1.0));
    104 		assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0
    105 				&& answer >= 9.9999999999999983E-1);
    106 	}
    107 
    108 	/**
    109 	 * @tests java.lang.Math#atan2(double, double)
    110 	 */
    111 	public void test_atan2DD() {
    112 		// Test for method double java.lang.Math.atan2(double, double)
    113 		double answer = Math.atan(Math.tan(1.0));
    114 		assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0
    115 				&& answer >= 9.9999999999999983E-1);
    116 	}
    117 
    118      /**
    119      * @tests java.lang.Math#cbrt(double)
    120      */
    121     public void test_cbrt_D() {
    122         //Test for special situations
    123         assertTrue("Should return Double.NaN", Double.isNaN(Math
    124                 .cbrt(Double.NaN)));
    125         assertEquals("Should return Double.POSITIVE_INFINITY",
    126                 Double.POSITIVE_INFINITY, Math
    127                         .cbrt(Double.POSITIVE_INFINITY), 0D);
    128         assertEquals("Should return Double.NEGATIVE_INFINITY",
    129                 Double.NEGATIVE_INFINITY, Math
    130                         .cbrt(Double.NEGATIVE_INFINITY), 0D);
    131         assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math
    132 				.cbrt(0.0)));
    133 		assertEquals(Double.doubleToLongBits(+0.0), Double.doubleToLongBits(Math
    134 				.cbrt(+0.0)));
    135 		assertEquals(Double.doubleToLongBits(-0.0), Double.doubleToLongBits(Math
    136 				.cbrt(-0.0)));
    137 
    138         assertEquals("Should return 3.0", 3.0, Math.cbrt(27.0), 0D);
    139         assertEquals("Should return 23.111993172558684", 23.111993172558684,
    140                 Math.cbrt(12345.6), 0D);
    141         assertEquals("Should return 5.643803094122362E102",
    142                 5.643803094122362E102, Math.cbrt(Double.MAX_VALUE), 0D);
    143         assertEquals("Should return 0.01", 0.01, Math.cbrt(0.000001), 0D);
    144 
    145         assertEquals("Should return -3.0", -3.0, Math.cbrt(-27.0), 0D);
    146         assertEquals("Should return -23.111993172558684", -23.111993172558684,
    147                 Math.cbrt(-12345.6), 0D);
    148         assertEquals("Should return 1.7031839360032603E-108",
    149                 1.7031839360032603E-108, Math.cbrt(Double.MIN_VALUE), 0D);
    150         assertEquals("Should return -0.01", -0.01, Math.cbrt(-0.000001), 0D);
    151     }
    152 
    153 	/**
    154 	 * @tests java.lang.Math#ceil(double)
    155 	 */
    156 	public void test_ceilD() {
    157 		// Test for method double java.lang.Math.ceil(double)
    158                 assertEquals("Incorrect ceiling for double",
    159                              79, Math.ceil(78.89), 0);
    160 		assertEquals("Incorrect ceiling for double",
    161                              -78, Math.ceil(-78.89), 0);
    162 	}
    163 
    164 	/**
    165      * cases for test_copySign_DD in MathTest/StrictMathTest
    166      */
    167     static final double[] COPYSIGN_DD_CASES = new double[] {
    168             Double.POSITIVE_INFINITY, Double.MAX_VALUE, 3.4E302, 2.3,
    169             Double.MIN_NORMAL, Double.MIN_NORMAL / 2, Double.MIN_VALUE, +0.0,
    170             0.0, -0.0, -Double.MIN_VALUE, -Double.MIN_NORMAL / 2,
    171             -Double.MIN_NORMAL, -4.5, -3.4E102, -Double.MAX_VALUE,
    172             Double.NEGATIVE_INFINITY };
    173 
    174     /**
    175      * @tests {@link java.lang.Math#copySign(double, double)}
    176      * @since 1.6
    177      *
    178      */
    179     @SuppressWarnings("boxing")
    180     public void test_copySign_DD() {
    181         for (int i = 0; i < COPYSIGN_DD_CASES.length; i++) {
    182             final double magnitude = COPYSIGN_DD_CASES[i];
    183             final long absMagnitudeBits = Double.doubleToLongBits(Math
    184                     .abs(magnitude));
    185             final long negMagnitudeBits = Double.doubleToLongBits(-Math
    186                     .abs(magnitude));
    187 
    188             // cases for NaN
    189             assertEquals("If the sign is NaN, the result should be positive.",
    190                     absMagnitudeBits, Double.doubleToLongBits(Math.copySign(
    191                             magnitude, Double.NaN)));
    192             assertTrue("The result should be NaN.", Double.isNaN(Math.copySign(
    193                     Double.NaN, magnitude)));
    194 
    195             for (int j = 0; j < COPYSIGN_DD_CASES.length; j++) {
    196                 final double sign = COPYSIGN_DD_CASES[j];
    197                 final long resultBits = Double.doubleToLongBits(Math.copySign(
    198                         magnitude, sign));
    199 
    200                 if (sign > 0 || Double.valueOf(+0.0).equals(sign)
    201                         || Double.valueOf(0.0).equals(sign)) {
    202                     assertEquals(
    203                             "If the sign is positive, the result should be positive.",
    204                             absMagnitudeBits, resultBits);
    205                 }
    206                 if (sign < 0 || Double.valueOf(-0.0).equals(sign)) {
    207                     assertEquals(
    208                             "If the sign is negative, the result should be negative.",
    209                             negMagnitudeBits, resultBits);
    210                 }
    211             }
    212         }
    213 
    214         assertTrue("The result should be NaN.", Double.isNaN(Math.copySign(
    215                 Double.NaN, Double.NaN)));
    216 
    217         try {
    218             Math.copySign((Double) null, 2.3);
    219             fail("Should throw NullPointerException");
    220         } catch (NullPointerException e) {
    221             // Expected
    222         }
    223         try {
    224             Math.copySign(2.3, (Double) null);
    225             fail("Should throw NullPointerException");
    226         } catch (NullPointerException e) {
    227             // Expected
    228         }
    229         try {
    230             Math.copySign((Double) null, (Double) null);
    231             fail("Should throw NullPointerException");
    232         } catch (NullPointerException e) {
    233             // Expected
    234         }
    235     }
    236 
    237     /**
    238      * cases for test_copySign_FF in MathTest/StrictMathTest
    239      */
    240     static final float[] COPYSIGN_FF_CASES = new float[] {
    241             Float.POSITIVE_INFINITY, Float.MAX_VALUE, 3.4E12f, 2.3f,
    242             Float.MIN_NORMAL, Float.MIN_NORMAL / 2, Float.MIN_VALUE, +0.0f,
    243             0.0f, -0.0f, -Float.MIN_VALUE, -Float.MIN_NORMAL / 2,
    244             -Float.MIN_NORMAL, -4.5f, -5.6442E21f, -Float.MAX_VALUE,
    245             Float.NEGATIVE_INFINITY };
    246 
    247     /**
    248      * @tests {@link java.lang.Math#copySign(float, float)}
    249      * @since 1.6
    250      */
    251     @SuppressWarnings("boxing")
    252     public void test_copySign_FF() {
    253         for (int i = 0; i < COPYSIGN_FF_CASES.length; i++) {
    254             final float magnitude = COPYSIGN_FF_CASES[i];
    255             final int absMagnitudeBits = Float.floatToIntBits(Math
    256                     .abs(magnitude));
    257             final int negMagnitudeBits = Float.floatToIntBits(-Math
    258                     .abs(magnitude));
    259 
    260             // cases for NaN
    261             assertEquals("If the sign is NaN, the result should be positive.",
    262                     absMagnitudeBits, Float.floatToIntBits(Math.copySign(
    263                             magnitude, Float.NaN)));
    264             assertTrue("The result should be NaN.", Float.isNaN(Math.copySign(
    265                     Float.NaN, magnitude)));
    266 
    267             for (int j = 0; j < COPYSIGN_FF_CASES.length; j++) {
    268                 final float sign = COPYSIGN_FF_CASES[j];
    269                 final int resultBits = Float.floatToIntBits(Math.copySign(
    270                         magnitude, sign));
    271                 if (sign > 0 || Float.valueOf(+0.0f).equals(sign)
    272                         || Float.valueOf(0.0f).equals(sign)) {
    273                     assertEquals(
    274                             "If the sign is positive, the result should be positive.",
    275                             absMagnitudeBits, resultBits);
    276                 }
    277                 if (sign < 0 || Float.valueOf(-0.0f).equals(sign)) {
    278                     assertEquals(
    279                             "If the sign is negative, the result should be negative.",
    280                             negMagnitudeBits, resultBits);
    281                 }
    282             }
    283         }
    284 
    285         assertTrue("The result should be NaN.", Float.isNaN(Math.copySign(
    286                 Float.NaN, Float.NaN)));
    287 
    288         try {
    289             Math.copySign((Float) null, 2.3f);
    290             fail("Should throw NullPointerException");
    291         } catch (NullPointerException e) {
    292             // Expected
    293         }
    294         try {
    295             Math.copySign(2.3f, (Float) null);
    296             fail("Should throw NullPointerException");
    297         } catch (NullPointerException e) {
    298             // Expected
    299         }
    300         try {
    301             Math.copySign((Float) null, (Float) null);
    302             fail("Should throw NullPointerException");
    303         } catch (NullPointerException e) {
    304             // Expected
    305         }
    306     }
    307 
    308 	/**
    309 	 * @tests java.lang.Math#cos(double)
    310 	 */
    311 	public void test_cosD() {
    312 		// Test for method double java.lang.Math.cos(double)
    313 		assertEquals("Incorrect answer", 1.0, Math.cos(0), 0D);
    314 		assertEquals("Incorrect answer", 0.5403023058681398, Math.cos(1), 0D);
    315 	}
    316 
    317     /**
    318      * @tests java.lang.Math#cosh(double)
    319      */
    320     public void test_cosh_D() {
    321         // Test for special situations
    322         assertTrue(Double.isNaN(Math.cosh(Double.NaN)));
    323         assertEquals("Should return POSITIVE_INFINITY",
    324                 Double.POSITIVE_INFINITY, Math.cosh(Double.POSITIVE_INFINITY), 0D);
    325         assertEquals("Should return POSITIVE_INFINITY",
    326                 Double.POSITIVE_INFINITY, Math.cosh(Double.NEGATIVE_INFINITY), 0D);
    327         assertEquals("Should return 1.0", 1.0, Math.cosh(+0.0), 0D);
    328         assertEquals("Should return 1.0", 1.0, Math.cosh(-0.0), 0D);
    329 
    330         assertEquals("Should return POSITIVE_INFINITY",
    331                 Double.POSITIVE_INFINITY, Math.cosh(1234.56), 0D);
    332         assertEquals("Should return POSITIVE_INFINITY",
    333                 Double.POSITIVE_INFINITY, Math.cosh(-1234.56), 0D);
    334         assertEquals("Should return 1.0000000000005", 1.0000000000005, Math
    335                 .cosh(0.000001), 0D);
    336         assertEquals("Should return 1.0000000000005", 1.0000000000005, Math
    337                 .cosh(-0.000001), 0D);
    338         assertEquals("Should return 5.212214351945598", 5.212214351945598, Math
    339                 .cosh(2.33482), 0D);
    340 
    341         assertEquals("Should return POSITIVE_INFINITY",
    342                 Double.POSITIVE_INFINITY, Math.cosh(Double.MAX_VALUE), 0D);
    343         assertEquals("Should return 1.0", 1.0, Math.cosh(Double.MIN_VALUE), 0D);
    344     }
    345 
    346 	/**
    347 	 * @tests java.lang.Math#exp(double)
    348 	 */
    349 	public void test_expD() {
    350 		// Test for method double java.lang.Math.exp(double)
    351 		assertTrue("Incorrect answer returned for simple power", Math.abs(Math
    352 				.exp(4D)
    353 				- Math.E * Math.E * Math.E * Math.E) < 0.1D);
    354 		assertTrue("Incorrect answer returned for larger power", Math.log(Math
    355 				.abs(Math.exp(5.5D)) - 5.5D) < 10.0D);
    356 	}
    357 
    358     /**
    359      * @tests java.lang.Math#expm1(double)
    360      */
    361     public void test_expm1_D() {
    362         // Test for special cases
    363         assertTrue("Should return NaN", Double.isNaN(Math.expm1(Double.NaN)));
    364         assertEquals("Should return POSITIVE_INFINITY",
    365                 Double.POSITIVE_INFINITY, Math.expm1(Double.POSITIVE_INFINITY), 0D);
    366         assertEquals("Should return -1.0", -1.0, Math
    367                 .expm1(Double.NEGATIVE_INFINITY), 0D);
    368         assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math
    369 				.expm1(0.0)));
    370 		assertEquals(Double.doubleToLongBits(+0.0), Double
    371 				.doubleToLongBits(Math.expm1(+0.0)));
    372 		assertEquals(Double.doubleToLongBits(-0.0), Double
    373 				.doubleToLongBits(Math.expm1(-0.0)));
    374 
    375         assertEquals("Should return -9.999950000166666E-6",
    376                 -9.999950000166666E-6, Math.expm1(-0.00001), 0D);
    377         assertEquals("Should return 1.0145103074469635E60",
    378                 1.0145103074469635E60, Math.expm1(138.16951162), 0D);
    379         assertEquals("Should return POSITIVE_INFINITY",
    380                 Double.POSITIVE_INFINITY, Math
    381                         .expm1(123456789123456789123456789.4521584223), 0D);
    382         assertEquals("Should return POSITIVE_INFINITY",
    383                 Double.POSITIVE_INFINITY, Math.expm1(Double.MAX_VALUE), 0D);
    384         assertEquals("Should return MIN_VALUE", Double.MIN_VALUE, Math
    385                 .expm1(Double.MIN_VALUE), 0D);
    386     }
    387 
    388     /**
    389      * @tests java.lang.Math#floor(double)
    390      */
    391     public void test_floorD() {
    392         assertEquals("Incorrect floor for int", 42, Math.floor(42), 0);
    393         assertEquals("Incorrect floor for -int", -2, Math.floor(-2), 0);
    394         assertEquals("Incorrect floor for zero", 0d, Math.floor(0d), 0);
    395 
    396         assertEquals("Incorrect floor for +double", 78, Math.floor(78.89), 0);
    397         assertEquals("Incorrect floor for -double", -79, Math.floor(-78.89), 0);
    398         assertEquals("floor large +double", 3.7314645675925406E19, Math.floor(3.7314645675925406E19), 0);
    399         assertEquals("floor large -double", -8.173521839218E12, Math.floor(-8.173521839218E12), 0);
    400         assertEquals("floor small double", 0.0d, Math.floor(1.11895241315E-102), 0);
    401 
    402         // Compare toString representations here since -0.0 = +0.0, and
    403         // NaN != NaN and we need to distinguish
    404         assertEquals("Floor failed for NaN",
    405                 Double.toString(Double.NaN), Double.toString(Math.floor(Double.NaN)));
    406         assertEquals("Floor failed for +0.0",
    407                 Double.toString(+0.0d), Double.toString(Math.floor(+0.0d)));
    408         assertEquals("Floor failed for -0.0",
    409                 Double.toString(-0.0d), Double.toString(Math.floor(-0.0d)));
    410         assertEquals("Floor failed for +infinity",
    411                 Double.toString(Double.POSITIVE_INFINITY), Double.toString(Math.floor(Double.POSITIVE_INFINITY)));
    412         assertEquals("Floor failed for -infinity",
    413                 Double.toString(Double.NEGATIVE_INFINITY), Double.toString(Math.floor(Double.NEGATIVE_INFINITY)));
    414     }
    415 
    416 	/**
    417      * cases for test_getExponent_D in MathTest/StrictMathTest
    418      */
    419     static final double GETEXPONENT_D_CASES[] = new double[] {
    420             Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY,
    421             Double.MAX_VALUE, -Double.MAX_VALUE, 2.342E231, -2.342E231, 2800.0,
    422             -2800.0, 5.323, -5.323, 1.323, -1.323, 0.623, -0.623, 0.323,
    423             -0.323, Double.MIN_NORMAL * 24, -Double.MIN_NORMAL * 24,
    424             Double.MIN_NORMAL, -Double.MIN_NORMAL, Double.MIN_NORMAL / 2,
    425             -Double.MIN_NORMAL / 2, Double.MIN_VALUE, -Double.MIN_VALUE, +0.0,
    426             0.0, -0.0, Double.NaN };
    427 
    428     /**
    429      * result for test_getExponent_D in MathTest/StrictMathTest
    430      */
    431     static final int GETEXPONENT_D_RESULTS[] = new int[] {
    432             Double.MAX_EXPONENT + 1, Double.MAX_EXPONENT + 1,
    433             Double.MAX_EXPONENT, Double.MAX_EXPONENT, 768, 768, 11, 11, 2, 2,
    434             0, 0, -1, -1, -2, -2, -1018, -1018, Double.MIN_EXPONENT,
    435             Double.MIN_EXPONENT, Double.MIN_EXPONENT - 1,
    436             Double.MIN_EXPONENT - 1, Double.MIN_EXPONENT - 1,
    437             Double.MIN_EXPONENT - 1, Double.MIN_EXPONENT - 1,
    438             Double.MIN_EXPONENT - 1, Double.MIN_EXPONENT - 1,
    439             Double.MAX_EXPONENT + 1 };
    440 
    441     /**
    442      * @tests {@link java.lang.Math#getExponent(double)}
    443      * @since 1.6
    444      */
    445     @SuppressWarnings("boxing")
    446     public void test_getExponent_D() {
    447         for (int i = 0; i < GETEXPONENT_D_CASES.length; i++) {
    448             final double number = GETEXPONENT_D_CASES[i];
    449             final int result = GETEXPONENT_D_RESULTS[i];
    450             assertEquals("Wrong result of getExponent(double).", result, Math
    451                     .getExponent(number));
    452         }
    453 
    454         try {
    455             Math.getExponent((Double) null);
    456             fail("Should throw NullPointerException");
    457         } catch (NullPointerException e) {
    458             // Expected
    459         }
    460     }
    461 
    462     /**
    463      * cases for test_getExponent_F in MathTest/StrictMathTest
    464      */
    465     static final float GETEXPONENT_F_CASES[] = new float[] {
    466             Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.MAX_VALUE,
    467             -Float.MAX_VALUE, 3.4256E23f, -3.4256E23f, 2800.0f, -2800.0f,
    468             5.323f, -5.323f, 1.323f, -1.323f, 0.623f, -0.623f, 0.323f, -0.323f,
    469             Float.MIN_NORMAL * 24, -Float.MIN_NORMAL * 24, Float.MIN_NORMAL,
    470             -Float.MIN_NORMAL, Float.MIN_NORMAL / 2, -Float.MIN_NORMAL / 2,
    471             Float.MIN_VALUE, -Float.MIN_VALUE, +0.0f, 0.0f, -0.0f, Float.NaN,1,Float.MIN_NORMAL * 1.5f };
    472 
    473     /**
    474      * result for test_getExponent_F in MathTest/StrictMathTest
    475      */
    476     static final int GETEXPONENT_F_RESULTS[] = new int[] {
    477             Float.MAX_EXPONENT + 1, Float.MAX_EXPONENT + 1, Float.MAX_EXPONENT,
    478             Float.MAX_EXPONENT, 78, 78, 11, 11, 2, 2, 0, 0, -1, -1, -2, -2,
    479             -122, -122, Float.MIN_EXPONENT, Float.MIN_EXPONENT,
    480             Float.MIN_EXPONENT - 1, Float.MIN_EXPONENT - 1,
    481             Float.MIN_EXPONENT - 1, Float.MIN_EXPONENT - 1,
    482             Float.MIN_EXPONENT - 1, Float.MIN_EXPONENT - 1,
    483             Float.MIN_EXPONENT - 1, Float.MAX_EXPONENT + 1,0,Float.MIN_EXPONENT };
    484 
    485     /**
    486      * @tests {@link java.lang.Math#getExponent(float)}
    487      * @since 1.6
    488      */
    489     @SuppressWarnings("boxing")
    490     public void test_getExponent_F() {
    491         for (int i = 0; i < GETEXPONENT_F_CASES.length; i++) {
    492             final float number = GETEXPONENT_F_CASES[i];
    493             final int result = GETEXPONENT_F_RESULTS[i];
    494             assertEquals("Wrong result of getExponent(float).", result, Math
    495                     .getExponent(number));
    496         }
    497         try {
    498             Math.getExponent((Float) null);
    499             fail("Should throw NullPointerException");
    500         } catch (NullPointerException e) {
    501             // Expected
    502         }
    503     }
    504 
    505     /**
    506      * @tests java.lang.Math#hypot(double, double)
    507      */
    508     public void test_hypot_DD() {
    509         // Test for special cases
    510         assertEquals("Should return POSITIVE_INFINITY",
    511                 Double.POSITIVE_INFINITY, Math.hypot(Double.POSITIVE_INFINITY,
    512                         1.0), 0D);
    513         assertEquals("Should return POSITIVE_INFINITY",
    514                 Double.POSITIVE_INFINITY, Math.hypot(Double.NEGATIVE_INFINITY,
    515                         123.324), 0D);
    516         assertEquals("Should return POSITIVE_INFINITY",
    517                 Double.POSITIVE_INFINITY, Math.hypot(-758.2587,
    518                         Double.POSITIVE_INFINITY), 0D);
    519         assertEquals("Should return POSITIVE_INFINITY",
    520                 Double.POSITIVE_INFINITY, Math.hypot(5687.21,
    521                         Double.NEGATIVE_INFINITY), 0D);
    522         assertEquals("Should return POSITIVE_INFINITY",
    523                 Double.POSITIVE_INFINITY, Math.hypot(Double.POSITIVE_INFINITY,
    524                         Double.NEGATIVE_INFINITY), 0D);
    525         assertEquals("Should return POSITIVE_INFINITY",
    526                 Double.POSITIVE_INFINITY, Math.hypot(Double.NEGATIVE_INFINITY,
    527                         Double.POSITIVE_INFINITY), 0D);
    528         assertTrue("Should be NaN", Double.isNaN(Math.hypot(Double.NaN,
    529                 2342301.89843)));
    530         assertTrue("Should be NaN", Double.isNaN(Math.hypot(-345.2680,
    531                 Double.NaN)));
    532 
    533         assertEquals("Should return 2396424.905416697", 2396424.905416697, Math
    534                 .hypot(12322.12, -2396393.2258), 0D);
    535         assertEquals("Should return 138.16958070558556", 138.16958070558556,
    536                 Math.hypot(-138.16951162, 0.13817035864), 0D);
    537         assertEquals("Should return 1.7976931348623157E308",
    538                 1.7976931348623157E308, Math.hypot(Double.MAX_VALUE, 211370.35), 0D);
    539         assertEquals("Should return 5413.7185", 5413.7185, Math.hypot(
    540                 -5413.7185, Double.MIN_VALUE), 0D);
    541     }
    542 
    543 	/**
    544 	 * @tests java.lang.Math#IEEEremainder(double, double)
    545 	 */
    546 	public void test_IEEEremainderDD() {
    547 		// Test for method double java.lang.Math.IEEEremainder(double, double)
    548 		assertEquals("Incorrect remainder returned",
    549 				0.0, Math.IEEEremainder(1.0, 1.0), 0D);
    550 		assertTrue("Incorrect remainder returned", Math.IEEEremainder(1.32,
    551 				89.765) >= 1.4705063220631647E-2
    552 				|| Math.IEEEremainder(1.32, 89.765) >= 1.4705063220631649E-2);
    553 	}
    554 
    555 	/**
    556 	 * @tests java.lang.Math#log(double)
    557 	 */
    558 	public void test_logD() {
    559 		// Test for method double java.lang.Math.log(double)
    560 		for (double d = 10; d >= -10; d -= 0.5) {
    561 			double answer = Math.log(Math.exp(d));
    562 			assertTrue("Answer does not equal expected answer for d = " + d
    563 					+ " answer = " + answer, Math.abs(answer - d) <= Math
    564 					.abs(d * 0.00000001));
    565 		}
    566 	}
    567 
    568     /**
    569      * @tests java.lang.Math#log10(double)
    570      */
    571     @SuppressWarnings("boxing")
    572     public void test_log10_D() {
    573         // Test for special cases
    574         assertTrue(Double.isNaN(Math.log10(Double.NaN)));
    575         assertTrue(Double.isNaN(Math.log10(-2541.05745687234187532)));
    576         assertTrue(Double.isNaN(Math.log10(-0.1)));
    577         assertEquals(Double.POSITIVE_INFINITY, Math.log10(Double.POSITIVE_INFINITY));
    578         assertEquals(Double.NEGATIVE_INFINITY, Math.log10(0.0));
    579         assertEquals(Double.NEGATIVE_INFINITY, Math.log10(+0.0));
    580         assertEquals(Double.NEGATIVE_INFINITY, Math.log10(-0.0));
    581 
    582         assertEquals(3.0, Math.log10(1000.0));
    583         assertEquals(14.0, Math.log10(Math.pow(10, 14)));
    584         assertEquals(3.7389561269540406, Math.log10(5482.2158));
    585         assertEquals(14.661551142893833, Math.log10(458723662312872.125782332587));
    586         assertEquals(-0.9083828622192334, Math.log10(0.12348583358871));
    587         assertEquals(308.25471555991675, Math.log10(Double.MAX_VALUE));
    588         assertEquals(-323.3062153431158, Math.log10(Double.MIN_VALUE));
    589     }
    590 
    591     /**
    592      * @tests java.lang.Math#log1p(double)
    593      */
    594     public void test_log1p_D() {
    595         // Test for special cases
    596         assertTrue("Should return NaN", Double.isNaN(Math.log1p(Double.NaN)));
    597         assertTrue("Should return NaN", Double.isNaN(Math.log1p(-32.0482175)));
    598         assertEquals("Should return POSITIVE_INFINITY",
    599                 Double.POSITIVE_INFINITY, Math.log1p(Double.POSITIVE_INFINITY), 0D);
    600         assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math
    601 				.log1p(0.0)));
    602 		assertEquals(Double.doubleToLongBits(+0.0), Double
    603 				.doubleToLongBits(Math.log1p(+0.0)));
    604 		assertEquals(Double.doubleToLongBits(-0.0), Double
    605 				.doubleToLongBits(Math.log1p(-0.0)));
    606 
    607         assertEquals("Should return -0.2941782295312541", -0.2941782295312541,
    608                 Math.log1p(-0.254856327), 0D);
    609         assertEquals("Should return 7.368050685564151", 7.368050685564151, Math
    610                 .log1p(1583.542), 0D);
    611         assertEquals("Should return 0.4633708685409921", 0.4633708685409921,
    612                 Math.log1p(0.5894227), 0D);
    613         assertEquals("Should return 709.782712893384", 709.782712893384, Math
    614                 .log1p(Double.MAX_VALUE), 0D);
    615         assertEquals("Should return Double.MIN_VALUE", Double.MIN_VALUE, Math
    616                 .log1p(Double.MIN_VALUE), 0D);
    617     }
    618 
    619 	/**
    620 	 * @tests java.lang.Math#max(double, double)
    621 	 */
    622 	public void test_maxDD() {
    623 		// Test for method double java.lang.Math.max(double, double)
    624 		assertEquals("Incorrect double max value", 1908897.6000089, Math.max(-1908897.6000089,
    625 				1908897.6000089), 0D);
    626 		assertEquals("Incorrect double max value",
    627 				1908897.6000089, Math.max(2.0, 1908897.6000089), 0D);
    628 		assertEquals("Incorrect double max value", -2.0, Math.max(-2.0,
    629 				-1908897.6000089), 0D);
    630 
    631 		// Compare toString representations here since -0.0 = +0.0, and
    632 		// NaN != NaN and we need to distinguish
    633         assertEquals("Max failed for NaN",
    634                 Double.toString(Double.NaN), Double.toString(Math.max(Double.NaN, 42.0d)));
    635         assertEquals("Max failed for NaN",
    636                 Double.toString(Double.NaN), Double.toString(Math.max(42.0d, Double.NaN)));
    637         assertEquals("Max failed for 0.0",
    638                 Double.toString(+0.0d), Double.toString(Math.max(+0.0d, -0.0d)));
    639         assertEquals("Max failed for 0.0",
    640                 Double.toString(+0.0d), Double.toString(Math.max(-0.0d, +0.0d)));
    641         assertEquals("Max failed for -0.0d",
    642                 Double.toString(-0.0d), Double.toString(Math.max(-0.0d, -0.0d)));
    643         assertEquals("Max failed for 0.0",
    644                 Double.toString(+0.0d), Double.toString(Math.max(+0.0d, +0.0d)));
    645 	}
    646 
    647 	/**
    648 	 * @tests java.lang.Math#max(float, float)
    649 	 */
    650 	public void test_maxFF() {
    651 		// Test for method float java.lang.Math.max(float, float)
    652 		assertTrue("Incorrect float max value", Math.max(-1908897.600f,
    653 				1908897.600f) == 1908897.600f);
    654 		assertTrue("Incorrect float max value",
    655 				Math.max(2.0f, 1908897.600f) == 1908897.600f);
    656 		assertTrue("Incorrect float max value",
    657 				Math.max(-2.0f, -1908897.600f) == -2.0f);
    658 
    659 	    // Compare toString representations here since -0.0 = +0.0, and
    660         // NaN != NaN and we need to distinguish
    661         assertEquals("Max failed for NaN",
    662                 Float.toString(Float.NaN), Float.toString(Math.max(Float.NaN, 42.0f)));
    663         assertEquals("Max failed for NaN",
    664                 Float.toString(Float.NaN), Float.toString(Math.max(42.0f, Float.NaN)));
    665         assertEquals("Max failed for 0.0",
    666                 Float.toString(+0.0f), Float.toString(Math.max(+0.0f, -0.0f)));
    667         assertEquals("Max failed for 0.0",
    668                 Float.toString(+0.0f), Float.toString(Math.max(-0.0f, +0.0f)));
    669         assertEquals("Max failed for -0.0f",
    670                 Float.toString(-0.0f), Float.toString(Math.max(-0.0f, -0.0f)));
    671         assertEquals("Max failed for 0.0",
    672                 Float.toString(+0.0f), Float.toString(Math.max(+0.0f, +0.0f)));
    673 	}
    674 
    675 	/**
    676 	 * @tests java.lang.Math#max(int, int)
    677 	 */
    678 	public void test_maxII() {
    679 		// Test for method int java.lang.Math.max(int, int)
    680 		assertEquals("Incorrect int max value",
    681 				19088976, Math.max(-19088976, 19088976));
    682 		assertEquals("Incorrect int max value",
    683 				19088976, Math.max(20, 19088976));
    684 		assertEquals("Incorrect int max value", -20, Math.max(-20, -19088976));
    685 	}
    686 
    687 	/**
    688 	 * @tests java.lang.Math#max(long, long)
    689 	 */
    690 	public void test_maxJJ() {
    691 		// Test for method long java.lang.Math.max(long, long)
    692 		assertEquals("Incorrect long max value", 19088976000089L, Math.max(-19088976000089L,
    693 				19088976000089L));
    694 		assertEquals("Incorrect long max value",
    695 				19088976000089L, Math.max(20, 19088976000089L));
    696 		assertEquals("Incorrect long max value",
    697 				-20, Math.max(-20, -19088976000089L));
    698 	}
    699 
    700 	/**
    701 	 * @tests java.lang.Math#min(double, double)
    702 	 */
    703 	public void test_minDD() {
    704 		// Test for method double java.lang.Math.min(double, double)
    705 		assertEquals("Incorrect double min value", -1908897.6000089, Math.min(-1908897.6000089,
    706 				1908897.6000089), 0D);
    707 		assertEquals("Incorrect double min value",
    708 				2.0, Math.min(2.0, 1908897.6000089), 0D);
    709 		assertEquals("Incorrect double min value", -1908897.6000089, Math.min(-2.0,
    710 				-1908897.6000089), 0D);
    711 		assertEquals("Incorrect double min value", 1.0d, Math.min(1.0d, 1.0d));
    712 
    713 	    // Compare toString representations here since -0.0 = +0.0, and
    714         // NaN != NaN and we need to distinguish
    715         assertEquals("Min failed for NaN",
    716                 Double.toString(Double.NaN), Double.toString(Math.min(Double.NaN, 42.0d)));
    717         assertEquals("Min failed for NaN",
    718                 Double.toString(Double.NaN), Double.toString(Math.min(42.0d, Double.NaN)));
    719         assertEquals("Min failed for -0.0",
    720                 Double.toString(-0.0d), Double.toString(Math.min(+0.0d, -0.0d)));
    721         assertEquals("Min failed for -0.0",
    722                 Double.toString(-0.0d), Double.toString(Math.min(-0.0d, +0.0d)));
    723         assertEquals("Min failed for -0.0d",
    724                 Double.toString(-0.0d), Double.toString(Math.min(-0.0d, -0.0d)));
    725         assertEquals("Min failed for 0.0",
    726                 Double.toString(+0.0d), Double.toString(Math.min(+0.0d, +0.0d)));
    727 	}
    728 
    729 	/**
    730 	 * @tests java.lang.Math#min(float, float)
    731 	 */
    732 	public void test_minFF() {
    733 		// Test for method float java.lang.Math.min(float, float)
    734 		assertTrue("Incorrect float min value", Math.min(-1908897.600f,
    735 				1908897.600f) == -1908897.600f);
    736 		assertTrue("Incorrect float min value",
    737 				Math.min(2.0f, 1908897.600f) == 2.0f);
    738 		assertTrue("Incorrect float min value",
    739 				Math.min(-2.0f, -1908897.600f) == -1908897.600f);
    740 		assertEquals("Incorrect float min value", 1.0f, Math.min(1.0f, 1.0f));
    741 
    742         // Compare toString representations here since -0.0 = +0.0, and
    743         // NaN != NaN and we need to distinguish
    744         assertEquals("Min failed for NaN",
    745                 Float.toString(Float.NaN), Float.toString(Math.min(Float.NaN, 42.0f)));
    746         assertEquals("Min failed for NaN",
    747                 Float.toString(Float.NaN), Float.toString(Math.min(42.0f, Float.NaN)));
    748         assertEquals("Min failed for -0.0",
    749                 Float.toString(-0.0f), Float.toString(Math.min(+0.0f, -0.0f)));
    750         assertEquals("Min failed for -0.0",
    751                 Float.toString(-0.0f), Float.toString(Math.min(-0.0f, +0.0f)));
    752         assertEquals("Min failed for -0.0f",
    753                 Float.toString(-0.0f), Float.toString(Math.min(-0.0f, -0.0f)));
    754         assertEquals("Min failed for 0.0",
    755                 Float.toString(+0.0f), Float.toString(Math.min(+0.0f, +0.0f)));
    756 	}
    757 
    758 	/**
    759 	 * @tests java.lang.Math#min(int, int)
    760 	 */
    761 	public void test_minII() {
    762 		// Test for method int java.lang.Math.min(int, int)
    763 		assertEquals("Incorrect int min value",
    764 				-19088976, Math.min(-19088976, 19088976));
    765 		assertEquals("Incorrect int min value", 20, Math.min(20, 19088976));
    766 		assertEquals("Incorrect int min value",
    767 				-19088976, Math.min(-20, -19088976));
    768 
    769 	}
    770 
    771 	/**
    772 	 * @tests java.lang.Math#min(long, long)
    773 	 */
    774 	public void test_minJJ() {
    775 		// Test for method long java.lang.Math.min(long, long)
    776 		assertEquals("Incorrect long min value", -19088976000089L, Math.min(-19088976000089L,
    777 				19088976000089L));
    778 		assertEquals("Incorrect long min value",
    779 				20, Math.min(20, 19088976000089L));
    780 		assertEquals("Incorrect long min value",
    781 				-19088976000089L, Math.min(-20, -19088976000089L));
    782 	}
    783 
    784 	/**
    785      * start number cases for test_nextAfter_DD in MathTest/StrictMathTest
    786      * NEXTAFTER_DD_START_CASES[i][0] is the start number
    787      * NEXTAFTER_DD_START_CASES[i][1] is the nextUp of start number
    788      * NEXTAFTER_DD_START_CASES[i][2] is the nextDown of start number
    789      */
    790     static final double NEXTAFTER_DD_START_CASES[][] = new double[][] {
    791             { 3.4, 3.4000000000000004, 3.3999999999999995 },
    792             { -3.4, -3.3999999999999995, -3.4000000000000004 },
    793             { 3.4233E109, 3.4233000000000005E109, 3.4232999999999996E109 },
    794             { -3.4233E109, -3.4232999999999996E109, -3.4233000000000005E109 },
    795             { +0.0, Double.MIN_VALUE, -Double.MIN_VALUE },
    796             { 0.0, Double.MIN_VALUE, -Double.MIN_VALUE },
    797             { -0.0, Double.MIN_VALUE, -Double.MIN_VALUE },
    798             { Double.MIN_VALUE, 1.0E-323, +0.0 },
    799             { -Double.MIN_VALUE, -0.0, -1.0E-323 },
    800             { Double.MIN_NORMAL, 2.225073858507202E-308, 2.225073858507201E-308 },
    801             { -Double.MIN_NORMAL, -2.225073858507201E-308,
    802                     -2.225073858507202E-308 },
    803             { Double.MAX_VALUE, Double.POSITIVE_INFINITY,
    804                     1.7976931348623155E308 },
    805             { -Double.MAX_VALUE, -1.7976931348623155E308,
    806                     Double.NEGATIVE_INFINITY },
    807             { Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY,
    808                     Double.MAX_VALUE },
    809             { Double.NEGATIVE_INFINITY, -Double.MAX_VALUE,
    810                     Double.NEGATIVE_INFINITY } };
    811 
    812     /**
    813      * direction number cases for test_nextAfter_DD/test_nextAfter_FD in
    814      * MathTest/StrictMathTest
    815      */
    816     static final double NEXTAFTER_DD_FD_DIRECTION_CASES[] = new double[] {
    817             Double.POSITIVE_INFINITY, Double.MAX_VALUE, 8.8, 3.4, 1.4,
    818             Double.MIN_NORMAL, Double.MIN_NORMAL / 2, Double.MIN_VALUE, +0.0,
    819             0.0, -0.0, -Double.MIN_VALUE, -Double.MIN_NORMAL / 2,
    820             -Double.MIN_NORMAL, -1.4, -3.4, -8.8, -Double.MAX_VALUE,
    821             Double.NEGATIVE_INFINITY };
    822 
    823     /**
    824      * @tests {@link java.lang.Math#nextAfter(double, double)}
    825      * @since 1.6
    826      */
    827     @SuppressWarnings("boxing")
    828     public void test_nextAfter_DD() {
    829         // test for most cases without exception
    830         for (int i = 0; i < NEXTAFTER_DD_START_CASES.length; i++) {
    831             final double start = NEXTAFTER_DD_START_CASES[i][0];
    832             final long nextUpBits = Double
    833                     .doubleToLongBits(NEXTAFTER_DD_START_CASES[i][1]);
    834             final long nextDownBits = Double
    835                     .doubleToLongBits(NEXTAFTER_DD_START_CASES[i][2]);
    836 
    837             for (int j = 0; j < NEXTAFTER_DD_FD_DIRECTION_CASES.length; j++) {
    838                 final double direction = NEXTAFTER_DD_FD_DIRECTION_CASES[j];
    839                 final long resultBits = Double.doubleToLongBits(Math.nextAfter(
    840                         start, direction));
    841                 final long directionBits = Double.doubleToLongBits(direction);
    842                 if (direction > start) {
    843                     assertEquals("Result should be next up-number.",
    844                             nextUpBits, resultBits);
    845                 } else if (direction < start) {
    846                     assertEquals("Result should be next down-number.",
    847                             nextDownBits, resultBits);
    848                 } else {
    849                     assertEquals("Result should be direction.", directionBits,
    850                             resultBits);
    851                 }
    852             }
    853         }
    854 
    855         // test for cases with NaN
    856         for (int i = 0; i < NEXTAFTER_DD_START_CASES.length; i++) {
    857             assertTrue("The result should be NaN.", Double.isNaN(Math
    858                     .nextAfter(NEXTAFTER_DD_START_CASES[i][0], Double.NaN)));
    859         }
    860         for (int i = 0; i < NEXTAFTER_DD_FD_DIRECTION_CASES.length; i++) {
    861             assertTrue("The result should be NaN.", Double.isNaN(Math
    862                     .nextAfter(Double.NaN, NEXTAFTER_DD_FD_DIRECTION_CASES[i])));
    863         }
    864         assertTrue("The result should be NaN.", Double.isNaN(Math.nextAfter(
    865                 Double.NaN, Double.NaN)));
    866 
    867         // test for exception
    868         try {
    869             Math.nextAfter((Double) null, 2.3);
    870             fail("Should throw NullPointerException");
    871         } catch (NullPointerException e) {
    872             // Expected
    873         }
    874         try {
    875             Math.nextAfter(2.3, (Double) null);
    876             fail("Should throw NullPointerException");
    877         } catch (NullPointerException e) {
    878             // Expected
    879         }
    880         try {
    881             Math.nextAfter((Double) null, (Double) null);
    882             fail("Should throw NullPointerException");
    883         } catch (NullPointerException e) {
    884             // Expected
    885         }
    886     }
    887 
    888     /**
    889      * start number cases for test_nextAfter_FD in MathTest/StrictMathTest
    890      * NEXTAFTER_FD_START_CASES[i][0] is the start number
    891      * NEXTAFTER_FD_START_CASES[i][1] is the nextUp of start number
    892      * NEXTAFTER_FD_START_CASES[i][2] is the nextDown of start number
    893      */
    894     static final float NEXTAFTER_FD_START_CASES[][] = new float[][] {
    895             { 3.4f, 3.4000003f, 3.3999999f },
    896             { -3.4f, -3.3999999f, -3.4000003f },
    897             { 3.4233E19f, 3.4233002E19f, 3.4232998E19f },
    898             { -3.4233E19f, -3.4232998E19f, -3.4233002E19f },
    899             { +0.0f, Float.MIN_VALUE, -Float.MIN_VALUE },
    900             { 0.0f, Float.MIN_VALUE, -Float.MIN_VALUE },
    901             { -0.0f, Float.MIN_VALUE, -Float.MIN_VALUE },
    902             { Float.MIN_VALUE, 2.8E-45f, +0.0f },
    903             { -Float.MIN_VALUE, -0.0f, -2.8E-45f },
    904             { Float.MIN_NORMAL, 1.1754945E-38f, 1.1754942E-38f },
    905             { -Float.MIN_NORMAL, -1.1754942E-38f, -1.1754945E-38f },
    906             { Float.MAX_VALUE, Float.POSITIVE_INFINITY, 3.4028233E38f },
    907             { -Float.MAX_VALUE, -3.4028233E38f, Float.NEGATIVE_INFINITY },
    908             { Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.MAX_VALUE },
    909             { Float.NEGATIVE_INFINITY, -Float.MAX_VALUE,
    910                     Float.NEGATIVE_INFINITY } };
    911 
    912     /**
    913      * @tests {@link java.lang.Math#nextAfter(float, double)}
    914      * @since 1.6
    915      */
    916     @SuppressWarnings("boxing")
    917     public void test_nextAfter_FD() {
    918         // test for most cases without exception
    919         for (int i = 0; i < NEXTAFTER_FD_START_CASES.length; i++) {
    920             final float start = NEXTAFTER_FD_START_CASES[i][0];
    921             final int nextUpBits = Float
    922                     .floatToIntBits(NEXTAFTER_FD_START_CASES[i][1]);
    923             final int nextDownBits = Float
    924                     .floatToIntBits(NEXTAFTER_FD_START_CASES[i][2]);
    925 
    926             for (int j = 0; j < NEXTAFTER_DD_FD_DIRECTION_CASES.length; j++) {
    927                 final double direction = NEXTAFTER_DD_FD_DIRECTION_CASES[j];
    928                 final int resultBits = Float.floatToIntBits(Math.nextAfter(
    929                         start, direction));
    930                 if (direction > start) {
    931                     assertEquals("Result should be next up-number.",
    932                             nextUpBits, resultBits);
    933                 } else if (direction < start) {
    934                     assertEquals("Result should be next down-number.",
    935                             nextDownBits, resultBits);
    936                 } else {
    937                     final int equivalentBits = Float.floatToIntBits(new Float(
    938                             direction));
    939                     assertEquals(
    940                             "Result should be a number equivalent to direction.",
    941                             equivalentBits, resultBits);
    942                 }
    943             }
    944         }
    945 
    946         // test for cases with NaN
    947         for (int i = 0; i < NEXTAFTER_FD_START_CASES.length; i++) {
    948             assertTrue("The result should be NaN.", Float.isNaN(Math.nextAfter(
    949                     NEXTAFTER_FD_START_CASES[i][0], Float.NaN)));
    950         }
    951         for (int i = 0; i < NEXTAFTER_DD_FD_DIRECTION_CASES.length; i++) {
    952             assertTrue("The result should be NaN.", Float.isNaN(Math.nextAfter(
    953                     Float.NaN, NEXTAFTER_DD_FD_DIRECTION_CASES[i])));
    954         }
    955         assertTrue("The result should be NaN.", Float.isNaN(Math.nextAfter(
    956                 Float.NaN, Float.NaN)));
    957 
    958         // test for exception
    959         try {
    960             Math.nextAfter((Float) null, 2.3);
    961             fail("Should throw NullPointerException");
    962         } catch (NullPointerException e) {
    963             // Expected
    964         }
    965         try {
    966             Math.nextAfter(2.3, (Float) null);
    967             fail("Should throw NullPointerException");
    968         } catch (NullPointerException e) {
    969             // Expected
    970         }
    971         try {
    972             Math.nextAfter((Float) null, (Float) null);
    973             fail("Should throw NullPointerException");
    974         } catch (NullPointerException e) {
    975             // Expected
    976         }
    977     }
    978 
    979     /**
    980      * @tests {@link java.lang.Math#nextUp(double)}
    981      * @since 1.6
    982      */
    983     @SuppressWarnings("boxing")
    984     public void test_nextUp_D() {
    985         // This method is semantically equivalent to nextAfter(d,
    986         // Double.POSITIVE_INFINITY),
    987         // so we use the data of test_nextAfter_DD
    988         for (int i = 0; i < NEXTAFTER_DD_START_CASES.length; i++) {
    989             final double start = NEXTAFTER_DD_START_CASES[i][0];
    990             final long nextUpBits = Double
    991                     .doubleToLongBits(NEXTAFTER_DD_START_CASES[i][1]);
    992             final long resultBits = Double.doubleToLongBits(Math.nextUp(start));
    993             assertEquals("Result should be next up-number.", nextUpBits,
    994                     resultBits);
    995         }
    996 
    997         // test for cases with NaN
    998         assertTrue("The result should be NaN.", Double.isNaN(Math
    999                 .nextUp(Double.NaN)));
   1000 
   1001         // test for exception
   1002         try {
   1003             Math.nextUp((Double) null);
   1004             fail("Should throw NullPointerException");
   1005         } catch (NullPointerException e) {
   1006             // Expected
   1007         }
   1008     }
   1009 
   1010     /**
   1011      * @tests {@link java.lang.Math#nextUp(float)}
   1012      * @since 1.6
   1013      */
   1014     @SuppressWarnings("boxing")
   1015     public void test_nextUp_F() {
   1016         // This method is semantically equivalent to nextAfter(f,
   1017         // Float.POSITIVE_INFINITY),
   1018         // so we use the data of test_nextAfter_FD
   1019         for (int i = 0; i < NEXTAFTER_FD_START_CASES.length; i++) {
   1020             final float start = NEXTAFTER_FD_START_CASES[i][0];
   1021             final int nextUpBits = Float
   1022                     .floatToIntBits(NEXTAFTER_FD_START_CASES[i][1]);
   1023             final int resultBits = Float.floatToIntBits(Math.nextUp(start));
   1024             assertEquals("Result should be next up-number.", nextUpBits,
   1025                     resultBits);
   1026         }
   1027 
   1028         // test for cases with NaN
   1029         assertTrue("The result should be NaN.", Float.isNaN(Math
   1030                 .nextUp(Float.NaN)));
   1031 
   1032         // test for exception
   1033         try {
   1034             Math.nextUp((Float) null);
   1035             fail("Should throw NullPointerException");
   1036         } catch (NullPointerException e) {
   1037             // Expected
   1038         }
   1039     }
   1040 
   1041 	/**
   1042 	 * @tests java.lang.Math#pow(double, double)
   1043 	 */
   1044 	public void test_powDD() {
   1045 		// Test for method double java.lang.Math.pow(double, double)
   1046         double NZERO = longTodouble(doubleTolong(0.0) ^ 0x8000000000000000L);
   1047         double p1 = 1.0;
   1048         double p2 = 2.0;
   1049         double p3 = 3.0;
   1050         double p4 = 4.0;
   1051         double p5 = 5.0;
   1052         double p6 = 6.0;
   1053         double p7 = 7.0;
   1054         double p8 = 8.0;
   1055         double p9 = 9.0;
   1056         double p10 = 10.0;
   1057         double p11 = 11.0;
   1058         double p12 = 12.0;
   1059         double p13 = 13.0;
   1060         double p14 = 14.0;
   1061         double p15 = 15.0;
   1062         double p16 = 16.0;
   1063         double[] values = { p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12,
   1064                 p13, p14, p15, p16 };
   1065 
   1066         for (int x = 0; x < values.length; x++) {
   1067             double dval = values[x];
   1068             double nagateDval = negateDouble(dval);
   1069             if (nagateDval == Double.NaN) {
   1070                 continue;
   1071             }
   1072 
   1073             // If the second argument is positive or negative zero, then the
   1074             // result is 1.0.
   1075             assertEquals("Result should be Math.pow(" + dval
   1076                     + ",-0.0)=+1.0", 1.0, Math.pow(dval, NZERO));
   1077             assertEquals("Result should be Math.pow(" + nagateDval
   1078                     + ",-0.0)=+1.0", 1.0, Math.pow(nagateDval, NZERO));
   1079             assertEquals("Result should be Math.pow(" + dval
   1080                     + ",+0.0)=+1.0", 1.0, Math.pow(dval, +0.0));
   1081             assertEquals("Result should be Math.pow(" + nagateDval
   1082                     + ",+0.0)=+1.0", 1.0, Math.pow(nagateDval, +0.0));
   1083 
   1084             // If the second argument is 1.0, then the result is the same as the
   1085             // first argument.
   1086             assertEquals("Result should be Math.pow(" + dval + "," + 1.0 + ")="
   1087                     + dval, dval, Math.pow(dval, 1.0));
   1088             assertEquals("Result should be Math.pow(" + nagateDval + "," + 1.0
   1089                     + ")=" + nagateDval, nagateDval, Math.pow(nagateDval, 1.0));
   1090 
   1091             // If the second argument is NaN, then the result is NaN.
   1092             assertEquals("Result should be Math.pow(" + dval + "," + Double.NaN
   1093                     + ")=" + Double.NaN,  Double.NaN, Math.pow(dval, Double.NaN));
   1094             assertEquals("Result should be Math.pow(" + nagateDval + ","
   1095                     + Double.NaN + ")=" + Double.NaN,  Double.NaN, Math.pow(nagateDval,
   1096                     Double.NaN));
   1097 
   1098             if (dval > 1) {
   1099                 // If the first argument is NaN and the second argument is
   1100                 // nonzero,
   1101                 // then the result is NaN.
   1102                 assertEquals("Result should be Math.pow(" + Double.NaN + ","
   1103                         + dval + ")=" + Double.NaN,  Double.NaN, Math.pow(Double.NaN, dval));
   1104                 assertEquals("Result should be Math.pow(" + Double.NaN + ","
   1105                         + nagateDval + ")=" + Double.NaN,  Double.NaN, Math.pow(Double.NaN,
   1106                         nagateDval));
   1107 
   1108                 /*
   1109                  * If the first argument is positive zero and the second
   1110                  * argument is greater than zero, or the first argument is
   1111                  * positive infinity and the second argument is less than zero,
   1112                  * then the result is positive zero.
   1113                  */
   1114                 assertEquals("Result should be Math.pow(" + 0.0 + "," + dval
   1115                         + ")=" + 0.0, +0.0, Math.pow(0.0, dval));
   1116                 assertEquals("Result should be Math.pow("
   1117                         + Double.POSITIVE_INFINITY + "," + nagateDval + ")="
   1118                         + 0.0, +0.0, Math.pow(Double.POSITIVE_INFINITY, nagateDval));
   1119 
   1120                 /*
   1121                  * If the first argument is positive zero and the second
   1122                  * argument is less than zero, or the first argument is positive
   1123                  * infinity and the second argument is greater than zero, then
   1124                  * the result is positive infinity.
   1125                  */
   1126                 assertEquals("Result should be Math.pow(" + 0.0 + ","
   1127                         + nagateDval + ")=" + Double.POSITIVE_INFINITY,Double.POSITIVE_INFINITY,
   1128                         Math.pow(0.0, nagateDval));
   1129                 assertEquals("Result should be Math.pow("
   1130                         + Double.POSITIVE_INFINITY + "," + dval + ")="
   1131                         + Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Math.pow(
   1132                         Double.POSITIVE_INFINITY, dval));
   1133 
   1134                 // Not a finite odd integer
   1135                 if (dval % 2 == 0) {
   1136                     /*
   1137                      * If the first argument is negative zero and the second
   1138                      * argument is greater than zero but not a finite odd
   1139                      * integer, or the first argument is negative infinity and
   1140                      * the second argument is less than zero but not a finite
   1141                      * odd integer, then the result is positive zero.
   1142                      */
   1143                     assertEquals("Result should be Math.pow(" + NZERO + ","
   1144                             + dval + ")=" + 0.0, +0.0, Math.pow(NZERO, dval));
   1145                     assertEquals("Result should be Math.pow("
   1146                             + Double.NEGATIVE_INFINITY + "," + nagateDval
   1147                             + ")=" + 0.0, +0.0, Math.pow(Double.NEGATIVE_INFINITY,
   1148                             nagateDval));
   1149 
   1150                     /*
   1151                      * If the first argument is negative zero and the second
   1152                      * argument is less than zero but not a finite odd integer,
   1153                      * or the first argument is negative infinity and the second
   1154                      * argument is greater than zero but not a finite odd
   1155                      * integer, then the result is positive infinity.
   1156                      */
   1157                     assertEquals("Result should be Math.pow(" + NZERO + ","
   1158                             + nagateDval + ")=" + Double.POSITIVE_INFINITY,Double.POSITIVE_INFINITY,
   1159                             Math.pow(NZERO, nagateDval));
   1160                     assertEquals("Result should be Math.pow("
   1161                             + Double.NEGATIVE_INFINITY + "," + dval + ")="
   1162                             + Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Math.pow(
   1163                             Double.NEGATIVE_INFINITY, dval));
   1164                 }
   1165 
   1166                 // finite odd integer
   1167                 if (dval % 2 != 0) {
   1168                     /*
   1169                      * If the first argument is negative zero and the second
   1170                      * argument is a positive finite odd integer, or the first
   1171                      * argument is negative infinity and the second argument is
   1172                      * a negative finite odd integer, then the result is
   1173                      * negative zero.
   1174                      */
   1175                     assertEquals("Result should be Math.pow(" + NZERO + ","
   1176                             + dval + ")=" + NZERO, NZERO, Math.pow(NZERO, dval));
   1177                     assertEquals("Result should be Math.pow("
   1178                             + Double.NEGATIVE_INFINITY + "," + nagateDval
   1179                             + ")=" + NZERO, NZERO, Math.pow(Double.NEGATIVE_INFINITY,
   1180                             nagateDval));
   1181                     /*
   1182                      * If the first argument is negative zero and the second
   1183                      * argument is a negative finite odd integer, or the first
   1184                      * argument is negative infinity and the second argument is
   1185                      * a positive finite odd integer then the result is negative
   1186                      * infinity.
   1187                      */
   1188                     assertEquals("Result should be Math.pow(" + NZERO + ","
   1189                             + nagateDval + ")=" + Double.NEGATIVE_INFINITY,Double.NEGATIVE_INFINITY,
   1190                             Math.pow(NZERO, nagateDval));
   1191                     assertEquals("Result should be Math.pow("
   1192                             + Double.NEGATIVE_INFINITY + "," + dval + ")="
   1193                             + Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Math.pow(
   1194                             Double.NEGATIVE_INFINITY, dval));
   1195                 }
   1196 
   1197                 /**
   1198                  * 1. If the first argument is finite and less than zero if the
   1199                  * second argument is a finite even integer, the result is equal
   1200                  * to the result of raising the absolute value of the first
   1201                  * argument to the power of the second argument
   1202                  *
   1203                  * 2. if the second argument is a finite odd integer, the result is equal to the
   1204                  * negative of the result of raising the absolute value of the
   1205                  * first argument to the power of the second argument
   1206                  *
   1207                  * 3. if the second argument is finite and not an integer, then the result
   1208                  * is NaN.
   1209                  */
   1210                 for (int j = 1; j < values.length; j++) {
   1211                     double jval = values[j];
   1212                     if (jval % 2.0 == 0.0) {
   1213                         assertEquals("" + nagateDval + " " + jval, Math.pow(
   1214                                 dval, jval), Math.pow(nagateDval, jval));
   1215                     } else {
   1216                         assertEquals("" + nagateDval + " " + jval, -1.0
   1217                                 * Math.pow(dval, jval), Math.pow(nagateDval,
   1218                                 jval));
   1219                     }
   1220                     assertEquals(Double.NaN, Math
   1221                             .pow(nagateDval, jval / 0.5467));
   1222                     assertEquals(Double.NaN, Math.pow(nagateDval, -1.0 * jval
   1223                             / 0.5467));
   1224                 }
   1225             }
   1226 
   1227             // If the absolute value of the first argument equals 1 and the
   1228             // second argument is infinite, then the result is NaN.
   1229             if (dval == 1) {
   1230                 assertEquals("Result should be Math.pow(" + dval + ","
   1231                         + Double.POSITIVE_INFINITY + ")=" + Double.NaN, Double.NaN, Math
   1232                         .pow(dval, Double.POSITIVE_INFINITY));
   1233                 assertEquals("Result should be Math.pow(" + dval + ","
   1234                         + Double.NEGATIVE_INFINITY + ")=" + Double.NaN, Double.NaN, Math
   1235                         .pow(dval, Double.NEGATIVE_INFINITY));
   1236 
   1237                 assertEquals("Result should be Math.pow(" + nagateDval + ","
   1238                         + Double.POSITIVE_INFINITY + ")=" + Double.NaN, Double.NaN, Math
   1239                         .pow(nagateDval, Double.POSITIVE_INFINITY));
   1240                 assertEquals("Result should be Math.pow(" + nagateDval + ","
   1241                         + Double.NEGATIVE_INFINITY + ")=" + Double.NaN, Double.NaN, Math
   1242                         .pow(nagateDval, Double.NEGATIVE_INFINITY));
   1243             }
   1244 
   1245             if (dval > 1) {
   1246                 /*
   1247                  * If the absolute value of the first argument is greater than 1
   1248                  * and the second argument is positive infinity, or the absolute
   1249                  * value of the first argument is less than 1 and the second
   1250                  * argument is negative infinity, then the result is positive
   1251                  * infinity.
   1252                  */
   1253                 assertEquals("Result should be Math.pow(" + dval + ","
   1254                         + Double.POSITIVE_INFINITY + ")="
   1255                         + Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Math.pow(dval,
   1256                         Double.POSITIVE_INFINITY));
   1257 
   1258                 assertEquals("Result should be Math.pow(" + nagateDval + ","
   1259                         + Double.NEGATIVE_INFINITY + ")="
   1260                         + Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Math.pow(-0.13456,
   1261                         Double.NEGATIVE_INFINITY));
   1262 
   1263                 /*
   1264                  * If the absolute value of the first argument is greater than 1
   1265                  * and the second argument is negative infinity, or the absolute
   1266                  * value of the first argument is less than 1 and the second
   1267                  * argument is positive infinity, then the result is positive
   1268                  * zero.
   1269                  */
   1270                 assertEquals("Result should be Math.pow(" + dval + ","
   1271                         + Double.NEGATIVE_INFINITY + ")= +0.0", +0.0, Math.pow(dval,
   1272                         Double.NEGATIVE_INFINITY));
   1273                 assertEquals("Result should be Math.pow(" + nagateDval + ","
   1274                         + Double.POSITIVE_INFINITY + ")= +0.0", +0.0, Math.pow(
   1275                         -0.13456, Double.POSITIVE_INFINITY));
   1276             }
   1277 
   1278             assertEquals("Result should be Math.pow(" + 0.0 + "," + dval + ")="
   1279                     + 0.0, 0.0, Math.pow(0.0, dval));
   1280             assertEquals("Result should be Math.pow(" + Double.NaN + "," + dval
   1281                     + ")=" + Double.NaN, Double.NaN, Math.pow(Double.NaN, dval));
   1282         }
   1283 		assertTrue("pow returned incorrect value",
   1284 				(long) Math.pow(2, 8) == 256l);
   1285 		assertTrue("pow returned incorrect value",
   1286 				Math.pow(2, -8) == 0.00390625d);
   1287 		assertEquals("Incorrect root returned1",
   1288                              2, Math.sqrt(Math.pow(Math.sqrt(2), 4)), 0);
   1289 
   1290 		assertEquals(Double.NEGATIVE_INFINITY, Math.pow(-10.0, 3.093403029238847E15));
   1291 		assertEquals(Double.POSITIVE_INFINITY, Math.pow(10.0, 3.093403029238847E15));
   1292 	}
   1293 
   1294     private double longTodouble(long longvalue) {
   1295         return Double.longBitsToDouble(longvalue);
   1296     }
   1297 
   1298     private long doubleTolong(double doublevalue) {
   1299         return Double.doubleToLongBits(doublevalue);
   1300     }
   1301 
   1302     private double negateDouble(double doublevalue) {
   1303         return doublevalue * -1.0;
   1304     }
   1305 
   1306 	/**
   1307 	 * @tests java.lang.Math#rint(double)
   1308 	 */
   1309 	public void test_rintD() {
   1310 		// Test for method double java.lang.Math.rint(double)
   1311 		assertEquals("Failed to round properly - up to odd",
   1312 				3.0, Math.rint(2.9), 0D);
   1313 		assertTrue("Failed to round properly - NaN", Double.isNaN(Math
   1314 				.rint(Double.NaN)));
   1315 		assertEquals("Failed to round properly down  to even",
   1316 				2.0, Math.rint(2.1), 0D);
   1317 		assertTrue("Failed to round properly " + 2.5 + " to even", Math
   1318 				.rint(2.5) == 2.0);
   1319                 assertTrue("Failed to round properly " + (+0.0d),
   1320                         Math.rint(+0.0d) == +0.0d);
   1321                 assertTrue("Failed to round properly " + (-0.0d),
   1322                         Math.rint(-0.0d) == -0.0d);
   1323 	}
   1324 
   1325 	/**
   1326 	 * @tests java.lang.Math#round(double)
   1327 	 */
   1328 	public void test_roundD() {
   1329 		// Test for method long java.lang.Math.round(double)
   1330 		assertEquals("Incorrect rounding of a float", -91, Math.round(-90.89d));
   1331 	}
   1332 
   1333 	/**
   1334 	 * @tests java.lang.Math#round(float)
   1335 	 */
   1336 	public void test_roundF() {
   1337 		// Test for method int java.lang.Math.round(float)
   1338 		assertEquals("Incorrect rounding of a float", -91, Math.round(-90.89f));
   1339 	}
   1340 
   1341 	/**
   1342      * @tests {@link java.lang.Math#scalb(double, int)}
   1343      * @since 1.6
   1344      */
   1345     @SuppressWarnings("boxing")
   1346     public void test_scalb_DI() {
   1347         // result is normal
   1348         assertEquals(4.1422946304E7, Math.scalb(1.2345, 25));
   1349         assertEquals(3.679096698760986E-8, Math.scalb(1.2345, -25));
   1350         assertEquals(1.2345, Math.scalb(1.2345, 0));
   1351         assertEquals(7868514.304, Math.scalb(0.2345, 25));
   1352 
   1353         double normal = Math.scalb(0.2345, -25);
   1354         assertEquals(6.98864459991455E-9, normal);
   1355         // precision kept
   1356         assertEquals(0.2345, Math.scalb(normal, 25));
   1357 
   1358         assertEquals(0.2345, Math.scalb(0.2345, 0));
   1359         assertEquals(-4.1422946304E7, Math.scalb(-1.2345, 25));
   1360         assertEquals(-6.98864459991455E-9, Math.scalb(-0.2345, -25));
   1361         assertEquals(2.0, Math.scalb(Double.MIN_NORMAL / 2, 1024));
   1362         assertEquals(64.0, Math.scalb(Double.MIN_VALUE, 1080));
   1363         assertEquals(234, Math.getExponent(Math.scalb(1.0, 234)));
   1364         assertEquals(3.9999999999999996, Math.scalb(Double.MAX_VALUE,
   1365                 Double.MIN_EXPONENT));
   1366 
   1367         // result is near infinity
   1368         double halfMax = Math.scalb(1.0, Double.MAX_EXPONENT);
   1369         assertEquals(8.98846567431158E307, halfMax);
   1370         assertEquals(Double.MAX_VALUE, halfMax - Math.ulp(halfMax) + halfMax);
   1371         assertEquals(Double.POSITIVE_INFINITY, halfMax + halfMax);
   1372         assertEquals(1.7976931348623155E308, Math.scalb(1.0 - Math.ulp(1.0),
   1373                 Double.MAX_EXPONENT + 1));
   1374         assertEquals(Double.POSITIVE_INFINITY, Math.scalb(1.0 - Math.ulp(1.0),
   1375                 Double.MAX_EXPONENT + 2));
   1376 
   1377         halfMax = Math.scalb(-1.0, Double.MAX_EXPONENT);
   1378         assertEquals(-8.98846567431158E307, halfMax);
   1379         assertEquals(-Double.MAX_VALUE, halfMax + Math.ulp(halfMax) + halfMax);
   1380         assertEquals(Double.NEGATIVE_INFINITY, halfMax + halfMax);
   1381 
   1382         assertEquals(Double.POSITIVE_INFINITY, Math.scalb(0.345, 1234));
   1383         assertEquals(Double.POSITIVE_INFINITY, Math.scalb(44.345E102, 934));
   1384         assertEquals(Double.NEGATIVE_INFINITY, Math.scalb(-44.345E102, 934));
   1385 
   1386         assertEquals(Double.POSITIVE_INFINITY, Math.scalb(
   1387                 Double.MIN_NORMAL / 2, 4000));
   1388         assertEquals(Double.POSITIVE_INFINITY, Math.scalb(Double.MIN_VALUE,
   1389                 8000));
   1390         assertEquals(Double.POSITIVE_INFINITY, Math.scalb(Double.MAX_VALUE, 1));
   1391         assertEquals(Double.POSITIVE_INFINITY, Math.scalb(
   1392                 Double.POSITIVE_INFINITY, 0));
   1393         assertEquals(Double.POSITIVE_INFINITY, Math.scalb(
   1394                 Double.POSITIVE_INFINITY, -1));
   1395         assertEquals(Double.NEGATIVE_INFINITY, Math.scalb(
   1396                 Double.NEGATIVE_INFINITY, -1));
   1397         assertEquals(Double.NEGATIVE_INFINITY, Math.scalb(
   1398                 Double.NEGATIVE_INFINITY, Double.MIN_EXPONENT));
   1399 
   1400         // result is subnormal/zero
   1401         long posZeroBits = Double.doubleToLongBits(+0.0);
   1402         long negZeroBits = Double.doubleToLongBits(-0.0);
   1403         assertEquals(posZeroBits, Double.doubleToLongBits(Math.scalb(+0.0,
   1404                 Integer.MAX_VALUE)));
   1405         assertEquals(posZeroBits, Double.doubleToLongBits(Math
   1406                 .scalb(+0.0, -123)));
   1407         assertEquals(posZeroBits, Double.doubleToLongBits(Math.scalb(+0.0, 0)));
   1408         assertEquals(negZeroBits, Double
   1409                 .doubleToLongBits(Math.scalb(-0.0, 123)));
   1410         assertEquals(negZeroBits, Double.doubleToLongBits(Math.scalb(-0.0,
   1411                 Integer.MIN_VALUE)));
   1412 
   1413         assertEquals(Double.MIN_VALUE, Math.scalb(1.0, -1074));
   1414         assertEquals(posZeroBits, Double.doubleToLongBits(Math
   1415                 .scalb(1.0, -1075)));
   1416         assertEquals(negZeroBits, Double.doubleToLongBits(Math.scalb(-1.0,
   1417                 -1075)));
   1418 
   1419         // precision lost
   1420         assertEquals(Math.scalb(21.405, -1078), Math.scalb(21.405, -1079));
   1421         assertEquals(Double.MIN_VALUE, Math.scalb(21.405, -1079));
   1422         assertEquals(-Double.MIN_VALUE, Math.scalb(-21.405, -1079));
   1423         assertEquals(posZeroBits, Double.doubleToLongBits(Math.scalb(21.405,
   1424                 -1080)));
   1425         assertEquals(negZeroBits, Double.doubleToLongBits(Math.scalb(-21.405,
   1426                 -1080)));
   1427         assertEquals(posZeroBits, Double.doubleToLongBits(Math.scalb(
   1428                 Double.MIN_VALUE, -1)));
   1429         assertEquals(negZeroBits, Double.doubleToLongBits(Math.scalb(
   1430                 -Double.MIN_VALUE, -1)));
   1431         assertEquals(Double.MIN_VALUE, Math.scalb(Double.MIN_NORMAL, -52));
   1432         assertEquals(posZeroBits, Double.doubleToLongBits(Math.scalb(
   1433                 Double.MIN_NORMAL, -53)));
   1434         assertEquals(negZeroBits, Double.doubleToLongBits(Math.scalb(
   1435                 -Double.MIN_NORMAL, -53)));
   1436         assertEquals(Double.MIN_VALUE, Math.scalb(Double.MAX_VALUE, -2098));
   1437         assertEquals(posZeroBits, Double.doubleToLongBits(Math.scalb(
   1438                 Double.MAX_VALUE, -2099)));
   1439         assertEquals(negZeroBits, Double.doubleToLongBits(Math.scalb(
   1440                 -Double.MAX_VALUE, -2099)));
   1441         assertEquals(Double.MIN_VALUE, Math.scalb(Double.MIN_NORMAL / 3, -51));
   1442         assertEquals(posZeroBits, Double.doubleToLongBits(Math.scalb(
   1443                 Double.MIN_NORMAL / 3, -52)));
   1444         assertEquals(negZeroBits, Double.doubleToLongBits(Math.scalb(
   1445                 -Double.MIN_NORMAL / 3, -52)));
   1446         double subnormal = Math.scalb(Double.MIN_NORMAL / 3, -25);
   1447         assertEquals(2.2104123E-316, subnormal);
   1448         // precision lost
   1449         assertFalse(Double.MIN_NORMAL / 3 == Math.scalb(subnormal, 25));
   1450 
   1451         // NaN
   1452         assertTrue(Double.isNaN(Math.scalb(Double.NaN, 1)));
   1453         assertTrue(Double.isNaN(Math.scalb(Double.NaN, 0)));
   1454         assertTrue(Double.isNaN(Math.scalb(Double.NaN, -120)));
   1455 
   1456         assertEquals(1283457024, Double.doubleToLongBits(Math.scalb(
   1457                 Double.MIN_VALUE * 153, 23)));
   1458         assertEquals(-9223372035571318784L, Double.doubleToLongBits(Math.scalb(
   1459                 -Double.MIN_VALUE * 153, 23)));
   1460         assertEquals(36908406321184768L, Double.doubleToLongBits(Math.scalb(
   1461                 Double.MIN_VALUE * 153, 52)));
   1462         assertEquals(-9186463630533591040L, Double.doubleToLongBits(Math.scalb(
   1463                 -Double.MIN_VALUE * 153, 52)));
   1464 
   1465         // test for exception
   1466         try {
   1467             Math.scalb((Double) null, (Integer) null);
   1468             fail("Should throw NullPointerException");
   1469         } catch (NullPointerException e) {
   1470             // Expected
   1471         }
   1472         try {
   1473             Math.scalb(1.0, (Integer) null);
   1474             fail("Should throw NullPointerException");
   1475         } catch (NullPointerException e) {
   1476             // Expected
   1477         }
   1478         try {
   1479             Math.scalb((Double) null, 1);
   1480             fail("Should throw NullPointerException");
   1481         } catch (NullPointerException e) {
   1482             // Expected
   1483         }
   1484 
   1485         long b1em1022 = 0x0010000000000000L; // bit representation of
   1486                                                 // Double.MIN_NORMAL
   1487         long b1em1023 = 0x0008000000000000L; // bit representation of half of
   1488                                                 // Double.MIN_NORMAL
   1489         // assert exact identity
   1490         assertEquals(b1em1023, Double.doubleToLongBits(Math.scalb(Double
   1491                 .longBitsToDouble(b1em1022), -1)));
   1492     }
   1493 
   1494     /**
   1495      * @tests {@link java.lang.Math#scalb(float, int)}
   1496      * @since 1.6
   1497      */
   1498     @SuppressWarnings("boxing")
   1499     public void test_scalb_FI() {
   1500         // result is normal
   1501         assertEquals(4.1422946304E7f, Math.scalb(1.2345f, 25));
   1502         assertEquals(3.679096698760986E-8f, Math.scalb(1.2345f, -25));
   1503         assertEquals(1.2345f, Math.scalb(1.2345f, 0));
   1504         assertEquals(7868514.304f, Math.scalb(0.2345f, 25));
   1505 
   1506         float normal = Math.scalb(0.2345f, -25);
   1507         assertEquals(6.98864459991455E-9f, normal);
   1508         // precision kept
   1509         assertEquals(0.2345f, Math.scalb(normal, 25));
   1510 
   1511         assertEquals(0.2345f, Math.scalb(0.2345f, 0));
   1512         assertEquals(-4.1422946304E7f, Math.scalb(-1.2345f, 25));
   1513         assertEquals(-6.98864459991455E-9f, Math.scalb(-0.2345f, -25));
   1514         assertEquals(2.0f, Math.scalb(Float.MIN_NORMAL / 2, 128));
   1515         assertEquals(64.0f, Math.scalb(Float.MIN_VALUE, 155));
   1516         assertEquals(34, Math.getExponent(Math.scalb(1.0f, 34)));
   1517         assertEquals(3.9999998f, Math
   1518                 .scalb(Float.MAX_VALUE, Float.MIN_EXPONENT));
   1519 
   1520         // result is near infinity
   1521         float halfMax = Math.scalb(1.0f, Float.MAX_EXPONENT);
   1522         assertEquals(1.7014118E38f, halfMax);
   1523         assertEquals(Float.MAX_VALUE, halfMax - Math.ulp(halfMax) + halfMax);
   1524         assertEquals(Float.POSITIVE_INFINITY, halfMax + halfMax);
   1525         assertEquals(3.4028233E38f, Math.scalb(1.0f - Math.ulp(1.0f),
   1526                 Float.MAX_EXPONENT + 1));
   1527         assertEquals(Float.POSITIVE_INFINITY, Math.scalb(1.0f - Math.ulp(1.0f),
   1528                 Float.MAX_EXPONENT + 2));
   1529 
   1530         halfMax = Math.scalb(-1.0f, Float.MAX_EXPONENT);
   1531         assertEquals(-1.7014118E38f, halfMax);
   1532         assertEquals(-Float.MAX_VALUE, halfMax + Math.ulp(halfMax) + halfMax);
   1533         assertEquals(Float.NEGATIVE_INFINITY, halfMax + halfMax);
   1534 
   1535         assertEquals(Float.POSITIVE_INFINITY, Math.scalb(0.345f, 1234));
   1536         assertEquals(Float.POSITIVE_INFINITY, Math.scalb(44.345E10f, 934));
   1537         assertEquals(Float.NEGATIVE_INFINITY, Math.scalb(-44.345E10f, 934));
   1538 
   1539         assertEquals(Float.POSITIVE_INFINITY, Math.scalb(Float.MIN_NORMAL / 2,
   1540                 400));
   1541         assertEquals(Float.POSITIVE_INFINITY, Math.scalb(Float.MIN_VALUE, 800));
   1542         assertEquals(Float.POSITIVE_INFINITY, Math.scalb(Float.MAX_VALUE, 1));
   1543         assertEquals(Float.POSITIVE_INFINITY, Math.scalb(
   1544                 Float.POSITIVE_INFINITY, 0));
   1545         assertEquals(Float.POSITIVE_INFINITY, Math.scalb(
   1546                 Float.POSITIVE_INFINITY, -1));
   1547         assertEquals(Float.NEGATIVE_INFINITY, Math.scalb(
   1548                 Float.NEGATIVE_INFINITY, -1));
   1549         assertEquals(Float.NEGATIVE_INFINITY, Math.scalb(
   1550                 Float.NEGATIVE_INFINITY, Float.MIN_EXPONENT));
   1551 
   1552         // result is subnormal/zero
   1553         int posZeroBits = Float.floatToIntBits(+0.0f);
   1554         int negZeroBits = Float.floatToIntBits(-0.0f);
   1555         assertEquals(posZeroBits, Float.floatToIntBits(Math.scalb(+0.0f,
   1556                 Integer.MAX_VALUE)));
   1557         assertEquals(posZeroBits, Float.floatToIntBits(Math.scalb(+0.0f, -123)));
   1558         assertEquals(posZeroBits, Float.floatToIntBits(Math.scalb(+0.0f, 0)));
   1559         assertEquals(negZeroBits, Float.floatToIntBits(Math.scalb(-0.0f, 123)));
   1560         assertEquals(negZeroBits, Float.floatToIntBits(Math.scalb(-0.0f,
   1561                 Integer.MIN_VALUE)));
   1562 
   1563         assertEquals(Float.MIN_VALUE, Math.scalb(1.0f, -149));
   1564         assertEquals(posZeroBits, Float.floatToIntBits(Math.scalb(1.0f, -150)));
   1565         assertEquals(negZeroBits, Float.floatToIntBits(Math.scalb(-1.0f, -150)));
   1566 
   1567         // precision lost
   1568         assertEquals(Math.scalb(21.405f, -154), Math.scalb(21.405f, -153));
   1569         assertEquals(Float.MIN_VALUE, Math.scalb(21.405f, -154));
   1570         assertEquals(-Float.MIN_VALUE, Math.scalb(-21.405f, -154));
   1571         assertEquals(posZeroBits, Float.floatToIntBits(Math
   1572                 .scalb(21.405f, -155)));
   1573         assertEquals(negZeroBits, Float.floatToIntBits(Math.scalb(-21.405f,
   1574                 -155)));
   1575         assertEquals(posZeroBits, Float.floatToIntBits(Math.scalb(
   1576                 Float.MIN_VALUE, -1)));
   1577         assertEquals(negZeroBits, Float.floatToIntBits(Math.scalb(
   1578                 -Float.MIN_VALUE, -1)));
   1579         assertEquals(Float.MIN_VALUE, Math.scalb(Float.MIN_NORMAL, -23));
   1580         assertEquals(posZeroBits, Float.floatToIntBits(Math.scalb(
   1581                 Float.MIN_NORMAL, -24)));
   1582         assertEquals(negZeroBits, Float.floatToIntBits(Math.scalb(
   1583                 -Float.MIN_NORMAL, -24)));
   1584         assertEquals(Float.MIN_VALUE, Math.scalb(Float.MAX_VALUE, -277));
   1585         assertEquals(posZeroBits, Float.floatToIntBits(Math.scalb(
   1586                 Float.MAX_VALUE, -278)));
   1587         assertEquals(negZeroBits, Float.floatToIntBits(Math.scalb(
   1588                 -Float.MAX_VALUE, -278)));
   1589         assertEquals(Float.MIN_VALUE, Math.scalb(Float.MIN_NORMAL / 3, -22));
   1590         assertEquals(posZeroBits, Float.floatToIntBits(Math.scalb(
   1591                 Float.MIN_NORMAL / 3, -23)));
   1592         assertEquals(negZeroBits, Float.floatToIntBits(Math.scalb(
   1593                 -Float.MIN_NORMAL / 3, -23)));
   1594         float subnormal = Math.scalb(Float.MIN_NORMAL / 3, -11);
   1595         assertEquals(1.913E-42f, subnormal);
   1596         // precision lost
   1597         assertFalse(Float.MIN_NORMAL / 3 == Math.scalb(subnormal, 11));
   1598 
   1599         assertEquals(68747264, Float.floatToIntBits(Math.scalb(
   1600                 Float.MIN_VALUE * 153, 23)));
   1601         assertEquals(-2078736384, Float.floatToIntBits(Math.scalb(
   1602                 -Float.MIN_VALUE * 153, 23)));
   1603 
   1604         assertEquals(4896, Float.floatToIntBits(Math.scalb(
   1605                 Float.MIN_VALUE * 153, 5)));
   1606         assertEquals(-2147478752, Float.floatToIntBits(Math.scalb(
   1607                 -Float.MIN_VALUE * 153, 5)));
   1608 
   1609         // NaN
   1610         assertTrue(Float.isNaN(Math.scalb(Float.NaN, 1)));
   1611         assertTrue(Float.isNaN(Math.scalb(Float.NaN, 0)));
   1612         assertTrue(Float.isNaN(Math.scalb(Float.NaN, -120)));
   1613 
   1614         // test for exception
   1615         try {
   1616             Math.scalb((Float) null, (Integer) null);
   1617             fail("Should throw NullPointerException");
   1618         } catch (NullPointerException e) {
   1619             // Expected
   1620         }
   1621         try {
   1622             Math.scalb(1.0f, (Integer) null);
   1623             fail("Should throw NullPointerException");
   1624         } catch (NullPointerException e) {
   1625             // Expected
   1626         }
   1627         try {
   1628             Math.scalb((Float) null, 1);
   1629             fail("Should throw NullPointerException");
   1630         } catch (NullPointerException e) {
   1631             // Expected
   1632         }
   1633 
   1634         int b1em126 = 0x00800000; // bit representation of Float.MIN_NORMAL
   1635         int b1em127 = 0x00400000; // bit representation of half
   1636                                     // Float.MIN_NORMAL
   1637         // assert exact identity
   1638         assertEquals(b1em127, Float.floatToIntBits(Math.scalb(Float
   1639                 .intBitsToFloat(b1em126), -1)));
   1640     }
   1641 
   1642     /**
   1643      * @tests java.lang.Math#signum(double)
   1644      */
   1645     public void test_signum_D() {
   1646         assertTrue(Double.isNaN(Math.signum(Double.NaN)));
   1647         assertTrue(Double.isNaN(Math.signum(Double.NaN)));
   1648         assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math
   1649                 .signum(0.0)));
   1650         assertEquals(Double.doubleToLongBits(+0.0), Double
   1651                 .doubleToLongBits(Math.signum(+0.0)));
   1652         assertEquals(Double.doubleToLongBits(-0.0), Double
   1653                 .doubleToLongBits(Math.signum(-0.0)));
   1654 
   1655         assertEquals(1.0, Math.signum(253681.2187962), 0D);
   1656         assertEquals(-1.0, Math.signum(-125874693.56), 0D);
   1657         assertEquals(1.0, Math.signum(1.2587E-308), 0D);
   1658         assertEquals(-1.0, Math.signum(-1.2587E-308), 0D);
   1659 
   1660         assertEquals(1.0, Math.signum(Double.MAX_VALUE), 0D);
   1661         assertEquals(1.0, Math.signum(Double.MIN_VALUE), 0D);
   1662         assertEquals(-1.0, Math.signum(-Double.MAX_VALUE), 0D);
   1663         assertEquals(-1.0, Math.signum(-Double.MIN_VALUE), 0D);
   1664         assertEquals(1.0, Math.signum(Double.POSITIVE_INFINITY), 0D);
   1665         assertEquals(-1.0, Math.signum(Double.NEGATIVE_INFINITY), 0D);
   1666     }
   1667 
   1668     /**
   1669      * @tests java.lang.Math#signum(float)
   1670      */
   1671     public void test_signum_F() {
   1672         assertTrue(Float.isNaN(Math.signum(Float.NaN)));
   1673         assertEquals(Float.floatToIntBits(0.0f), Float
   1674                 .floatToIntBits(Math.signum(0.0f)));
   1675         assertEquals(Float.floatToIntBits(+0.0f), Float
   1676                 .floatToIntBits(Math.signum(+0.0f)));
   1677         assertEquals(Float.floatToIntBits(-0.0f), Float
   1678                 .floatToIntBits(Math.signum(-0.0f)));
   1679 
   1680         assertEquals(1.0f, Math.signum(253681.2187962f), 0f);
   1681         assertEquals(-1.0f, Math.signum(-125874693.56f), 0f);
   1682         assertEquals(1.0f, Math.signum(1.2587E-11f), 0f);
   1683         assertEquals(-1.0f, Math.signum(-1.2587E-11f), 0f);
   1684 
   1685         assertEquals(1.0f, Math.signum(Float.MAX_VALUE), 0f);
   1686         assertEquals(1.0f, Math.signum(Float.MIN_VALUE), 0f);
   1687         assertEquals(-1.0f, Math.signum(-Float.MAX_VALUE), 0f);
   1688         assertEquals(-1.0f, Math.signum(-Float.MIN_VALUE), 0f);
   1689         assertEquals(1.0f, Math.signum(Float.POSITIVE_INFINITY), 0f);
   1690         assertEquals(-1.0f, Math.signum(Float.NEGATIVE_INFINITY), 0f);
   1691     }
   1692 
   1693 	/**
   1694      * @tests java.lang.Math#sin(double)
   1695      */
   1696 	public void test_sinD() {
   1697 		// Test for method double java.lang.Math.sin(double)
   1698 		assertEquals("Incorrect answer", 0.0, Math.sin(0), 0D);
   1699 		assertEquals("Incorrect answer", 0.8414709848078965, Math.sin(1), 0D);
   1700 	}
   1701 
   1702     /**
   1703      * @tests java.lang.Math#sinh(double)
   1704      */
   1705     public void test_sinh_D() {
   1706         // Test for special situations
   1707         assertTrue("Should return NaN", Double.isNaN(Math.sinh(Double.NaN)));
   1708         assertEquals("Should return POSITIVE_INFINITY",
   1709                 Double.POSITIVE_INFINITY, Math.sinh(Double.POSITIVE_INFINITY), 0D);
   1710         assertEquals("Should return NEGATIVE_INFINITY",
   1711                 Double.NEGATIVE_INFINITY, Math.sinh(Double.NEGATIVE_INFINITY), 0D);
   1712         assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math
   1713 				.sinh(0.0)));
   1714 		assertEquals(Double.doubleToLongBits(+0.0), Double
   1715 				.doubleToLongBits(Math.sinh(+0.0)));
   1716 		assertEquals(Double.doubleToLongBits(-0.0), Double
   1717 				.doubleToLongBits(Math.sinh(-0.0)));
   1718 
   1719         assertEquals("Should return POSITIVE_INFINITY",
   1720                 Double.POSITIVE_INFINITY, Math.sinh(1234.56), 0D);
   1721         assertEquals("Should return NEGATIVE_INFINITY",
   1722                 Double.NEGATIVE_INFINITY, Math.sinh(-1234.56), 0D);
   1723         assertEquals("Should return 1.0000000000001666E-6",
   1724                 1.0000000000001666E-6, Math.sinh(0.000001), 0D);
   1725         assertEquals("Should return -1.0000000000001666E-6",
   1726                 -1.0000000000001666E-6, Math.sinh(-0.000001), 0D);
   1727         assertEquals("Should return 5.115386441963859", 5.115386441963859, Math
   1728                 .sinh(2.33482), 0D);
   1729         assertEquals("Should return POSITIVE_INFINITY",
   1730                 Double.POSITIVE_INFINITY, Math.sinh(Double.MAX_VALUE), 0D);
   1731         assertEquals("Should return 4.9E-324", 4.9E-324, Math
   1732                 .sinh(Double.MIN_VALUE), 0D);
   1733     }
   1734 
   1735 	/**
   1736 	 * @tests java.lang.Math#sqrt(double)
   1737 	 */
   1738 	public void test_sqrtD() {
   1739 		// Test for method double java.lang.Math.sqrt(double)
   1740                 assertEquals("Incorrect root returned2", 7, Math.sqrt(49), 0);
   1741 	}
   1742 
   1743 	/**
   1744 	 * @tests java.lang.Math#tan(double)
   1745 	 */
   1746 	public void test_tanD() {
   1747 		// Test for method double java.lang.Math.tan(double)
   1748 		assertEquals("Incorrect answer", 0.0, Math.tan(0), 0D);
   1749 		assertEquals("Incorrect answer", 1.5574077246549023, Math.tan(1), 0D);
   1750 
   1751 	}
   1752 
   1753     /**
   1754      * @tests java.lang.Math#tanh(double)
   1755      */
   1756     public void test_tanh_D() {
   1757         // Test for special situations
   1758         assertTrue("Should return NaN", Double.isNaN(Math.tanh(Double.NaN)));
   1759         assertEquals("Should return +1.0", +1.0, Math
   1760                 .tanh(Double.POSITIVE_INFINITY), 0D);
   1761         assertEquals("Should return -1.0", -1.0, Math
   1762                 .tanh(Double.NEGATIVE_INFINITY), 0D);
   1763         assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math
   1764 				.tanh(0.0)));
   1765 		assertEquals(Double.doubleToLongBits(+0.0), Double
   1766 				.doubleToLongBits(Math.tanh(+0.0)));
   1767 		assertEquals(Double.doubleToLongBits(-0.0), Double
   1768 				.doubleToLongBits(Math.tanh(-0.0)));
   1769 
   1770         assertEquals("Should return 1.0", 1.0, Math.tanh(1234.56), 0D);
   1771         assertEquals("Should return -1.0", -1.0, Math.tanh(-1234.56), 0D);
   1772         assertEquals("Should return 9.999999999996666E-7",
   1773                 9.999999999996666E-7, Math.tanh(0.000001), 0D);
   1774         assertEquals("Should return 0.981422884124941", 0.981422884124941, Math
   1775                 .tanh(2.33482), 0D);
   1776         assertEquals("Should return 1.0", 1.0, Math.tanh(Double.MAX_VALUE), 0D);
   1777         assertEquals("Should return 4.9E-324", 4.9E-324, Math
   1778                 .tanh(Double.MIN_VALUE), 0D);
   1779     }
   1780 
   1781 	/**
   1782 	 * @tests java.lang.Math#random()
   1783 	 */
   1784 	public void test_random() {
   1785 		// There isn't a place for these tests so just stick them here
   1786 		assertEquals("Wrong value E",
   1787 				4613303445314885481L, Double.doubleToLongBits(Math.E));
   1788 		assertEquals("Wrong value PI",
   1789 				4614256656552045848L, Double.doubleToLongBits(Math.PI));
   1790 
   1791 		for (int i = 500; i >= 0; i--) {
   1792 			double d = Math.random();
   1793 			assertTrue("Generated number is out of range: " + d, d >= 0.0
   1794 					&& d < 1.0);
   1795 		}
   1796 	}
   1797 
   1798 	/**
   1799 	 * @tests java.lang.Math#toRadians(double)
   1800 	 */
   1801 	public void test_toRadiansD() {
   1802 		for (double d = 500; d >= 0; d -= 1.0) {
   1803 			double converted = Math.toDegrees(Math.toRadians(d));
   1804 			assertTrue("Converted number not equal to original. d = " + d,
   1805 					converted >= d * 0.99999999 && converted <= d * 1.00000001);
   1806 		}
   1807 	}
   1808 
   1809 	/**
   1810 	 * @tests java.lang.Math#toDegrees(double)
   1811 	 */
   1812 	public void test_toDegreesD() {
   1813 		for (double d = 500; d >= 0; d -= 1.0) {
   1814 			double converted = Math.toRadians(Math.toDegrees(d));
   1815 			assertTrue("Converted number not equal to original. d = " + d,
   1816 					converted >= d * 0.99999999 && converted <= d * 1.00000001);
   1817 		}
   1818 	}
   1819 
   1820 	/**
   1821      * @tests java.lang.Math#ulp(double)
   1822      */
   1823     @SuppressWarnings("boxing")
   1824     public void test_ulp_D() {
   1825 		// Test for special cases
   1826 		assertTrue("Should return NaN", Double.isNaN(Math.ulp(Double.NaN)));
   1827 		assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, Math
   1828 				.ulp(Double.POSITIVE_INFINITY), 0D);
   1829 		assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, Math
   1830 				.ulp(Double.NEGATIVE_INFINITY), 0D);
   1831 		assertEquals("Returned incorrect value", Double.MIN_VALUE, Math
   1832 				.ulp(0.0), 0D);
   1833 		assertEquals("Returned incorrect value", Double.MIN_VALUE, Math
   1834 				.ulp(+0.0), 0D);
   1835 		assertEquals("Returned incorrect value", Double.MIN_VALUE, Math
   1836 				.ulp(-0.0), 0D);
   1837 		assertEquals("Returned incorrect value", Math.pow(2, 971), Math
   1838 				.ulp(Double.MAX_VALUE), 0D);
   1839 		assertEquals("Returned incorrect value", Math.pow(2, 971), Math
   1840 				.ulp(-Double.MAX_VALUE), 0D);
   1841 
   1842 		assertEquals("Returned incorrect value", Double.MIN_VALUE, Math
   1843 				.ulp(Double.MIN_VALUE), 0D);
   1844 		assertEquals("Returned incorrect value", Double.MIN_VALUE, Math
   1845 				.ulp(-Double.MIN_VALUE), 0D);
   1846 
   1847 		assertEquals("Returned incorrect value", 2.220446049250313E-16, Math
   1848 				.ulp(1.0), 0D);
   1849 		assertEquals("Returned incorrect value", 2.220446049250313E-16, Math
   1850 				.ulp(-1.0), 0D);
   1851 		assertEquals("Returned incorrect value", 2.2737367544323206E-13, Math
   1852 				.ulp(1153.0), 0D);
   1853 	}
   1854 
   1855 	/**
   1856 	 * @tests java.lang.Math#ulp(float)
   1857 	 */
   1858 	@SuppressWarnings("boxing")
   1859 	public void test_ulp_f() {
   1860 		// Test for special cases
   1861 		assertTrue("Should return NaN", Float.isNaN(Math.ulp(Float.NaN)));
   1862 		assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, Math
   1863 				.ulp(Float.POSITIVE_INFINITY), 0f);
   1864 		assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, Math
   1865 				.ulp(Float.NEGATIVE_INFINITY), 0f);
   1866 		assertEquals("Returned incorrect value", Float.MIN_VALUE, Math
   1867 				.ulp(0.0f), 0f);
   1868 		assertEquals("Returned incorrect value", Float.MIN_VALUE, Math
   1869 				.ulp(+0.0f), 0f);
   1870 		assertEquals("Returned incorrect value", Float.MIN_VALUE, Math
   1871 				.ulp(-0.0f), 0f);
   1872 		assertEquals("Returned incorrect value", 2.028241E31f, Math
   1873 				.ulp(Float.MAX_VALUE), 0f);
   1874 		assertEquals("Returned incorrect value", 2.028241E31f, Math
   1875 				.ulp(-Float.MAX_VALUE), 0f);
   1876 
   1877 		assertEquals("Returned incorrect value", 1.4E-45f, Math
   1878 				.ulp(Float.MIN_VALUE), 0f);
   1879 		assertEquals("Returned incorrect value", 1.4E-45f, Math
   1880 				.ulp(-Float.MIN_VALUE), 0f);
   1881 
   1882 		assertEquals("Returned incorrect value", 1.1920929E-7f, Math.ulp(1.0f),
   1883 				0f);
   1884 		assertEquals("Returned incorrect value", 1.1920929E-7f,
   1885 				Math.ulp(-1.0f), 0f);
   1886 		assertEquals("Returned incorrect value", 1.2207031E-4f, Math
   1887 				.ulp(1153.0f), 0f);
   1888 		assertEquals("Returned incorrect value", 5.6E-45f, Math
   1889 				.ulp(9.403954E-38f), 0f);
   1890     }
   1891 
   1892 	/**
   1893      * @tests {@link java.lang.Math#shiftIntBits(int, int)}
   1894      *
   1895      * @since 1.6
   1896      */
   1897     public void test_shiftIntBits_II() {
   1898         class Tuple {
   1899             public int result;
   1900 
   1901             public int value;
   1902 
   1903             public int factor;
   1904 
   1905             public Tuple(int result, int value, int factor) {
   1906                 this.result = result;
   1907                 this.value = value;
   1908                 this.factor = factor;
   1909             }
   1910         }
   1911         final Tuple[] TUPLES = new Tuple[] {
   1912         // sub-normal to sub-normal
   1913                 new Tuple(0x00000000, 0x00000001, -1),
   1914                 // round to even
   1915                 new Tuple(0x00000002, 0x00000003, -1),
   1916                 // round to even
   1917                 new Tuple(0x00000001, 0x00000005, -3),
   1918                 // round to infinity
   1919                 new Tuple(0x00000002, 0x0000000d, -3),
   1920                 // round to infinity
   1921 
   1922                 // normal to sub-normal
   1923                 new Tuple(0x00000002, 0x01a00000, -24),
   1924                 // round to even
   1925                 new Tuple(0x00000004, 0x01e00000, -24),
   1926                 // round to even
   1927                 new Tuple(0x00000003, 0x01c80000, -24),
   1928                 // round to infinity
   1929                 new Tuple(0x00000004, 0x01e80000, -24),
   1930         // round to infinity
   1931         };
   1932         for (int i = 0; i < TUPLES.length; ++i) {
   1933             Tuple tuple = TUPLES[i];
   1934             assertEquals(tuple.result, Float.floatToIntBits(Math.scalb(Float
   1935                     .intBitsToFloat(tuple.value), tuple.factor)));
   1936             assertEquals(tuple.result, Float.floatToIntBits(-Math.scalb(-Float
   1937                     .intBitsToFloat(tuple.value), tuple.factor)));
   1938         }
   1939     }
   1940 
   1941     /**
   1942      * @tests {@link java.lang.Math#shiftLongBits(long, long)}
   1943      *
   1944      * Round result to nearest value on precision lost.
   1945      *
   1946      * @since 1.6
   1947      */
   1948     public void test_shiftLongBits_LL() {
   1949         class Tuple {
   1950             public long result;
   1951 
   1952             public long value;
   1953 
   1954             public int factor;
   1955 
   1956             public Tuple(long result, long value, int factor) {
   1957                 this.result = result;
   1958                 this.value = value;
   1959                 this.factor = factor;
   1960             }
   1961         }
   1962         final Tuple[] TUPLES = new Tuple[] {
   1963         // sub-normal to sub-normal
   1964                 new Tuple(0x00000000L, 0x00000001L, -1),
   1965                 //round to even
   1966                 new Tuple(0x00000002L, 0x00000003L, -1),
   1967                 //round to even
   1968                 new Tuple(0x00000001L, 0x00000005L, -3),
   1969                 //round to infinity
   1970                 new Tuple(0x00000002L, 0x0000000dL, -3),
   1971                 //round to infinity
   1972 
   1973                 // normal to sub-normal
   1974                 new Tuple(0x0000000000000002L, 0x0034000000000000L, -53), // round to even
   1975                 new Tuple(0x0000000000000004L, 0x003c000000000000L, -53), // round to even
   1976                 new Tuple(0x0000000000000003L, 0x0035000000000000L, -53), // round to infinity
   1977                 new Tuple(0x0000000000000004L, 0x003d000000000000L, -53), // round to infinity
   1978         };
   1979         for (int i = 0; i < TUPLES.length; ++i) {
   1980             Tuple tuple = TUPLES[i];
   1981             assertEquals(tuple.result, Double.doubleToLongBits(Math.scalb(
   1982                     Double.longBitsToDouble(tuple.value), tuple.factor)));
   1983             assertEquals(tuple.result, Double.doubleToLongBits(-Math.scalb(
   1984                     -Double.longBitsToDouble(tuple.value), tuple.factor)));
   1985         }
   1986     }
   1987 }
   1988