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