Home | History | Annotate | Download | only in lang
      1 /* Licensed to the Apache Software Foundation (ASF) under one or more
      2  * contributor license agreements.  See the NOTICE file distributed with
      3  * this work for additional information regarding copyright ownership.
      4  * The ASF licenses this file to You under the Apache License, Version 2.0
      5  * (the "License"); you may not use this file except in compliance with
      6  * the License.  You may obtain a copy of the License at
      7  *
      8  *     http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package org.apache.harmony.luni.tests.java.lang;
     18 
     19 import junit.framework.TestCase;
     20 
     21 public class FloatTest extends TestCase {
     22 
     23     private static final int rawBitsFor3_4eN38To38[] = { 0x1394470, 0x2e7958c, 0x490bd77, 0x634ecd5,
     24             0x7e2280b, 0x98d5907, 0xb30af48, 0xcdcdb1a, 0xe8a08f0, 0x102c8b2d, 0x11d7adf8,
     25             0x1386ccbb, 0x15287fe9, 0x16d29fe4, 0x1883a3ee, 0x1a248cea, 0x1bcdb025, 0x1d808e17,
     26             0x1f20b19d, 0x20c8de04, 0x227b1585, 0x241ced73, 0x25c428d0, 0x27753303, 0x29193fe2,
     27             0x2abf8fdb, 0x2c6f73d1, 0x2e15a863, 0x2fbb127c, 0x3169d71a, 0x33122671, 0x34b6b00d,
     28             0x36645c10, 0x380eb98a, 0x39b267ec, 0x3b5f01e8, 0x3d0b6131, 0x3eae397d, 0x4059c7dc,
     29             0x42081cea, 0x43aa2424, 0x4554ad2d, 0x4704ec3c, 0x48a6274b, 0x4a4fb11e, 0x4c01ceb3,
     30             0x4da2425f, 0x4f4ad2f7, 0x50fd87b5, 0x529e74d1, 0x54461205, 0x55f79687, 0x579abe14,
     31             0x59416d99, 0x5af1c900, 0x5c971da0, 0x5e3ce508, 0x5fec1e4a, 0x619392ee, 0x633877a9,
     32             0x64e69594, 0x66901d7c, 0x683424dc, 0x69e12e12, 0x6b8cbccb, 0x6d2febfe, 0x6edbe6fe,
     33             0x7089705f, 0x722bcc76, 0x73d6bf94, 0x758637bc, 0x7727c5ac, 0x78d1b717, 0x7a83126e,
     34             0x7c23d70a, 0x7dcccccc, 0x7f7fffff };
     35 
     36     private static final String expectedStringFor3_4eN38To38[] = { "3.4028235E-38", "3.4028235E-37",
     37             "3.4028233E-36", "3.4028234E-35", "3.4028236E-34", "3.4028236E-33",
     38             "3.4028234E-32", "3.4028234E-31", "3.4028233E-30", "3.4028236E-29",
     39             "3.4028235E-28", "3.4028235E-27", "3.4028233E-26", "3.4028235E-25",
     40             "3.4028233E-24", "3.4028235E-23", "3.4028236E-22", "3.4028235E-21",
     41             "3.4028236E-20", "3.4028236E-19", "3.4028236E-18", "3.4028235E-17",
     42             "3.4028236E-16", "3.4028234E-15", "3.4028234E-14", "3.4028235E-13",
     43             "3.4028234E-12", "3.4028235E-11", "3.4028236E-10", "3.4028234E-9", "3.4028236E-8",
     44             "3.4028236E-7", "3.4028235E-6", "3.4028235E-5", "3.4028233E-4", "0.0034028236",
     45             "0.034028236", "0.34028235", "3.4028234", "34.028236", "340.28235", "3402.8235",
     46             "34028.234", "340282.34", "3402823.5", "3.4028236E7", "3.40282336E8",
     47             "3.40282342E9", "3.40282348E10", "3.40282343E11", "3.40282337E12", "3.40282353E13",
     48             "3.4028234E14", "3.4028234E15", "3.40282356E16", "3.40282356E17", "3.40282356E18",
     49             "3.4028236E19", "3.4028235E20", "3.4028233E21", "3.4028235E22", "3.4028233E23",
     50             "3.4028236E24", "3.4028234E25", "3.4028233E26", "3.4028234E27", "3.4028235E28",
     51             "3.4028236E29", "3.4028233E30", "3.4028235E31", "3.4028233E32", "3.4028236E33",
     52             "3.4028236E34", "3.4028234E35", "3.4028236E36", "3.4028235E37", "3.4028235E38" };
     53 
     54     private static final int rawBitsFor1_17eN38To38[] = { 0x80800000, 0x82200000, 0x83c80000,
     55             0x857a0000, 0x871c4000, 0x88c35000, 0x8a742400, 0x8c189680, 0x8dbebc20, 0x8f6e6b28,
     56             0x911502f9, 0x92ba43b7, 0x9468d4a5, 0x961184e7, 0x97b5e621, 0x99635fa9, 0x9b0e1bca,
     57             0x9cb1a2bc, 0x9e5e0b6b, 0xa00ac723, 0xa1ad78ec, 0xa358d727, 0xa5078678, 0xa6a96816,
     58             0xa853c21c, 0xaa045951, 0xaba56fa6, 0xad4ecb8f, 0xaf013f39, 0xb0a18f08, 0xb249f2ca,
     59             0xb3fc6f7c, 0xb59dc5ae, 0xb7453719, 0xb8f684df, 0xba9a130c, 0xbc4097ce, 0xbdf0bdc2,
     60             0xbf967699, 0xc13c1440, 0xc2eb1950, 0xc492efd2, 0xc637abc6, 0xc7e596b8, 0xc98f7e33,
     61             0xcb335dc0, 0xcce0352f, 0xce8c213e, 0xd02f298d, 0xd1daf3f0, 0xd388d876, 0xd52b0e94,
     62             0xd6d5d239, 0xd885a363, 0xda270c3c, 0xdbd0cf4b, 0xdd82818f, 0xdf2321f3, 0xe0cbea70,
     63             0xe27ee50b, 0xe41f4f27, 0xe5c722f1, 0xe778ebad, 0xe91b934c, 0xeac2781f, 0xec731627,
     64             0xee17edd8, 0xefbde94f, 0xf16d63a2, 0xf3145e45, 0xf4b975d7, 0xf667d34c, 0xf810e410,
     65             0xf9b51d14, 0xfb626459, 0xfd0d7eb7, 0xfeb0de65 };
     66 
     67     private static final String expectedStringFor1_17eN38To38[] = { "-1.17549435E-38",
     68             "-1.1754944E-37", "-1.17549435E-36", "-1.17549435E-35", "-1.1754944E-34",
     69             "-1.17549435E-33", "-1.17549435E-32", "-1.1754944E-31", "-1.17549435E-30",
     70             "-1.17549435E-29", "-1.1754944E-28", "-1.1754943E-27", "-1.17549435E-26",
     71             "-1.1754943E-25", "-1.1754944E-24", "-1.1754943E-23", "-1.1754944E-22",
     72             "-1.1754943E-21", "-1.1754943E-20", "-1.1754943E-19", "-1.1754944E-18",
     73             "-1.1754944E-17", "-1.1754943E-16", "-1.1754943E-15", "-1.1754944E-14",
     74             "-1.1754943E-13", "-1.1754944E-12", "-1.1754943E-11", "-1.1754943E-10",
     75             "-1.1754944E-9", "-1.1754944E-8", "-1.1754943E-7", "-1.1754944E-6",
     76             "-1.1754943E-5", "-1.1754943E-4", "-0.0011754944", "-0.011754943", "-0.117549434",
     77             "-1.1754943", "-11.754944", "-117.54944", "-1175.4944", "-11754.943", "-117549.44",
     78             "-1175494.4", "-1.1754944E7", "-1.17549432E8", "-1.1754944E9", "-1.17549435E10",
     79             "-1.17549433E11", "-1.17549433E12", "-1.17549438E13", "-1.17549438E14",
     80             "-1.1754943E15", "-1.17549432E16", "-1.17549432E17", "-1.17549434E18",
     81             "-1.1754944E19", "-1.1754944E20", "-1.1754943E21", "-1.1754943E22",
     82             "-1.1754944E23", "-1.17549434E24", "-1.1754943E25", "-1.1754943E26",
     83             "-1.17549434E27", "-1.1754943E28", "-1.1754944E29", "-1.1754943E30",
     84             "-1.1754943E31", "-1.1754944E32", "-1.1754943E33", "-1.1754944E34",
     85             "-1.1754944E35", "-1.1754944E36", "-1.1754943E37", "-1.1754943E38" };
     86 
     87     private void doTestCompareRawBits(String originalFloatString, int expectedRawBits,
     88             String expectedString) {
     89         int rawBits;
     90         float result = Float.parseFloat(originalFloatString);
     91         rawBits = Float.floatToIntBits(result);
     92         assertEquals("Original float(" + originalFloatString + ") Converted float(" + result
     93                 + ") Expecting:" + Integer.toHexString(expectedRawBits) + " Got: "
     94                 + Integer.toHexString(rawBits), expectedRawBits, rawBits);
     95     }
     96 
     97     /**
     98      * @tests java.lang.Float#Float(float)
     99      */
    100     public void test_ConstructorF() {
    101         // Test for method java.lang.Float(float)
    102 
    103         Float f = new Float(900.89f);
    104         assertTrue("Created incorrect float", f.floatValue() == 900.89f);
    105     }
    106 
    107     /**
    108      * @tests java.lang.Float#Float(java.lang.String)
    109      */
    110     public void test_ConstructorLjava_lang_String() {
    111         // Test for method java.lang.Float(java.lang.String)
    112 
    113         Float f = new Float("900.89");
    114         assertTrue("Created incorrect Float", f.floatValue() == 900.89f);
    115     }
    116 
    117     /**
    118      * @tests java.lang.Float#byteValue()
    119      */
    120     public void test_byteValue() {
    121         // Test for method byte java.lang.Float.byteValue()
    122         Float f = new Float(0.46874f);
    123         Float f2 = new Float(90.8f);
    124         assertTrue("Returned incorrect byte value", f.byteValue() == 0 && f2.byteValue() == 90);
    125     }
    126 
    127     /**
    128      * @tests java.lang.Float#compareTo(java.lang.Float)
    129      * @tests java.lang.Float#compare(float, float)
    130      */
    131     public void test_compare() {
    132         float[] values = new float[] { Float.NEGATIVE_INFINITY, -Float.MAX_VALUE, -2f,
    133                 -Float.MIN_VALUE, -0f, 0f, Float.MIN_VALUE, 2f, Float.MAX_VALUE,
    134                 Float.POSITIVE_INFINITY, Float.NaN };
    135         for (int i = 0; i < values.length; i++) {
    136             float f1 = values[i];
    137             assertTrue("compare() should be equal: " + f1, Float.compare(f1, f1) == 0);
    138             Float F1 = new Float(f1);
    139             assertTrue("compareTo() should be equal: " + f1, F1.compareTo(F1) == 0);
    140             for (int j = i + 1; j < values.length; j++) {
    141                 float f2 = values[j];
    142                 assertTrue("compare() " + f1 + " should be less " + f2,
    143                         Float.compare(f1, f2) == -1);
    144                 assertTrue("compare() " + f2 + " should be greater " + f1, Float
    145                         .compare(f2, f1) == 1);
    146                 Float F2 = new Float(f2);
    147                 assertTrue("compareTo() " + f1 + " should be less " + f2,
    148                         F1.compareTo(F2) == -1);
    149                 assertTrue("compareTo() " + f2 + " should be greater " + f1,
    150                         F2.compareTo(F1) == 1);
    151             }
    152         }
    153 
    154         try {
    155             new Float(0.0F).compareTo(null);
    156             fail("No NPE");
    157         } catch (NullPointerException e) {
    158         }
    159     }
    160 
    161     /**
    162      * @tests java.lang.Float#doubleValue()
    163      */
    164     public void test_doubleValue() {
    165         // Test for method double java.lang.Float.doubleValue()
    166         assertTrue("Incorrect double value returned", Math.abs(new Float(999999.999f)
    167                 .doubleValue() - 999999.999d) < 1);
    168     }
    169 
    170     /**
    171      * @tests java.lang.Float#floatToIntBits(float)
    172      */
    173     public void test_floatToIntBitsF() {
    174         float f = 9876.2345f;
    175         int bits = Float.floatToIntBits(f);
    176         float r = Float.intBitsToFloat(bits);
    177         assertTrue("Incorrect intBits returned", f == r);
    178     }
    179 
    180     /**
    181      * @tests java.lang.Float#floatToRawIntBits(float)
    182      */
    183     public void test_floatToRawIntBitsF() {
    184         int i = 0x7fc004d2;
    185         float f = Float.intBitsToFloat(i);
    186         assertTrue("Wrong raw bits", Float.floatToRawIntBits(f) == i);
    187     }
    188 
    189     /**
    190      * @tests java.lang.Float#floatValue()
    191      */
    192     public void test_floatValue() {
    193         // Test for method float java.lang.Float.floatValue()
    194         Float f = new Float(87.657f);
    195         Float f2 = new Float(-0.876f);
    196         assertTrue("Returned incorrect floatValue", f.floatValue() == 87.657f
    197                 && (f2.floatValue() == -0.876f));
    198 
    199     }
    200 
    201     /**
    202      * @tests java.lang.Float#hashCode()
    203      */
    204     public void test_hashCode() {
    205         // Test for method int java.lang.Float.hashCode()
    206         Float f = new Float(1908.8786f);
    207         assertTrue("Returned invalid hash code for 1908.8786f", f.hashCode() == Float
    208                 .floatToIntBits(1908.8786f));
    209 
    210         f = new Float(-1.112f);
    211         assertTrue("Returned invalid hash code for -1.112", f.hashCode() == Float
    212                 .floatToIntBits(-1.112f));
    213 
    214         f = new Float(0f);
    215         assertTrue("Returned invalid hash code for 0", f.hashCode() == Float.floatToIntBits(0f));
    216 
    217     }
    218 
    219     /**
    220      * @tests java.lang.Float#intBitsToFloat(int)
    221      */
    222     public void test_intBitsToFloatI() {
    223         float f = 9876.2345f;
    224         int bits = Float.floatToIntBits(f);
    225         float r = Float.intBitsToFloat(bits);
    226         assertEquals("Incorrect intBits returned", f, r, 0F);
    227     }
    228 
    229     /**
    230      * @tests java.lang.Float#intValue()
    231      */
    232     public void test_intValue() {
    233         // Test for method int java.lang.Float.intValue()
    234         Float f = new Float(0.46874f);
    235         Float f2 = new Float(90.8f);
    236         assertTrue("Returned incorrect int value", f.intValue() == 0 && f2.intValue() == 90);
    237     }
    238 
    239     /**
    240      * @tests java.lang.Float#isInfinite()
    241      */
    242     public void test_isInfinite() {
    243         // Test for method boolean java.lang.Float.isInfinite()
    244         assertTrue("Infinity check failed",
    245                 (new Float(Float.POSITIVE_INFINITY).isInfinite() && new Float(
    246                         Float.NEGATIVE_INFINITY).isInfinite())
    247                         && !(new Float(0.13131414f).isInfinite()));
    248     }
    249 
    250     /**
    251      * @tests java.lang.Float#isInfinite(float)
    252      */
    253     public void test_isInfiniteF() {
    254         // Test for method boolean java.lang.Float.isInfinite(float)
    255 
    256         assertTrue("Infinity check failed", Float.isInfinite(Float.POSITIVE_INFINITY)
    257                 && (Float.isInfinite(Float.NEGATIVE_INFINITY)) && !(Float.isInfinite(1.0f)));
    258     }
    259 
    260     /**
    261      * @tests java.lang.Float#isNaN()
    262      */
    263     public void test_isNaN() {
    264         // Test for method boolean java.lang.Float.isNaN()
    265         assertTrue("NAN check failed", new Float(Float.NaN).isNaN()
    266                 && !(new Float(1.0f).isNaN()));
    267     }
    268 
    269     /**
    270      * @tests java.lang.Float#isNaN(float)
    271      */
    272     public void test_isNaNF() {
    273         // Test for method boolean java.lang.Float.isNaN(float)
    274         assertTrue("NaN check failed", Float.isNaN(Float.NaN) && !(Float.isNaN(12.09f)));
    275     }
    276 
    277     /**
    278      * @tests java.lang.Float#longValue()
    279      */
    280     public void test_longValue() {
    281         // Test for method long java.lang.Float.longValue()
    282         Float f = new Float(0.46874f);
    283         Float f2 = new Float(90.8f);
    284         assertTrue("Returned incorrect long value", f.longValue() == 0 && f2.longValue() == 90);
    285     }
    286 
    287     /**
    288      * @tests java.lang.Float#parseFloat(java.lang.String)
    289      */
    290     public void test_parseFloatLjava_lang_String() {
    291         assertEquals("Incorrect float returned, expected zero.", 0.0, Float
    292                 .parseFloat("7.0064923216240853546186479164495e-46"), 0.0);
    293         assertEquals("Incorrect float returned, expected minimum float.", Float.MIN_VALUE,
    294                 Float.parseFloat("7.0064923216240853546186479164496e-46"), 0.0);
    295 
    296         doTestCompareRawBits(
    297                 "0.000000000000000000000000000000000000011754942807573642917278829910357665133228589927589904276829631184250030649651730385585324256680905818939208984375",
    298                 0x800000, "1.17549435E-38");
    299         doTestCompareRawBits(
    300                 "0.00000000000000000000000000000000000001175494280757364291727882991035766513322858992758990427682963118425003064965173038558532425668090581893920898437499999f",
    301                 0x7fffff, "1.1754942E-38");
    302 
    303         /* Test a set of regular floats with exponents from -38 to +38 */
    304         for (int i = 38; i > 3; i--) {
    305             String testString;
    306             testString = "3.4028234663852886e-" + i;
    307             doTestCompareRawBits(testString, rawBitsFor3_4eN38To38[38 - i],
    308                     expectedStringFor3_4eN38To38[38 - i]);
    309         }
    310         doTestCompareRawBits("3.4028234663852886e-3", rawBitsFor3_4eN38To38[38 - 3],
    311                 expectedStringFor3_4eN38To38[38 - 3]);
    312         doTestCompareRawBits("3.4028234663852886e-2", rawBitsFor3_4eN38To38[38 - 2],
    313                 expectedStringFor3_4eN38To38[38 - 2]);
    314         doTestCompareRawBits("3.4028234663852886e-1", rawBitsFor3_4eN38To38[38 - 1],
    315                 expectedStringFor3_4eN38To38[38 - 1]);
    316         doTestCompareRawBits("3.4028234663852886e-0", rawBitsFor3_4eN38To38[38 - 0],
    317                 expectedStringFor3_4eN38To38[38 - 0]);
    318         doTestCompareRawBits("3.4028234663852886e+1", rawBitsFor3_4eN38To38[38 + 1],
    319                 expectedStringFor3_4eN38To38[38 + 1]);
    320         doTestCompareRawBits("3.4028234663852886e+2", rawBitsFor3_4eN38To38[38 + 2],
    321                 expectedStringFor3_4eN38To38[38 + 2]);
    322         doTestCompareRawBits("3.4028234663852886e+3", rawBitsFor3_4eN38To38[38 + 3],
    323                 expectedStringFor3_4eN38To38[38 + 3]);
    324         doTestCompareRawBits("3.4028234663852886e+4", rawBitsFor3_4eN38To38[38 + 4],
    325                 expectedStringFor3_4eN38To38[38 + 4]);
    326         doTestCompareRawBits("3.4028234663852886e+5", rawBitsFor3_4eN38To38[38 + 5],
    327                 expectedStringFor3_4eN38To38[38 + 5]);
    328         doTestCompareRawBits("3.4028234663852886e+6", rawBitsFor3_4eN38To38[38 + 6],
    329                 expectedStringFor3_4eN38To38[38 + 6]);
    330 
    331         for (int i = 7; i < 39; i++) {
    332             String testString;
    333             testString = "3.4028234663852886e+" + i;
    334             doTestCompareRawBits(testString, rawBitsFor3_4eN38To38[38 + i],
    335                     expectedStringFor3_4eN38To38[38 + i]);
    336         }
    337 
    338         /* Test another set of regular floats with exponents from -38 to +38 */
    339         for (int i = 38; i > 3; i--) {
    340             String testString;
    341             testString = "-1.1754943508222875e-" + i;
    342             doTestCompareRawBits(testString, rawBitsFor1_17eN38To38[38 - i],
    343                     expectedStringFor1_17eN38To38[38 - i]);
    344         }
    345         doTestCompareRawBits("-1.1754943508222875e-3", rawBitsFor1_17eN38To38[38 - 3],
    346                 expectedStringFor1_17eN38To38[38 - 3]);
    347         doTestCompareRawBits("-1.1754943508222875e-2", rawBitsFor1_17eN38To38[38 - 2],
    348                 expectedStringFor1_17eN38To38[38 - 2]);
    349         doTestCompareRawBits("-1.1754943508222875e-1", rawBitsFor1_17eN38To38[38 - 1],
    350                 expectedStringFor1_17eN38To38[38 - 1]);
    351         doTestCompareRawBits("-1.1754943508222875e-0", rawBitsFor1_17eN38To38[38 - 0],
    352                 expectedStringFor1_17eN38To38[38 - 0]);
    353         doTestCompareRawBits("-1.1754943508222875e+1", rawBitsFor1_17eN38To38[38 + 1],
    354                 expectedStringFor1_17eN38To38[38 + 1]);
    355         doTestCompareRawBits("-1.1754943508222875e+2", rawBitsFor1_17eN38To38[38 + 2],
    356                 expectedStringFor1_17eN38To38[38 + 2]);
    357         doTestCompareRawBits("-1.1754943508222875e+3", rawBitsFor1_17eN38To38[38 + 3],
    358                 expectedStringFor1_17eN38To38[38 + 3]);
    359         doTestCompareRawBits("-1.1754943508222875e+4", rawBitsFor1_17eN38To38[38 + 4],
    360                 expectedStringFor1_17eN38To38[38 + 4]);
    361         doTestCompareRawBits("-1.1754943508222875e+5", rawBitsFor1_17eN38To38[38 + 5],
    362                 expectedStringFor1_17eN38To38[38 + 5]);
    363         doTestCompareRawBits("-1.1754943508222875e+6", rawBitsFor1_17eN38To38[38 + 6],
    364                 expectedStringFor1_17eN38To38[38 + 6]);
    365 
    366         for (int i = 7; i < 39; i++) {
    367             String testString;
    368             testString = "-1.1754943508222875e+" + i;
    369             doTestCompareRawBits(testString, rawBitsFor1_17eN38To38[38 + i],
    370                     expectedStringFor1_17eN38To38[38 + i]);
    371         }
    372 
    373         /* Test denormalized floats (floats with exponents <= -38 */
    374         doTestCompareRawBits("1.1012984643248170E-45", 1, "1.4E-45");
    375         doTestCompareRawBits("-1.1012984643248170E-45", 0x80000001, "-1.4E-45");
    376         doTestCompareRawBits("1.0E-45", 1, "1.4E-45");
    377         doTestCompareRawBits("-1.0E-45", 0x80000001, "-1.4E-45");
    378         doTestCompareRawBits("0.9E-45", 1, "1.4E-45");
    379         doTestCompareRawBits("-0.9E-45", 0x80000001, "-1.4E-45");
    380         doTestCompareRawBits("4.203895392974451e-45", 3, "4.2E-45");
    381         doTestCompareRawBits("-4.203895392974451e-45", 0x80000003, "-4.2E-45");
    382         doTestCompareRawBits("0.004E-45", 0, "0.0");
    383         doTestCompareRawBits("-0.004E-45", 0x80000000, "-0.0");
    384 
    385         /*
    386          * Test for large floats close to and greater than 3.4028235E38 and
    387          * -3.4028235E38
    388          */
    389         doTestCompareRawBits("1.2E+38", 0x7eb48e52, "1.2E38");
    390         doTestCompareRawBits("-1.2E+38", 0xfeb48e52, "-1.2E38");
    391         doTestCompareRawBits("3.2E+38", 0x7f70bdc2, "3.2E38");
    392         doTestCompareRawBits("-3.2E+38", 0xff70bdc2, "-3.2E38");
    393         doTestCompareRawBits("3.4E+38", 0x7f7fc99e, "3.4E38");
    394         doTestCompareRawBits("-3.4E+38", 0xff7fc99e, "-3.4E38");
    395         doTestCompareRawBits("3.4028234663852886E+38", 0x7f7fffff, "3.4028235E38");
    396         doTestCompareRawBits("-3.4028234663852886E+38", 0xff7fffff, "-3.4028235E38");
    397         doTestCompareRawBits("3.405E+38", 0x7f800000, "Infinity");
    398         doTestCompareRawBits("-3.405E+38", 0xff800000, "-Infinity");
    399         doTestCompareRawBits("3.41E+38", 0x7f800000, "Infinity");
    400         doTestCompareRawBits("-3.41E+38", 0xff800000, "-Infinity");
    401         doTestCompareRawBits("3.42E+38", 0x7f800000, "Infinity");
    402         doTestCompareRawBits("-3.42E+38", 0xff800000, "-Infinity");
    403         doTestCompareRawBits("1.0E+39", 0x7f800000, "Infinity");
    404         doTestCompareRawBits("-1.0E+39", 0xff800000, "-Infinity");
    405     }
    406 
    407     /**
    408      * @tests java.lang.Float#parseFloat(java.lang.String)
    409      */
    410     public void test_parseFloat_LString_Unusual() {
    411         float actual;
    412 
    413         actual = Float.parseFloat("0x00000000000000000000000000000000000000000.0000000000000000000000000000000000000p0000000000000000000000000000000000");
    414         assertEquals("Returned incorrect value", 0.0f, actual, 0.0F);
    415 
    416         actual = Float.parseFloat("+0Xfffff.fffffffffffffffffffffffffffffffp+99F");
    417         assertEquals("Returned incorrect value", 6.64614E35f, actual, 0.0F);
    418 
    419         actual = Float.parseFloat("-0X.123456789abcdefp+99f");
    420         assertEquals("Returned incorrect value", -4.5072022E28f, actual, 0.0F);
    421 
    422         actual = Float.parseFloat("-0X123456789abcdef.p+1f");
    423         assertEquals("Returned incorrect value", -1.63971062E17f, actual, 0.0F);
    424 
    425         actual = Float.parseFloat("-0X000000000000000000000000000001abcdef.0000000000000000000000000001abefp00000000000000000000000000000000000000000004f");
    426         assertEquals("Returned incorrect value", -4.48585472E8f, actual, 0.0F);
    427 
    428         actual = Float.parseFloat("0X0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001234p600f");
    429         assertEquals("Returned incorrect value", 5.907252E33f, actual, 0.0F);
    430 
    431         actual = Float.parseFloat("0x1.p9223372036854775807");
    432         assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, actual, 0.0F);
    433 
    434         actual = Float.parseFloat("0x1.p9223372036854775808");
    435         assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, actual, 0.0F);
    436 
    437         actual = Float.parseFloat("0x10.p9223372036854775808");
    438         assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, actual, 0.0F);
    439 
    440         actual = Float.parseFloat("0xabcd.ffffffffp+2000");
    441         assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, actual, 0.0F);
    442 
    443         actual = Float.parseFloat("0x1.p-9223372036854775808");
    444         assertEquals("Returned incorrect value", 0.0f, actual, 0.0F);
    445 
    446         actual = Float.parseFloat("0x1.p-9223372036854775809");
    447         assertEquals("Returned incorrect value", 0.0f, actual, 0.0F);
    448 
    449         actual = Float.parseFloat("0x.1p-9223372036854775809");
    450         assertEquals("Returned incorrect value", 0.0f, actual, 0.0F);
    451     }
    452 
    453     /**
    454      * @tests java.lang.Float#parseFloat(java.lang.String)
    455      */
    456     public void test_parseFloat_LString_NormalPositiveExponent() {
    457         int[] expecteds = {
    458                 0x3991a2b4,                0x43cc0247,                0x47909009,
    459                 0x4ac0c009,                0x4e109005,                0x5140c005,
    460                 0x5458d805,                0x57848402,                0x5a909002,
    461                 0x5da8a802,                0x60c0c002,                0x63cccc02,
    462                 0x66e4e402,                0x69f0f002,                0x6d048401,
    463                 0x70109001,                0x73169601,                0x76810810,
    464                 0x79840840,                0x7c8a08a0,                0x7f800000,
    465                 0x7f800000,                0x7f800000,                0x7f800000,
    466                 0x7f800000,
    467         };
    468 
    469         for (int i = 0; i < expecteds.length; i++) {
    470             int part = i * 6;
    471             String inputString = "0x" + part + "." + part + "0123456789abcdefp" + part;
    472 
    473             float actual = Float.parseFloat(inputString);
    474             float expected = Float.intBitsToFloat(expecteds[i]);
    475 
    476             String expectedString = Integer.toHexString(Float.floatToIntBits(expected));
    477             String actualString = Integer.toHexString(Float.floatToIntBits(actual));
    478             String errorMsg = i + "th input string is:<" + inputString
    479             + ">.The expected result should be:<" + expectedString
    480             + ">, but was: <" + actualString + ">. ";
    481 
    482             assertEquals(errorMsg, expected, actual, 0.0F);
    483         }
    484     }
    485 
    486     /**
    487      * @tests java.lang.Float#parseFloat(java.lang.String)
    488      */
    489     public void test_parseFloat_LString_NormalNegativeExponent() {
    490         int[] expecteds = {
    491                 0x3991a2b4,
    492                 0x3d6e0247,
    493                 0x3aa0a009,
    494                 0x37848405,
    495                 0x3420a005,
    496                 0x30d4d405,
    497                 0x2d848402,
    498                 0x2a129202,
    499                 0x26acac02,
    500                 0x2346c602,
    501                 0x1fe0e002,
    502                 0x1c6eee02,
    503                 0x19048401,
    504                 0x15919101,
    505                 0x12189801,
    506                 0xf028828,
    507                 0xb890890,
    508                 0x80c88c8,
    509                 0x4930930,
    510                 0x1198998,
    511                 0x28028,
    512                 0x51c,
    513                 0xb,
    514                 0x0,
    515                 0x0,
    516         };
    517 
    518         for (int i = 0; i < expecteds.length; i++) {
    519             int part = i * 7;
    520             String inputString = "0x" + part + "." + part + "0123456789abcdefp-"  + part;
    521 
    522             float actual = Float.parseFloat(inputString);
    523             float expected = Float.intBitsToFloat(expecteds[i]);
    524 
    525             String expectedString = Integer.toHexString(Float.floatToIntBits(expected));
    526             String actualString = Integer.toHexString(Float.floatToIntBits(actual));
    527             String errorMsg = i + "th input string is:<" + inputString
    528             + ">.The expected result should be:<" + expectedString
    529             + ">, but was: <" + actualString + ">. ";
    530 
    531             assertEquals(errorMsg, expected, actual, 0.0F);
    532         }
    533     }
    534 
    535     /**
    536      * @tests java.lang.Float#parseFloat(java.lang.String)
    537      */
    538     public void test_parseFloat_LString_MaxNormalBoundary() {
    539         int[] expecteds ={
    540                 0x7f7fffff,
    541                 0x7f7fffff,
    542                 0x7f7fffff,
    543                 0x7f800000,
    544                 0x7f800000,
    545                 0x7f800000,
    546 
    547                 0xff7fffff,
    548                 0xff7fffff,
    549                 0xff7fffff,
    550                 0xff800000,
    551                 0xff800000,
    552                 0xff800000,
    553         };
    554 
    555         String[] inputs = {
    556                 "0x1.fffffep127",
    557                 "0x1.fffffe000000000000000000000000000000000000000000000001p127",
    558                 "0x1.fffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp127",
    559                 "0x1.ffffffp127",
    560                 "0x1.ffffff000000000000000000000000000000000000000000000001p127",
    561                 "0x1.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp127",
    562 
    563                 "-0x1.fffffep127",
    564                 "-0x1.fffffe000000000000000000000000000000000000000000000001p127",
    565                 "-0x1.fffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp127",
    566                 "-0x1.ffffffp127",
    567                 "-0x1.ffffff000000000000000000000000000000000000000000000001p127",
    568                 "-0x1.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp127",
    569         };
    570 
    571         for (int i = 0; i < inputs.length; i++) {
    572             float actual = Float.parseFloat(inputs[i]);
    573             float expected = Float.intBitsToFloat(expecteds[i]);
    574 
    575             String expectedString = Integer.toHexString(Float.floatToIntBits(expected));
    576             String actualString = Integer.toHexString(Float.floatToIntBits(actual));
    577             String errorMsg = i + "th input string is:<" + inputs[i]
    578             + ">.The expected result should be:<" + expectedString
    579             + ">, but was: <" + actualString + ">. ";
    580 
    581             assertEquals(errorMsg, expected, actual, 0.0F);
    582         }
    583     }
    584 
    585     /**
    586      * @tests java.lang.Float#parseFloat(java.lang.String)
    587      */
    588     public void test_parseFloat_LString_MinNormalBoundary() {
    589         int expecteds[] = {
    590                 0x800000,
    591                 0x800000,
    592                 0x800000,
    593                 0x800000,
    594                 0x800001,
    595                 0x800001,
    596 
    597                 0x80800000,
    598                 0x80800000,
    599                 0x80800000,
    600                 0x80800000,
    601                 0x80800001,
    602                 0x80800001,
    603         };
    604 
    605         String inputs[] = {
    606                 "0x1.0p-126",
    607                 "0x1.00000000000000000000000000000000000000000000001p-126",
    608                 "0x1.000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
    609                 "0x1.000001p-126",
    610                 "0x1.000001000000000000000000000000000000000000000001p-126",
    611                 "0x1.000001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
    612 
    613                 "-0x1.0p-126",
    614                 "-0x1.00000000000000000000000000000000000000000000001p-126",
    615                 "-0x1.000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
    616                 "-0x1.000001p-126",
    617                 "-0x1.000001000000000000000000000000000000000000000001p-126",
    618                 "-0x1.000001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
    619         };
    620 
    621         for (int i = 0; i < inputs.length; i++) {
    622             float actual = Float.parseFloat(inputs[i]);
    623             float expected = Float.intBitsToFloat(expecteds[i]);
    624 
    625             String expectedString = Integer.toHexString(Float.floatToIntBits(expected));
    626             String actualString = Integer.toHexString(Float.floatToIntBits(actual));
    627             String errorMsg = i + "th input string is:<" + inputs[i]
    628             + ">.The expected result should be:<" + expectedString
    629             + ">, but was: <" + actualString + ">. ";
    630 
    631             assertEquals(errorMsg, expected, actual, 0.0F);
    632         }
    633     }
    634 
    635     /**
    636      * @tests java.lang.Float#parseFloat(java.lang.String)
    637      */
    638     public void test_parseFloat_LString_MaxSubNormalBoundary() {
    639         int expecteds[] = {
    640                 0x7fffff,
    641                 0x7fffff,
    642                 0x7fffff,
    643                 0x800000,
    644                 0x800000,
    645                 0x800000,
    646 
    647                 0x807fffff,
    648                 0x807fffff,
    649                 0x807fffff,
    650                 0x80800000,
    651                 0x80800000,
    652                 0x80800000,
    653         };
    654 
    655         String inputs[] = {
    656                 "0x0.fffffep-126",
    657                 "0x0.fffffe000000000000000000000000000000000000000000000000000001p-126",
    658                 "0x0.fffffefffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
    659                 "0x0.ffffffp-126",
    660                 "0x0.ffffff0000000000000000000000000000000000000000000000000000001p-126",
    661                 "0x0.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
    662 
    663                 "-0x0.fffffep-126",
    664                 "-0x0.fffffe000000000000000000000000000000000000000000000000000001p-126",
    665                 "-0x0.fffffefffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
    666                 "-0x0.ffffffp-126",
    667                 "-0x0.ffffff0000000000000000000000000000000000000000000000000000001p-126",
    668                 "-0x0.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
    669         };
    670 
    671         for (int i = 0; i < inputs.length; i++) {
    672             float actual = Float.parseFloat(inputs[i]);
    673             float expected = Float.intBitsToFloat(expecteds[i]);
    674 
    675             String expectedString = Integer.toHexString(Float.floatToIntBits(expected));
    676             String actualString = Integer.toHexString(Float.floatToIntBits(actual));
    677             String errorMsg = i + "th input string is:<" + inputs[i]
    678             + ">.The expected result should be:<" + expectedString
    679             + ">, but was: <" + actualString + ">. ";
    680 
    681             assertEquals(errorMsg, expected, actual, 0.0F);
    682         }
    683     }
    684 
    685     /**
    686      * @tests java.lang.Float#parseFloat(java.lang.String)
    687      */
    688     public void test_parseFloat_LString_MinSubNormalBoundary() {
    689         int expecteds[] = {
    690                 0x1,
    691                 0x1,
    692                 0x1,
    693                 0x2,
    694                 0x2,
    695                 0x2,
    696 
    697                 0x80000001,
    698                 0x80000001,
    699                 0x80000001,
    700                 0x80000002,
    701                 0x80000002,
    702                 0x80000002,
    703         };
    704 
    705         String inputs[] = {
    706                 "0x0.000002p-126",
    707                 "0x0.00000200000000000000000000000000000000000001p-126",
    708                 "0x0.000002ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
    709                 "0x0.000003p-126",
    710                 "0x0.000003000000000000000000000000000000000000001p-126",
    711                 "0x0.000003ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
    712 
    713                 "-0x0.000002p-126",
    714                 "-0x0.00000200000000000000000000000000000000000001p-126",
    715                 "-0x0.000002ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
    716                 "-0x0.000003p-126",
    717                 "-0x0.000003000000000000000000000000000000000000001p-126",
    718                 "-0x0.000003ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
    719         };
    720 
    721         for (int i = 0; i < inputs.length; i++) {
    722             float actual = Float.parseFloat(inputs[i]);
    723             float expected = Float.intBitsToFloat(expecteds[i]);
    724 
    725             String expectedString = Integer.toHexString(Float.floatToIntBits(expected));
    726             String actualString = Integer.toHexString(Float.floatToIntBits(actual));
    727             String errorMsg = i + "th input string is:<" + inputs[i]
    728             + ">.The expected result should be:<" + expectedString
    729             + ">, but was: <" + actualString + ">. ";
    730 
    731             assertEquals(errorMsg, expected, actual, 0.0F);
    732         }
    733     }
    734 
    735     /**
    736      * @tests java.lang.Float#parseFloat(java.lang.String)
    737      */
    738     public void test_parseFloat_LString_ZeroBoundary() {
    739         int expecteds[] = {
    740                 0x0,
    741                 0x0,
    742                 0x0,
    743                 0x0,
    744                 0x1,
    745                 0x1,
    746 
    747                 0x80000000,
    748                 0x80000000,
    749                 0x80000000,
    750                 0x80000000,
    751                 0x80000001,
    752                 0x80000001,
    753         };
    754 
    755         String inputs[] = {
    756                 "0x0.000000000000000p-126",
    757                 "0x0.000000000000000000000000000000000000000000000001p-126",
    758                 "0x0.000000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
    759                 "0x0.000001p-126",
    760                 "0x0.000001000000000000000000000000000000000000000001p-126",
    761                 "0x0.000001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
    762 
    763                 "-0x0.000000000000000p-126",
    764                 "-0x0.000000000000000000000000000000000000000000000001p-126",
    765                 "-0x0.000000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
    766                 "-0x0.000001p-126",
    767                 "-0x0.000001000000000000000000000000000000000000000001p-126",
    768                 "-0x0.000001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
    769         };
    770 
    771         for (int i = 0; i < inputs.length; i++) {
    772             float actual = Float.parseFloat(inputs[i]);
    773             float expected = Float.intBitsToFloat(expecteds[i]);
    774 
    775             String expectedString = Integer.toHexString(Float.floatToIntBits(expected));
    776             String actualString = Integer.toHexString(Float.floatToIntBits(actual));
    777             String errorMsg = i + "th input string is:<" + inputs[i]
    778             + ">.The expected result should be:<" + expectedString
    779             + ">, but was: <" + actualString + ">. ";
    780 
    781             assertEquals(errorMsg, expected, actual, 0.0F);
    782         }
    783     }
    784 
    785     /**
    786      * @tests java.lang.Float#parseFloat(java.lang.String)
    787      */
    788     public void test_parseFloat_LString_Harmony6261() {
    789         // Regression test for HARMONY-6261
    790         float f = new Float("2147483648");
    791         assertEquals("2.1474836E9", Float.toString(f));
    792 
    793         doTestCompareRawBits("123456790528.000000000000000f", 0x51e5f4c9, "1.2345679E11");
    794         doTestCompareRawBits("8589934592", 0x50000000, "8.5899346E9");
    795         doTestCompareRawBits("8606711808", 0x50004000, "8.606712E9");
    796     }
    797 
    798     /**
    799      * @tests java.lang.Float#shortValue()
    800      */
    801     public void test_shortValue() {
    802         // Test for method short java.lang.Float.shortValue()
    803         Float f = new Float(0.46874f);
    804         Float f2 = new Float(90.8f);
    805         assertTrue("Returned incorrect short value", f.shortValue() == 0
    806                 && f2.shortValue() == 90);
    807     }
    808 
    809     /**
    810      * @tests java.lang.Float#toString()
    811      */
    812     public void test_toString() {
    813         // Test for method java.lang.String java.lang.Float.toString()
    814 
    815         test_toString(12.90898f, "12.90898");
    816 
    817         test_toString(1.7014118346046924e+38F, "1.7014118E38");
    818 
    819         test_toString(1E19F, "1.0E19");
    820 
    821         test_toString(1E-36F, "1.0E-36");
    822 
    823         test_toString(1.0E-38F, "1.0E-38");
    824     }
    825 
    826     /**
    827      * @tests java.lang.Float#toString(float)
    828      */
    829     public void test_toStringF() {
    830         // Test for method java.lang.String java.lang.Float.toString(float)
    831 
    832         float ff;
    833         String answer;
    834 
    835         ff = 12.90898f;
    836         answer = "12.90898";
    837         assertTrue("Incorrect String representation want " + answer + ", got "
    838                 + Float.toString(ff), Float.toString(ff).equals(answer));
    839 
    840         ff = Float.MAX_VALUE;
    841         answer = "3.4028235E38";
    842         assertTrue("Incorrect String representation want " + answer + ", got "
    843                 + Float.toString(ff), Float.toString(ff).equals(answer));
    844     }
    845 
    846     /**
    847      * @tests java.lang.Float#valueOf(java.lang.String)
    848      */
    849     public void test_valueOfLjava_lang_String() {
    850         // Test for method java.lang.Float
    851         // java.lang.Float.valueOf(java.lang.String)
    852 
    853         Float wanted = new Float(432.1235f);
    854         Float got = Float.valueOf("432.1235");
    855         assertTrue("Incorrect float returned--wanted: " + wanted + " but got: " + got, got
    856                 .equals(wanted));
    857 
    858         wanted = new Float(0f);
    859         got = Float.valueOf("0");
    860         assertTrue("Incorrect float returned--wanted: " + wanted + " but got: " + got, got
    861                 .equals(wanted));
    862 
    863         wanted = new Float(-1212.3232f);
    864         got = Float.valueOf("-1212.3232");
    865         assertTrue("Incorrect float returned--wanted: " + wanted + " but got: " + got, got
    866                 .equals(wanted));
    867 
    868         try {
    869             Float.valueOf(null);
    870             fail("Expected Float.valueOf(null) to throw NPE.");
    871         } catch (NullPointerException ex) {
    872             // expected
    873         }
    874 
    875         try {
    876             Float.valueOf("");
    877             fail("Expected Float.valueOf(\"\") to throw NFE");
    878         } catch (NumberFormatException e) {
    879             // expected
    880         }
    881 
    882         Float posZero = Float.valueOf("+0.0");
    883         Float negZero = Float.valueOf("-0.0");
    884         assertFalse("Floattest0", posZero.equals(negZero));
    885         assertTrue("Floattest1", 0.0f == -0.0f);
    886 
    887         // Tests for float values by name.
    888         Float expectedNaN = new Float(Float.NaN);
    889 
    890         Float posNaN = Float.valueOf("NaN");
    891         assertTrue("Floattest2", posNaN.equals(expectedNaN));
    892 
    893         Float posNaNSigned = Float.valueOf("+NaN");
    894         assertTrue("Floattest3", posNaNSigned.equals(expectedNaN));
    895 
    896         Float negNaNSigned = Float.valueOf("-NaN");
    897         assertTrue("Floattest4", negNaNSigned.equals(expectedNaN));
    898 
    899         Float posInfinite = Float.valueOf("Infinity");
    900         assertTrue("Floattest5", posInfinite.equals(new Float(Float.POSITIVE_INFINITY)));
    901 
    902         Float posInfiniteSigned = Float.valueOf("+Infinity");
    903         assertTrue("Floattest6", posInfiniteSigned.equals(new Float(Float.POSITIVE_INFINITY)));
    904 
    905         Float negInfiniteSigned = Float.valueOf("-Infinity");
    906         assertTrue("Floattest7", negInfiniteSigned.equals(new Float(Float.NEGATIVE_INFINITY)));
    907 
    908         // test HARMONY-6641
    909         posInfinite = Float.valueOf("320.0E+2147483647");
    910         assertEquals("Floattest8", Float.POSITIVE_INFINITY, posInfinite);
    911 
    912         negZero = Float.valueOf("-1.4E-2147483314");
    913         assertEquals("Floattest9", -0.0f, negZero);
    914     }
    915 
    916     private void test_toString(float ff, String answer) {
    917         // Test for method java.lang.String java.lang.Double.toString(double)
    918         assertTrue("Incorrect String representation want " + answer + ", got ("
    919                 + Float.toString(ff) + ")", Float.toString(ff).equals(answer));
    920         Float f = new Float(ff);
    921         assertTrue("Incorrect String representation want " + answer + ", got ("
    922                 + Float.toString(f.floatValue()) + ")", Float.toString(f.floatValue()).equals(
    923                 answer));
    924         assertTrue("Incorrect String representation want " + answer + ", got (" + f.toString()
    925                 + ")", f.toString().equals(answer));
    926     }
    927 
    928     /**
    929      * @tests java.lang.Float#compareTo(java.lang.Float)
    930      * @tests java.lang.Float#compare(float, float)
    931      */
    932     public void test_compareToLjava_lang_Float() {
    933         // A selection of float values in ascending order.
    934         float[] values = new float[] { Float.NEGATIVE_INFINITY, -Float.MAX_VALUE, -2f,
    935                 -Float.MIN_VALUE, -0f, 0f, Float.MIN_VALUE, 2f, Float.MAX_VALUE,
    936                 Float.POSITIVE_INFINITY, Float.NaN };
    937 
    938         for (int i = 0; i < values.length; i++) {
    939             float f1 = values[i];
    940 
    941             // Test that each value compares equal to itself; and each object is
    942             // equal to another object
    943             // like itself
    944             assertTrue("Assert 0: compare() should be equal: " + f1, Float.compare(f1, f1) == 0);
    945             Float objFloat = new Float(f1);
    946             assertTrue("Assert 1: compareTo() should be equal: " + objFloat, objFloat
    947                     .compareTo(objFloat) == 0);
    948 
    949             // Test that the Float-defined order is respected
    950             for (int j = i + 1; j < values.length; j++) {
    951                 float f2 = values[j];
    952                 assertTrue("Assert 2: compare() " + f1 + " should be less " + f2, Float
    953                         .compare(f1, f2) == -1);
    954                 assertTrue("Assert 3: compare() " + f2 + " should be greater " + f1, Float
    955                         .compare(f2, f1) == 1);
    956 
    957                 Float F2 = new Float(f2);
    958                 assertTrue("Assert 4: compareTo() " + f1 + " should be less " + f2, objFloat
    959                         .compareTo(F2) == -1);
    960                 assertTrue("Assert 5: compareTo() " + f2 + " should be greater " + f1, F2
    961                         .compareTo(objFloat) == 1);
    962             }
    963         }
    964     }
    965 
    966     /**
    967      * @tests java.lang.Float#equals(java.lang.Object)
    968      */
    969     public void test_equalsLjava_lang_Object() {
    970         Float f1 = new Float(8765.4321f);
    971         Float f2 = new Float(8765.4321f);
    972         Float f3 = new Float(-1.0f);
    973         assertTrue("Assert 0: Equality test failed", f1.equals(f2) && !(f1.equals(f3)));
    974 
    975         assertTrue("Assert 1: NaN should not be == Nan", Float.NaN != Float.NaN);
    976         assertTrue("Assert 2: NaN should not be == Nan", new Float(Float.NaN).equals(new Float(
    977                 Float.NaN)));
    978         assertTrue("Assert 3: -0f should be == 0f", 0f == -0f);
    979         assertTrue("Assert 4: -0f should not be equals() 0f", !new Float(0f).equals(new Float(
    980                 -0f)));
    981 
    982         f1 = new Float(1098.576f);
    983         f2 = new Float(1098.576f);
    984         f3 = new Float(1.0f);
    985         assertTrue("Equality test failed", f1.equals(f2) && !(f1.equals(f3)));
    986 
    987         assertTrue("NaN should not be == Nan", Float.NaN != Float.NaN);
    988         assertTrue("NaN should not be == Nan", new Float(Float.NaN)
    989                 .equals(new Float(Float.NaN)));
    990         assertTrue("-0f should be == 0f", 0f == -0f);
    991         assertTrue("-0f should not be equals() 0f", !new Float(0f).equals(new Float(-0f)));
    992     }
    993 
    994     /**
    995      * @tests java.lang.Float#toHexString(float)
    996      */
    997     public void test_toHexStringF() {
    998         // the follow values comes from the Float Javadoc/Spec
    999         assertEquals("0x0.0p0", Float.toHexString(0.0F));
   1000         assertEquals("-0x0.0p0", Float.toHexString(-0.0F));
   1001         assertEquals("0x1.0p0", Float.toHexString(1.0F));
   1002         assertEquals("-0x1.0p0", Float.toHexString(-1.0F));
   1003         assertEquals("0x1.0p1", Float.toHexString(2.0F));
   1004         assertEquals("0x1.8p1", Float.toHexString(3.0F));
   1005         assertEquals("0x1.0p-1", Float.toHexString(0.5F));
   1006         assertEquals("0x1.0p-2", Float.toHexString(0.25F));
   1007         assertEquals("0x1.fffffep127", Float.toHexString(Float.MAX_VALUE));
   1008         assertEquals("0x0.000002p-126", Float.toHexString(Float.MIN_VALUE));
   1009 
   1010         // test edge cases
   1011         assertEquals("NaN", Float.toHexString(Float.NaN));
   1012         assertEquals("-Infinity", Float.toHexString(Float.NEGATIVE_INFINITY));
   1013         assertEquals("Infinity", Float.toHexString(Float.POSITIVE_INFINITY));
   1014 
   1015         // test various numbers
   1016         assertEquals("-0x1.da8p6", Float.toHexString(-118.625F));
   1017         assertEquals("0x1.295788p23", Float.toHexString(9743299.65F));
   1018         assertEquals("0x1.295788p23", Float.toHexString(9743299.65000F));
   1019         assertEquals("0x1.295788p23", Float.toHexString(9743299.650001234F));
   1020         assertEquals("0x1.700d1p33", Float.toHexString(12349743299.65000F));
   1021 
   1022         // test HARMONY-2132
   1023         assertEquals("0x1.01p10", Float.toHexString(0x1.01p10f));
   1024     }
   1025 
   1026     /**
   1027      * @tests java.lang.Float#valueOf(float)
   1028      */
   1029     public void test_valueOfF() {
   1030         assertEquals(new Float(Float.MIN_VALUE), Float.valueOf(Float.MIN_VALUE));
   1031         assertEquals(new Float(Float.MAX_VALUE), Float.valueOf(Float.MAX_VALUE));
   1032         assertEquals(new Float(0), Float.valueOf(0));
   1033 
   1034         int s = -128;
   1035         while (s < 128) {
   1036             assertEquals(new Float(s), Float.valueOf(s));
   1037             assertEquals(new Float(s + 0.1F), Float.valueOf(s + 0.1F));
   1038             assertEquals(Float.valueOf(s + 0.1F), Float.valueOf(s + 0.1F));
   1039             s++;
   1040         }
   1041     }
   1042 
   1043     /**
   1044 	 * @tests {@link java.lang.Float#MAX_EXPONENT}
   1045 	 * @since 1.6
   1046 	 */
   1047 	public void test_MAX_EXPONENT() {
   1048 		assertTrue("Wrong value of java.lang.Float.MAX_EXPONENT",
   1049 				Float.MAX_EXPONENT == 127);
   1050 		assertTrue("Wrong value of java.lang.Float.MAX_EXPONENT",
   1051 				Float.MAX_EXPONENT == Math.getExponent(Float.MAX_VALUE));
   1052 	}
   1053 
   1054 	/**
   1055 	 * @tests {@link java.lang.Float#MIN_EXPONENT}
   1056 	 * @since 1.6
   1057 	 */
   1058 	public void test_MIN_EXPONENT() {
   1059 		assertTrue("Wrong value of java.lang.Float.MIN_EXPONENT",
   1060 				Float.MIN_EXPONENT == -126);
   1061 		assertTrue("Wrong value of java.lang.Float.MIN_EXPONENT",
   1062 				Float.MIN_EXPONENT == Math.getExponent(Float.MIN_NORMAL));
   1063 	}
   1064 
   1065 	/**
   1066 	 * @tests {@link java.lang.Float#MIN_NORMAL}
   1067 	 * @since 1.6
   1068 	 */
   1069 	public void test_MIN_NORMAL() {
   1070 		assertTrue("Wrong value of java.lang.Float.MIN_NORMAL",
   1071 				Float.MIN_NORMAL == 0x1.0p-126f);
   1072 		assertTrue("Wrong value of java.lang.Float.MIN_NORMAL",
   1073 				Float.MIN_NORMAL == Float.intBitsToFloat(0x00800000));
   1074 		assertTrue("Wrong value of java.lang.Float.MIN_NORMAL",
   1075 				Float.MIN_NORMAL == 1.1754943508222875E-38f);
   1076 	}
   1077 }
   1078