emul/src/main/java/java/lang/Float.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sun, 18 Nov 2012 10:00:23 +0100
branchjavap
changeset 181 f426de5dc7f6
parent 116 033d51e026b0
child 187 391a5d25c0e1
permissions -rw-r--r--
Can deserialize float
jaroslav@67
     1
/*
jaroslav@67
     2
 * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
jaroslav@67
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jaroslav@67
     4
 *
jaroslav@67
     5
 * This code is free software; you can redistribute it and/or modify it
jaroslav@67
     6
 * under the terms of the GNU General Public License version 2 only, as
jaroslav@67
     7
 * published by the Free Software Foundation.  Oracle designates this
jaroslav@67
     8
 * particular file as subject to the "Classpath" exception as provided
jaroslav@67
     9
 * by Oracle in the LICENSE file that accompanied this code.
jaroslav@67
    10
 *
jaroslav@67
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
jaroslav@67
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jaroslav@67
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
jaroslav@67
    14
 * version 2 for more details (a copy is included in the LICENSE file that
jaroslav@67
    15
 * accompanied this code).
jaroslav@67
    16
 *
jaroslav@67
    17
 * You should have received a copy of the GNU General Public License version
jaroslav@67
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
jaroslav@67
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jaroslav@67
    20
 *
jaroslav@67
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jaroslav@67
    22
 * or visit www.oracle.com if you need additional information or have any
jaroslav@67
    23
 * questions.
jaroslav@67
    24
 */
jaroslav@67
    25
jaroslav@67
    26
package java.lang;
jaroslav@67
    27
jaroslav@116
    28
import org.apidesign.bck2brwsr.core.JavaScriptBody;
jaroslav@116
    29
jaroslav@67
    30
/**
jaroslav@67
    31
 * The {@code Float} class wraps a value of primitive type
jaroslav@67
    32
 * {@code float} in an object. An object of type
jaroslav@67
    33
 * {@code Float} contains a single field whose type is
jaroslav@67
    34
 * {@code float}.
jaroslav@67
    35
 *
jaroslav@67
    36
 * <p>In addition, this class provides several methods for converting a
jaroslav@67
    37
 * {@code float} to a {@code String} and a
jaroslav@67
    38
 * {@code String} to a {@code float}, as well as other
jaroslav@67
    39
 * constants and methods useful when dealing with a
jaroslav@67
    40
 * {@code float}.
jaroslav@67
    41
 *
jaroslav@67
    42
 * @author  Lee Boynton
jaroslav@67
    43
 * @author  Arthur van Hoff
jaroslav@67
    44
 * @author  Joseph D. Darcy
jaroslav@67
    45
 * @since JDK1.0
jaroslav@67
    46
 */
jaroslav@67
    47
public final class Float extends Number implements Comparable<Float> {
jaroslav@67
    48
    /**
jaroslav@67
    49
     * A constant holding the positive infinity of type
jaroslav@67
    50
     * {@code float}. It is equal to the value returned by
jaroslav@67
    51
     * {@code Float.intBitsToFloat(0x7f800000)}.
jaroslav@67
    52
     */
jaroslav@67
    53
    public static final float POSITIVE_INFINITY = 1.0f / 0.0f;
jaroslav@67
    54
jaroslav@67
    55
    /**
jaroslav@67
    56
     * A constant holding the negative infinity of type
jaroslav@67
    57
     * {@code float}. It is equal to the value returned by
jaroslav@67
    58
     * {@code Float.intBitsToFloat(0xff800000)}.
jaroslav@67
    59
     */
jaroslav@67
    60
    public static final float NEGATIVE_INFINITY = -1.0f / 0.0f;
jaroslav@67
    61
jaroslav@67
    62
    /**
jaroslav@67
    63
     * A constant holding a Not-a-Number (NaN) value of type
jaroslav@67
    64
     * {@code float}.  It is equivalent to the value returned by
jaroslav@67
    65
     * {@code Float.intBitsToFloat(0x7fc00000)}.
jaroslav@67
    66
     */
jaroslav@67
    67
    public static final float NaN = 0.0f / 0.0f;
jaroslav@67
    68
jaroslav@67
    69
    /**
jaroslav@67
    70
     * A constant holding the largest positive finite value of type
jaroslav@67
    71
     * {@code float}, (2-2<sup>-23</sup>)&middot;2<sup>127</sup>.
jaroslav@67
    72
     * It is equal to the hexadecimal floating-point literal
jaroslav@67
    73
     * {@code 0x1.fffffeP+127f} and also equal to
jaroslav@67
    74
     * {@code Float.intBitsToFloat(0x7f7fffff)}.
jaroslav@67
    75
     */
jaroslav@67
    76
    public static final float MAX_VALUE = 0x1.fffffeP+127f; // 3.4028235e+38f
jaroslav@67
    77
jaroslav@67
    78
    /**
jaroslav@67
    79
     * A constant holding the smallest positive normal value of type
jaroslav@67
    80
     * {@code float}, 2<sup>-126</sup>.  It is equal to the
jaroslav@67
    81
     * hexadecimal floating-point literal {@code 0x1.0p-126f} and also
jaroslav@67
    82
     * equal to {@code Float.intBitsToFloat(0x00800000)}.
jaroslav@67
    83
     *
jaroslav@67
    84
     * @since 1.6
jaroslav@67
    85
     */
jaroslav@67
    86
    public static final float MIN_NORMAL = 0x1.0p-126f; // 1.17549435E-38f
jaroslav@67
    87
jaroslav@67
    88
    /**
jaroslav@67
    89
     * A constant holding the smallest positive nonzero value of type
jaroslav@67
    90
     * {@code float}, 2<sup>-149</sup>. It is equal to the
jaroslav@67
    91
     * hexadecimal floating-point literal {@code 0x0.000002P-126f}
jaroslav@67
    92
     * and also equal to {@code Float.intBitsToFloat(0x1)}.
jaroslav@67
    93
     */
jaroslav@67
    94
    public static final float MIN_VALUE = 0x0.000002P-126f; // 1.4e-45f
jaroslav@67
    95
jaroslav@67
    96
    /**
jaroslav@67
    97
     * Maximum exponent a finite {@code float} variable may have.  It
jaroslav@67
    98
     * is equal to the value returned by {@code
jaroslav@67
    99
     * Math.getExponent(Float.MAX_VALUE)}.
jaroslav@67
   100
     *
jaroslav@67
   101
     * @since 1.6
jaroslav@67
   102
     */
jaroslav@67
   103
    public static final int MAX_EXPONENT = 127;
jaroslav@67
   104
jaroslav@67
   105
    /**
jaroslav@67
   106
     * Minimum exponent a normalized {@code float} variable may have.
jaroslav@67
   107
     * It is equal to the value returned by {@code
jaroslav@67
   108
     * Math.getExponent(Float.MIN_NORMAL)}.
jaroslav@67
   109
     *
jaroslav@67
   110
     * @since 1.6
jaroslav@67
   111
     */
jaroslav@67
   112
    public static final int MIN_EXPONENT = -126;
jaroslav@67
   113
jaroslav@67
   114
    /**
jaroslav@67
   115
     * The number of bits used to represent a {@code float} value.
jaroslav@67
   116
     *
jaroslav@67
   117
     * @since 1.5
jaroslav@67
   118
     */
jaroslav@67
   119
    public static final int SIZE = 32;
jaroslav@67
   120
jaroslav@67
   121
    /**
jaroslav@67
   122
     * The {@code Class} instance representing the primitive type
jaroslav@67
   123
     * {@code float}.
jaroslav@67
   124
     *
jaroslav@67
   125
     * @since JDK1.1
jaroslav@67
   126
     */
jaroslav@67
   127
    public static final Class<Float> TYPE = Class.getPrimitiveClass("float");
jaroslav@67
   128
jaroslav@67
   129
    /**
jaroslav@67
   130
     * Returns a string representation of the {@code float}
jaroslav@67
   131
     * argument. All characters mentioned below are ASCII characters.
jaroslav@67
   132
     * <ul>
jaroslav@67
   133
     * <li>If the argument is NaN, the result is the string
jaroslav@67
   134
     * "{@code NaN}".
jaroslav@67
   135
     * <li>Otherwise, the result is a string that represents the sign and
jaroslav@67
   136
     *     magnitude (absolute value) of the argument. If the sign is
jaroslav@67
   137
     *     negative, the first character of the result is
jaroslav@67
   138
     *     '{@code -}' (<code>'&#92;u002D'</code>); if the sign is
jaroslav@67
   139
     *     positive, no sign character appears in the result. As for
jaroslav@67
   140
     *     the magnitude <i>m</i>:
jaroslav@67
   141
     * <ul>
jaroslav@67
   142
     * <li>If <i>m</i> is infinity, it is represented by the characters
jaroslav@67
   143
     *     {@code "Infinity"}; thus, positive infinity produces
jaroslav@67
   144
     *     the result {@code "Infinity"} and negative infinity
jaroslav@67
   145
     *     produces the result {@code "-Infinity"}.
jaroslav@67
   146
     * <li>If <i>m</i> is zero, it is represented by the characters
jaroslav@67
   147
     *     {@code "0.0"}; thus, negative zero produces the result
jaroslav@67
   148
     *     {@code "-0.0"} and positive zero produces the result
jaroslav@67
   149
     *     {@code "0.0"}.
jaroslav@67
   150
     * <li> If <i>m</i> is greater than or equal to 10<sup>-3</sup> but
jaroslav@67
   151
     *      less than 10<sup>7</sup>, then it is represented as the
jaroslav@67
   152
     *      integer part of <i>m</i>, in decimal form with no leading
jaroslav@67
   153
     *      zeroes, followed by '{@code .}'
jaroslav@67
   154
     *      (<code>'&#92;u002E'</code>), followed by one or more
jaroslav@67
   155
     *      decimal digits representing the fractional part of
jaroslav@67
   156
     *      <i>m</i>.
jaroslav@67
   157
     * <li> If <i>m</i> is less than 10<sup>-3</sup> or greater than or
jaroslav@67
   158
     *      equal to 10<sup>7</sup>, then it is represented in
jaroslav@67
   159
     *      so-called "computerized scientific notation." Let <i>n</i>
jaroslav@67
   160
     *      be the unique integer such that 10<sup><i>n</i> </sup>&le;
jaroslav@67
   161
     *      <i>m</i> {@literal <} 10<sup><i>n</i>+1</sup>; then let <i>a</i>
jaroslav@67
   162
     *      be the mathematically exact quotient of <i>m</i> and
jaroslav@67
   163
     *      10<sup><i>n</i></sup> so that 1 &le; <i>a</i> {@literal <} 10.
jaroslav@67
   164
     *      The magnitude is then represented as the integer part of
jaroslav@67
   165
     *      <i>a</i>, as a single decimal digit, followed by
jaroslav@67
   166
     *      '{@code .}' (<code>'&#92;u002E'</code>), followed by
jaroslav@67
   167
     *      decimal digits representing the fractional part of
jaroslav@67
   168
     *      <i>a</i>, followed by the letter '{@code E}'
jaroslav@67
   169
     *      (<code>'&#92;u0045'</code>), followed by a representation
jaroslav@67
   170
     *      of <i>n</i> as a decimal integer, as produced by the
jaroslav@67
   171
     *      method {@link java.lang.Integer#toString(int)}.
jaroslav@67
   172
     *
jaroslav@67
   173
     * </ul>
jaroslav@67
   174
     * </ul>
jaroslav@67
   175
     * How many digits must be printed for the fractional part of
jaroslav@67
   176
     * <i>m</i> or <i>a</i>? There must be at least one digit
jaroslav@67
   177
     * to represent the fractional part, and beyond that as many, but
jaroslav@67
   178
     * only as many, more digits as are needed to uniquely distinguish
jaroslav@67
   179
     * the argument value from adjacent values of type
jaroslav@67
   180
     * {@code float}. That is, suppose that <i>x</i> is the
jaroslav@67
   181
     * exact mathematical value represented by the decimal
jaroslav@67
   182
     * representation produced by this method for a finite nonzero
jaroslav@67
   183
     * argument <i>f</i>. Then <i>f</i> must be the {@code float}
jaroslav@67
   184
     * value nearest to <i>x</i>; or, if two {@code float} values are
jaroslav@67
   185
     * equally close to <i>x</i>, then <i>f</i> must be one of
jaroslav@67
   186
     * them and the least significant bit of the significand of
jaroslav@67
   187
     * <i>f</i> must be {@code 0}.
jaroslav@67
   188
     *
jaroslav@67
   189
     * <p>To create localized string representations of a floating-point
jaroslav@67
   190
     * value, use subclasses of {@link java.text.NumberFormat}.
jaroslav@67
   191
     *
jaroslav@67
   192
     * @param   f   the float to be converted.
jaroslav@67
   193
     * @return a string representation of the argument.
jaroslav@67
   194
     */
jaroslav@116
   195
    @JavaScriptBody(args="d", body="return d.toString();")
jaroslav@67
   196
    public static String toString(float f) {
jaroslav@84
   197
        throw new UnsupportedOperationException();
jaroslav@84
   198
//        return new FloatingDecimal(f).toJavaFormatString();
jaroslav@67
   199
    }
jaroslav@67
   200
jaroslav@67
   201
    /**
jaroslav@67
   202
     * Returns a hexadecimal string representation of the
jaroslav@67
   203
     * {@code float} argument. All characters mentioned below are
jaroslav@67
   204
     * ASCII characters.
jaroslav@67
   205
     *
jaroslav@67
   206
     * <ul>
jaroslav@67
   207
     * <li>If the argument is NaN, the result is the string
jaroslav@67
   208
     *     "{@code NaN}".
jaroslav@67
   209
     * <li>Otherwise, the result is a string that represents the sign and
jaroslav@67
   210
     * magnitude (absolute value) of the argument. If the sign is negative,
jaroslav@67
   211
     * the first character of the result is '{@code -}'
jaroslav@67
   212
     * (<code>'&#92;u002D'</code>); if the sign is positive, no sign character
jaroslav@67
   213
     * appears in the result. As for the magnitude <i>m</i>:
jaroslav@67
   214
     *
jaroslav@67
   215
     * <ul>
jaroslav@67
   216
     * <li>If <i>m</i> is infinity, it is represented by the string
jaroslav@67
   217
     * {@code "Infinity"}; thus, positive infinity produces the
jaroslav@67
   218
     * result {@code "Infinity"} and negative infinity produces
jaroslav@67
   219
     * the result {@code "-Infinity"}.
jaroslav@67
   220
     *
jaroslav@67
   221
     * <li>If <i>m</i> is zero, it is represented by the string
jaroslav@67
   222
     * {@code "0x0.0p0"}; thus, negative zero produces the result
jaroslav@67
   223
     * {@code "-0x0.0p0"} and positive zero produces the result
jaroslav@67
   224
     * {@code "0x0.0p0"}.
jaroslav@67
   225
     *
jaroslav@67
   226
     * <li>If <i>m</i> is a {@code float} value with a
jaroslav@67
   227
     * normalized representation, substrings are used to represent the
jaroslav@67
   228
     * significand and exponent fields.  The significand is
jaroslav@67
   229
     * represented by the characters {@code "0x1."}
jaroslav@67
   230
     * followed by a lowercase hexadecimal representation of the rest
jaroslav@67
   231
     * of the significand as a fraction.  Trailing zeros in the
jaroslav@67
   232
     * hexadecimal representation are removed unless all the digits
jaroslav@67
   233
     * are zero, in which case a single zero is used. Next, the
jaroslav@67
   234
     * exponent is represented by {@code "p"} followed
jaroslav@67
   235
     * by a decimal string of the unbiased exponent as if produced by
jaroslav@67
   236
     * a call to {@link Integer#toString(int) Integer.toString} on the
jaroslav@67
   237
     * exponent value.
jaroslav@67
   238
     *
jaroslav@67
   239
     * <li>If <i>m</i> is a {@code float} value with a subnormal
jaroslav@67
   240
     * representation, the significand is represented by the
jaroslav@67
   241
     * characters {@code "0x0."} followed by a
jaroslav@67
   242
     * hexadecimal representation of the rest of the significand as a
jaroslav@67
   243
     * fraction.  Trailing zeros in the hexadecimal representation are
jaroslav@67
   244
     * removed. Next, the exponent is represented by
jaroslav@67
   245
     * {@code "p-126"}.  Note that there must be at
jaroslav@67
   246
     * least one nonzero digit in a subnormal significand.
jaroslav@67
   247
     *
jaroslav@67
   248
     * </ul>
jaroslav@67
   249
     *
jaroslav@67
   250
     * </ul>
jaroslav@67
   251
     *
jaroslav@67
   252
     * <table border>
jaroslav@67
   253
     * <caption><h3>Examples</h3></caption>
jaroslav@67
   254
     * <tr><th>Floating-point Value</th><th>Hexadecimal String</th>
jaroslav@67
   255
     * <tr><td>{@code 1.0}</td> <td>{@code 0x1.0p0}</td>
jaroslav@67
   256
     * <tr><td>{@code -1.0}</td>        <td>{@code -0x1.0p0}</td>
jaroslav@67
   257
     * <tr><td>{@code 2.0}</td> <td>{@code 0x1.0p1}</td>
jaroslav@67
   258
     * <tr><td>{@code 3.0}</td> <td>{@code 0x1.8p1}</td>
jaroslav@67
   259
     * <tr><td>{@code 0.5}</td> <td>{@code 0x1.0p-1}</td>
jaroslav@67
   260
     * <tr><td>{@code 0.25}</td>        <td>{@code 0x1.0p-2}</td>
jaroslav@67
   261
     * <tr><td>{@code Float.MAX_VALUE}</td>
jaroslav@67
   262
     *     <td>{@code 0x1.fffffep127}</td>
jaroslav@67
   263
     * <tr><td>{@code Minimum Normal Value}</td>
jaroslav@67
   264
     *     <td>{@code 0x1.0p-126}</td>
jaroslav@67
   265
     * <tr><td>{@code Maximum Subnormal Value}</td>
jaroslav@67
   266
     *     <td>{@code 0x0.fffffep-126}</td>
jaroslav@67
   267
     * <tr><td>{@code Float.MIN_VALUE}</td>
jaroslav@67
   268
     *     <td>{@code 0x0.000002p-126}</td>
jaroslav@67
   269
     * </table>
jaroslav@67
   270
     * @param   f   the {@code float} to be converted.
jaroslav@67
   271
     * @return a hex string representation of the argument.
jaroslav@67
   272
     * @since 1.5
jaroslav@67
   273
     * @author Joseph D. Darcy
jaroslav@67
   274
     */
jaroslav@67
   275
    public static String toHexString(float f) {
jaroslav@84
   276
        throw new UnsupportedOperationException();
jaroslav@84
   277
//        if (Math.abs(f) < FloatConsts.MIN_NORMAL
jaroslav@84
   278
//            &&  f != 0.0f ) {// float subnormal
jaroslav@84
   279
//            // Adjust exponent to create subnormal double, then
jaroslav@84
   280
//            // replace subnormal double exponent with subnormal float
jaroslav@84
   281
//            // exponent
jaroslav@84
   282
//            String s = Double.toHexString(FpUtils.scalb((double)f,
jaroslav@84
   283
//                                                        /* -1022+126 */
jaroslav@84
   284
//                                                        DoubleConsts.MIN_EXPONENT-
jaroslav@84
   285
//                                                        FloatConsts.MIN_EXPONENT));
jaroslav@84
   286
//            return s.replaceFirst("p-1022$", "p-126");
jaroslav@84
   287
//        }
jaroslav@84
   288
//        else // double string will be the same as float string
jaroslav@84
   289
//            return Double.toHexString(f);
jaroslav@67
   290
    }
jaroslav@67
   291
jaroslav@67
   292
    /**
jaroslav@67
   293
     * Returns a {@code Float} object holding the
jaroslav@67
   294
     * {@code float} value represented by the argument string
jaroslav@67
   295
     * {@code s}.
jaroslav@67
   296
     *
jaroslav@67
   297
     * <p>If {@code s} is {@code null}, then a
jaroslav@67
   298
     * {@code NullPointerException} is thrown.
jaroslav@67
   299
     *
jaroslav@67
   300
     * <p>Leading and trailing whitespace characters in {@code s}
jaroslav@67
   301
     * are ignored.  Whitespace is removed as if by the {@link
jaroslav@67
   302
     * String#trim} method; that is, both ASCII space and control
jaroslav@67
   303
     * characters are removed. The rest of {@code s} should
jaroslav@67
   304
     * constitute a <i>FloatValue</i> as described by the lexical
jaroslav@67
   305
     * syntax rules:
jaroslav@67
   306
     *
jaroslav@67
   307
     * <blockquote>
jaroslav@67
   308
     * <dl>
jaroslav@67
   309
     * <dt><i>FloatValue:</i>
jaroslav@67
   310
     * <dd><i>Sign<sub>opt</sub></i> {@code NaN}
jaroslav@67
   311
     * <dd><i>Sign<sub>opt</sub></i> {@code Infinity}
jaroslav@67
   312
     * <dd><i>Sign<sub>opt</sub> FloatingPointLiteral</i>
jaroslav@67
   313
     * <dd><i>Sign<sub>opt</sub> HexFloatingPointLiteral</i>
jaroslav@67
   314
     * <dd><i>SignedInteger</i>
jaroslav@67
   315
     * </dl>
jaroslav@67
   316
     *
jaroslav@67
   317
     * <p>
jaroslav@67
   318
     *
jaroslav@67
   319
     * <dl>
jaroslav@67
   320
     * <dt><i>HexFloatingPointLiteral</i>:
jaroslav@67
   321
     * <dd> <i>HexSignificand BinaryExponent FloatTypeSuffix<sub>opt</sub></i>
jaroslav@67
   322
     * </dl>
jaroslav@67
   323
     *
jaroslav@67
   324
     * <p>
jaroslav@67
   325
     *
jaroslav@67
   326
     * <dl>
jaroslav@67
   327
     * <dt><i>HexSignificand:</i>
jaroslav@67
   328
     * <dd><i>HexNumeral</i>
jaroslav@67
   329
     * <dd><i>HexNumeral</i> {@code .}
jaroslav@67
   330
     * <dd>{@code 0x} <i>HexDigits<sub>opt</sub>
jaroslav@67
   331
     *     </i>{@code .}<i> HexDigits</i>
jaroslav@67
   332
     * <dd>{@code 0X}<i> HexDigits<sub>opt</sub>
jaroslav@67
   333
     *     </i>{@code .} <i>HexDigits</i>
jaroslav@67
   334
     * </dl>
jaroslav@67
   335
     *
jaroslav@67
   336
     * <p>
jaroslav@67
   337
     *
jaroslav@67
   338
     * <dl>
jaroslav@67
   339
     * <dt><i>BinaryExponent:</i>
jaroslav@67
   340
     * <dd><i>BinaryExponentIndicator SignedInteger</i>
jaroslav@67
   341
     * </dl>
jaroslav@67
   342
     *
jaroslav@67
   343
     * <p>
jaroslav@67
   344
     *
jaroslav@67
   345
     * <dl>
jaroslav@67
   346
     * <dt><i>BinaryExponentIndicator:</i>
jaroslav@67
   347
     * <dd>{@code p}
jaroslav@67
   348
     * <dd>{@code P}
jaroslav@67
   349
     * </dl>
jaroslav@67
   350
     *
jaroslav@67
   351
     * </blockquote>
jaroslav@67
   352
     *
jaroslav@67
   353
     * where <i>Sign</i>, <i>FloatingPointLiteral</i>,
jaroslav@67
   354
     * <i>HexNumeral</i>, <i>HexDigits</i>, <i>SignedInteger</i> and
jaroslav@67
   355
     * <i>FloatTypeSuffix</i> are as defined in the lexical structure
jaroslav@67
   356
     * sections of
jaroslav@67
   357
     * <cite>The Java&trade; Language Specification</cite>,
jaroslav@67
   358
     * except that underscores are not accepted between digits.
jaroslav@67
   359
     * If {@code s} does not have the form of
jaroslav@67
   360
     * a <i>FloatValue</i>, then a {@code NumberFormatException}
jaroslav@67
   361
     * is thrown. Otherwise, {@code s} is regarded as
jaroslav@67
   362
     * representing an exact decimal value in the usual
jaroslav@67
   363
     * "computerized scientific notation" or as an exact
jaroslav@67
   364
     * hexadecimal value; this exact numerical value is then
jaroslav@67
   365
     * conceptually converted to an "infinitely precise"
jaroslav@67
   366
     * binary value that is then rounded to type {@code float}
jaroslav@67
   367
     * by the usual round-to-nearest rule of IEEE 754 floating-point
jaroslav@67
   368
     * arithmetic, which includes preserving the sign of a zero
jaroslav@67
   369
     * value.
jaroslav@67
   370
     *
jaroslav@67
   371
     * Note that the round-to-nearest rule also implies overflow and
jaroslav@67
   372
     * underflow behaviour; if the exact value of {@code s} is large
jaroslav@67
   373
     * enough in magnitude (greater than or equal to ({@link
jaroslav@67
   374
     * #MAX_VALUE} + {@link Math#ulp(float) ulp(MAX_VALUE)}/2),
jaroslav@67
   375
     * rounding to {@code float} will result in an infinity and if the
jaroslav@67
   376
     * exact value of {@code s} is small enough in magnitude (less
jaroslav@67
   377
     * than or equal to {@link #MIN_VALUE}/2), rounding to float will
jaroslav@67
   378
     * result in a zero.
jaroslav@67
   379
     *
jaroslav@67
   380
     * Finally, after rounding a {@code Float} object representing
jaroslav@67
   381
     * this {@code float} value is returned.
jaroslav@67
   382
     *
jaroslav@67
   383
     * <p>To interpret localized string representations of a
jaroslav@67
   384
     * floating-point value, use subclasses of {@link
jaroslav@67
   385
     * java.text.NumberFormat}.
jaroslav@67
   386
     *
jaroslav@67
   387
     * <p>Note that trailing format specifiers, specifiers that
jaroslav@67
   388
     * determine the type of a floating-point literal
jaroslav@67
   389
     * ({@code 1.0f} is a {@code float} value;
jaroslav@67
   390
     * {@code 1.0d} is a {@code double} value), do
jaroslav@67
   391
     * <em>not</em> influence the results of this method.  In other
jaroslav@67
   392
     * words, the numerical value of the input string is converted
jaroslav@67
   393
     * directly to the target floating-point type.  In general, the
jaroslav@67
   394
     * two-step sequence of conversions, string to {@code double}
jaroslav@67
   395
     * followed by {@code double} to {@code float}, is
jaroslav@67
   396
     * <em>not</em> equivalent to converting a string directly to
jaroslav@67
   397
     * {@code float}.  For example, if first converted to an
jaroslav@67
   398
     * intermediate {@code double} and then to
jaroslav@67
   399
     * {@code float}, the string<br>
jaroslav@67
   400
     * {@code "1.00000017881393421514957253748434595763683319091796875001d"}<br>
jaroslav@67
   401
     * results in the {@code float} value
jaroslav@67
   402
     * {@code 1.0000002f}; if the string is converted directly to
jaroslav@67
   403
     * {@code float}, <code>1.000000<b>1</b>f</code> results.
jaroslav@67
   404
     *
jaroslav@67
   405
     * <p>To avoid calling this method on an invalid string and having
jaroslav@67
   406
     * a {@code NumberFormatException} be thrown, the documentation
jaroslav@67
   407
     * for {@link Double#valueOf Double.valueOf} lists a regular
jaroslav@67
   408
     * expression which can be used to screen the input.
jaroslav@67
   409
     *
jaroslav@67
   410
     * @param   s   the string to be parsed.
jaroslav@67
   411
     * @return  a {@code Float} object holding the value
jaroslav@67
   412
     *          represented by the {@code String} argument.
jaroslav@67
   413
     * @throws  NumberFormatException  if the string does not contain a
jaroslav@67
   414
     *          parsable number.
jaroslav@67
   415
     */
jaroslav@67
   416
    public static Float valueOf(String s) throws NumberFormatException {
jaroslav@84
   417
        throw new UnsupportedOperationException();
jaroslav@84
   418
//        return new Float(FloatingDecimal.readJavaFormatString(s).floatValue());
jaroslav@67
   419
    }
jaroslav@67
   420
jaroslav@67
   421
    /**
jaroslav@67
   422
     * Returns a {@code Float} instance representing the specified
jaroslav@67
   423
     * {@code float} value.
jaroslav@67
   424
     * If a new {@code Float} instance is not required, this method
jaroslav@67
   425
     * should generally be used in preference to the constructor
jaroslav@67
   426
     * {@link #Float(float)}, as this method is likely to yield
jaroslav@67
   427
     * significantly better space and time performance by caching
jaroslav@67
   428
     * frequently requested values.
jaroslav@67
   429
     *
jaroslav@67
   430
     * @param  f a float value.
jaroslav@67
   431
     * @return a {@code Float} instance representing {@code f}.
jaroslav@67
   432
     * @since  1.5
jaroslav@67
   433
     */
jaroslav@67
   434
    public static Float valueOf(float f) {
jaroslav@67
   435
        return new Float(f);
jaroslav@67
   436
    }
jaroslav@67
   437
jaroslav@67
   438
    /**
jaroslav@67
   439
     * Returns a new {@code float} initialized to the value
jaroslav@67
   440
     * represented by the specified {@code String}, as performed
jaroslav@67
   441
     * by the {@code valueOf} method of class {@code Float}.
jaroslav@67
   442
     *
jaroslav@67
   443
     * @param  s the string to be parsed.
jaroslav@67
   444
     * @return the {@code float} value represented by the string
jaroslav@67
   445
     *         argument.
jaroslav@67
   446
     * @throws NullPointerException  if the string is null
jaroslav@67
   447
     * @throws NumberFormatException if the string does not contain a
jaroslav@67
   448
     *               parsable {@code float}.
jaroslav@67
   449
     * @see    java.lang.Float#valueOf(String)
jaroslav@67
   450
     * @since 1.2
jaroslav@67
   451
     */
jaroslav@67
   452
    public static float parseFloat(String s) throws NumberFormatException {
jaroslav@84
   453
        throw new UnsupportedOperationException();
jaroslav@84
   454
//        return FloatingDecimal.readJavaFormatString(s).floatValue();
jaroslav@67
   455
    }
jaroslav@67
   456
jaroslav@67
   457
    /**
jaroslav@67
   458
     * Returns {@code true} if the specified number is a
jaroslav@67
   459
     * Not-a-Number (NaN) value, {@code false} otherwise.
jaroslav@67
   460
     *
jaroslav@67
   461
     * @param   v   the value to be tested.
jaroslav@67
   462
     * @return  {@code true} if the argument is NaN;
jaroslav@67
   463
     *          {@code false} otherwise.
jaroslav@67
   464
     */
jaroslav@67
   465
    static public boolean isNaN(float v) {
jaroslav@67
   466
        return (v != v);
jaroslav@67
   467
    }
jaroslav@67
   468
jaroslav@67
   469
    /**
jaroslav@67
   470
     * Returns {@code true} if the specified number is infinitely
jaroslav@67
   471
     * large in magnitude, {@code false} otherwise.
jaroslav@67
   472
     *
jaroslav@67
   473
     * @param   v   the value to be tested.
jaroslav@67
   474
     * @return  {@code true} if the argument is positive infinity or
jaroslav@67
   475
     *          negative infinity; {@code false} otherwise.
jaroslav@67
   476
     */
jaroslav@67
   477
    static public boolean isInfinite(float v) {
jaroslav@67
   478
        return (v == POSITIVE_INFINITY) || (v == NEGATIVE_INFINITY);
jaroslav@67
   479
    }
jaroslav@67
   480
jaroslav@67
   481
    /**
jaroslav@67
   482
     * The value of the Float.
jaroslav@67
   483
     *
jaroslav@67
   484
     * @serial
jaroslav@67
   485
     */
jaroslav@67
   486
    private final float value;
jaroslav@67
   487
jaroslav@67
   488
    /**
jaroslav@67
   489
     * Constructs a newly allocated {@code Float} object that
jaroslav@67
   490
     * represents the primitive {@code float} argument.
jaroslav@67
   491
     *
jaroslav@67
   492
     * @param   value   the value to be represented by the {@code Float}.
jaroslav@67
   493
     */
jaroslav@67
   494
    public Float(float value) {
jaroslav@67
   495
        this.value = value;
jaroslav@67
   496
    }
jaroslav@67
   497
jaroslav@67
   498
    /**
jaroslav@67
   499
     * Constructs a newly allocated {@code Float} object that
jaroslav@67
   500
     * represents the argument converted to type {@code float}.
jaroslav@67
   501
     *
jaroslav@67
   502
     * @param   value   the value to be represented by the {@code Float}.
jaroslav@67
   503
     */
jaroslav@67
   504
    public Float(double value) {
jaroslav@67
   505
        this.value = (float)value;
jaroslav@67
   506
    }
jaroslav@67
   507
jaroslav@67
   508
    /**
jaroslav@67
   509
     * Constructs a newly allocated {@code Float} object that
jaroslav@67
   510
     * represents the floating-point value of type {@code float}
jaroslav@67
   511
     * represented by the string. The string is converted to a
jaroslav@67
   512
     * {@code float} value as if by the {@code valueOf} method.
jaroslav@67
   513
     *
jaroslav@67
   514
     * @param      s   a string to be converted to a {@code Float}.
jaroslav@67
   515
     * @throws  NumberFormatException  if the string does not contain a
jaroslav@67
   516
     *               parsable number.
jaroslav@67
   517
     * @see        java.lang.Float#valueOf(java.lang.String)
jaroslav@67
   518
     */
jaroslav@67
   519
    public Float(String s) throws NumberFormatException {
jaroslav@67
   520
        // REMIND: this is inefficient
jaroslav@67
   521
        this(valueOf(s).floatValue());
jaroslav@67
   522
    }
jaroslav@67
   523
jaroslav@67
   524
    /**
jaroslav@67
   525
     * Returns {@code true} if this {@code Float} value is a
jaroslav@67
   526
     * Not-a-Number (NaN), {@code false} otherwise.
jaroslav@67
   527
     *
jaroslav@67
   528
     * @return  {@code true} if the value represented by this object is
jaroslav@67
   529
     *          NaN; {@code false} otherwise.
jaroslav@67
   530
     */
jaroslav@67
   531
    public boolean isNaN() {
jaroslav@67
   532
        return isNaN(value);
jaroslav@67
   533
    }
jaroslav@67
   534
jaroslav@67
   535
    /**
jaroslav@67
   536
     * Returns {@code true} if this {@code Float} value is
jaroslav@67
   537
     * infinitely large in magnitude, {@code false} otherwise.
jaroslav@67
   538
     *
jaroslav@67
   539
     * @return  {@code true} if the value represented by this object is
jaroslav@67
   540
     *          positive infinity or negative infinity;
jaroslav@67
   541
     *          {@code false} otherwise.
jaroslav@67
   542
     */
jaroslav@67
   543
    public boolean isInfinite() {
jaroslav@67
   544
        return isInfinite(value);
jaroslav@67
   545
    }
jaroslav@67
   546
jaroslav@67
   547
    /**
jaroslav@67
   548
     * Returns a string representation of this {@code Float} object.
jaroslav@67
   549
     * The primitive {@code float} value represented by this object
jaroslav@67
   550
     * is converted to a {@code String} exactly as if by the method
jaroslav@67
   551
     * {@code toString} of one argument.
jaroslav@67
   552
     *
jaroslav@67
   553
     * @return  a {@code String} representation of this object.
jaroslav@67
   554
     * @see java.lang.Float#toString(float)
jaroslav@67
   555
     */
jaroslav@67
   556
    public String toString() {
jaroslav@67
   557
        return Float.toString(value);
jaroslav@67
   558
    }
jaroslav@67
   559
jaroslav@67
   560
    /**
jaroslav@67
   561
     * Returns the value of this {@code Float} as a {@code byte} (by
jaroslav@67
   562
     * casting to a {@code byte}).
jaroslav@67
   563
     *
jaroslav@67
   564
     * @return  the {@code float} value represented by this object
jaroslav@67
   565
     *          converted to type {@code byte}
jaroslav@67
   566
     */
jaroslav@67
   567
    public byte byteValue() {
jaroslav@67
   568
        return (byte)value;
jaroslav@67
   569
    }
jaroslav@67
   570
jaroslav@67
   571
    /**
jaroslav@67
   572
     * Returns the value of this {@code Float} as a {@code short} (by
jaroslav@67
   573
     * casting to a {@code short}).
jaroslav@67
   574
     *
jaroslav@67
   575
     * @return  the {@code float} value represented by this object
jaroslav@67
   576
     *          converted to type {@code short}
jaroslav@67
   577
     * @since JDK1.1
jaroslav@67
   578
     */
jaroslav@67
   579
    public short shortValue() {
jaroslav@67
   580
        return (short)value;
jaroslav@67
   581
    }
jaroslav@67
   582
jaroslav@67
   583
    /**
jaroslav@67
   584
     * Returns the value of this {@code Float} as an {@code int} (by
jaroslav@67
   585
     * casting to type {@code int}).
jaroslav@67
   586
     *
jaroslav@67
   587
     * @return  the {@code float} value represented by this object
jaroslav@67
   588
     *          converted to type {@code int}
jaroslav@67
   589
     */
jaroslav@67
   590
    public int intValue() {
jaroslav@67
   591
        return (int)value;
jaroslav@67
   592
    }
jaroslav@67
   593
jaroslav@67
   594
    /**
jaroslav@67
   595
     * Returns value of this {@code Float} as a {@code long} (by
jaroslav@67
   596
     * casting to type {@code long}).
jaroslav@67
   597
     *
jaroslav@67
   598
     * @return  the {@code float} value represented by this object
jaroslav@67
   599
     *          converted to type {@code long}
jaroslav@67
   600
     */
jaroslav@67
   601
    public long longValue() {
jaroslav@67
   602
        return (long)value;
jaroslav@67
   603
    }
jaroslav@67
   604
jaroslav@67
   605
    /**
jaroslav@67
   606
     * Returns the {@code float} value of this {@code Float} object.
jaroslav@67
   607
     *
jaroslav@67
   608
     * @return the {@code float} value represented by this object
jaroslav@67
   609
     */
jaroslav@67
   610
    public float floatValue() {
jaroslav@67
   611
        return value;
jaroslav@67
   612
    }
jaroslav@67
   613
jaroslav@67
   614
    /**
jaroslav@67
   615
     * Returns the {@code double} value of this {@code Float} object.
jaroslav@67
   616
     *
jaroslav@67
   617
     * @return the {@code float} value represented by this
jaroslav@67
   618
     *         object is converted to type {@code double} and the
jaroslav@67
   619
     *         result of the conversion is returned.
jaroslav@67
   620
     */
jaroslav@67
   621
    public double doubleValue() {
jaroslav@67
   622
        return (double)value;
jaroslav@67
   623
    }
jaroslav@67
   624
jaroslav@67
   625
    /**
jaroslav@67
   626
     * Returns a hash code for this {@code Float} object. The
jaroslav@67
   627
     * result is the integer bit representation, exactly as produced
jaroslav@67
   628
     * by the method {@link #floatToIntBits(float)}, of the primitive
jaroslav@67
   629
     * {@code float} value represented by this {@code Float}
jaroslav@67
   630
     * object.
jaroslav@67
   631
     *
jaroslav@67
   632
     * @return a hash code value for this object.
jaroslav@67
   633
     */
jaroslav@67
   634
    public int hashCode() {
jaroslav@67
   635
        return floatToIntBits(value);
jaroslav@67
   636
    }
jaroslav@67
   637
jaroslav@67
   638
    /**
jaroslav@67
   639
jaroslav@67
   640
     * Compares this object against the specified object.  The result
jaroslav@67
   641
     * is {@code true} if and only if the argument is not
jaroslav@67
   642
     * {@code null} and is a {@code Float} object that
jaroslav@67
   643
     * represents a {@code float} with the same value as the
jaroslav@67
   644
     * {@code float} represented by this object. For this
jaroslav@67
   645
     * purpose, two {@code float} values are considered to be the
jaroslav@67
   646
     * same if and only if the method {@link #floatToIntBits(float)}
jaroslav@67
   647
     * returns the identical {@code int} value when applied to
jaroslav@67
   648
     * each.
jaroslav@67
   649
     *
jaroslav@67
   650
     * <p>Note that in most cases, for two instances of class
jaroslav@67
   651
     * {@code Float}, {@code f1} and {@code f2}, the value
jaroslav@67
   652
     * of {@code f1.equals(f2)} is {@code true} if and only if
jaroslav@67
   653
     *
jaroslav@67
   654
     * <blockquote><pre>
jaroslav@67
   655
     *   f1.floatValue() == f2.floatValue()
jaroslav@67
   656
     * </pre></blockquote>
jaroslav@67
   657
     *
jaroslav@67
   658
     * <p>also has the value {@code true}. However, there are two exceptions:
jaroslav@67
   659
     * <ul>
jaroslav@67
   660
     * <li>If {@code f1} and {@code f2} both represent
jaroslav@67
   661
     *     {@code Float.NaN}, then the {@code equals} method returns
jaroslav@67
   662
     *     {@code true}, even though {@code Float.NaN==Float.NaN}
jaroslav@67
   663
     *     has the value {@code false}.
jaroslav@67
   664
     * <li>If {@code f1} represents {@code +0.0f} while
jaroslav@67
   665
     *     {@code f2} represents {@code -0.0f}, or vice
jaroslav@67
   666
     *     versa, the {@code equal} test has the value
jaroslav@67
   667
     *     {@code false}, even though {@code 0.0f==-0.0f}
jaroslav@67
   668
     *     has the value {@code true}.
jaroslav@67
   669
     * </ul>
jaroslav@67
   670
     *
jaroslav@67
   671
     * This definition allows hash tables to operate properly.
jaroslav@67
   672
     *
jaroslav@67
   673
     * @param obj the object to be compared
jaroslav@67
   674
     * @return  {@code true} if the objects are the same;
jaroslav@67
   675
     *          {@code false} otherwise.
jaroslav@67
   676
     * @see java.lang.Float#floatToIntBits(float)
jaroslav@67
   677
     */
jaroslav@67
   678
    public boolean equals(Object obj) {
jaroslav@67
   679
        return (obj instanceof Float)
jaroslav@67
   680
               && (floatToIntBits(((Float)obj).value) == floatToIntBits(value));
jaroslav@67
   681
    }
jaroslav@67
   682
jaroslav@67
   683
    /**
jaroslav@67
   684
     * Returns a representation of the specified floating-point value
jaroslav@67
   685
     * according to the IEEE 754 floating-point "single format" bit
jaroslav@67
   686
     * layout.
jaroslav@67
   687
     *
jaroslav@67
   688
     * <p>Bit 31 (the bit that is selected by the mask
jaroslav@67
   689
     * {@code 0x80000000}) represents the sign of the floating-point
jaroslav@67
   690
     * number.
jaroslav@67
   691
     * Bits 30-23 (the bits that are selected by the mask
jaroslav@67
   692
     * {@code 0x7f800000}) represent the exponent.
jaroslav@67
   693
     * Bits 22-0 (the bits that are selected by the mask
jaroslav@67
   694
     * {@code 0x007fffff}) represent the significand (sometimes called
jaroslav@67
   695
     * the mantissa) of the floating-point number.
jaroslav@67
   696
     *
jaroslav@67
   697
     * <p>If the argument is positive infinity, the result is
jaroslav@67
   698
     * {@code 0x7f800000}.
jaroslav@67
   699
     *
jaroslav@67
   700
     * <p>If the argument is negative infinity, the result is
jaroslav@67
   701
     * {@code 0xff800000}.
jaroslav@67
   702
     *
jaroslav@67
   703
     * <p>If the argument is NaN, the result is {@code 0x7fc00000}.
jaroslav@67
   704
     *
jaroslav@67
   705
     * <p>In all cases, the result is an integer that, when given to the
jaroslav@67
   706
     * {@link #intBitsToFloat(int)} method, will produce a floating-point
jaroslav@67
   707
     * value the same as the argument to {@code floatToIntBits}
jaroslav@67
   708
     * (except all NaN values are collapsed to a single
jaroslav@67
   709
     * "canonical" NaN value).
jaroslav@67
   710
     *
jaroslav@67
   711
     * @param   value   a floating-point number.
jaroslav@67
   712
     * @return the bits that represent the floating-point number.
jaroslav@67
   713
     */
jaroslav@67
   714
    public static int floatToIntBits(float value) {
jaroslav@84
   715
        throw new UnsupportedOperationException();
jaroslav@84
   716
//        int result = floatToRawIntBits(value);
jaroslav@84
   717
//        // Check for NaN based on values of bit fields, maximum
jaroslav@84
   718
//        // exponent and nonzero significand.
jaroslav@84
   719
//        if ( ((result & FloatConsts.EXP_BIT_MASK) ==
jaroslav@84
   720
//              FloatConsts.EXP_BIT_MASK) &&
jaroslav@84
   721
//             (result & FloatConsts.SIGNIF_BIT_MASK) != 0)
jaroslav@84
   722
//            result = 0x7fc00000;
jaroslav@84
   723
//        return result;
jaroslav@67
   724
    }
jaroslav@67
   725
jaroslav@67
   726
    /**
jaroslav@67
   727
     * Returns a representation of the specified floating-point value
jaroslav@67
   728
     * according to the IEEE 754 floating-point "single format" bit
jaroslav@67
   729
     * layout, preserving Not-a-Number (NaN) values.
jaroslav@67
   730
     *
jaroslav@67
   731
     * <p>Bit 31 (the bit that is selected by the mask
jaroslav@67
   732
     * {@code 0x80000000}) represents the sign of the floating-point
jaroslav@67
   733
     * number.
jaroslav@67
   734
     * Bits 30-23 (the bits that are selected by the mask
jaroslav@67
   735
     * {@code 0x7f800000}) represent the exponent.
jaroslav@67
   736
     * Bits 22-0 (the bits that are selected by the mask
jaroslav@67
   737
     * {@code 0x007fffff}) represent the significand (sometimes called
jaroslav@67
   738
     * the mantissa) of the floating-point number.
jaroslav@67
   739
     *
jaroslav@67
   740
     * <p>If the argument is positive infinity, the result is
jaroslav@67
   741
     * {@code 0x7f800000}.
jaroslav@67
   742
     *
jaroslav@67
   743
     * <p>If the argument is negative infinity, the result is
jaroslav@67
   744
     * {@code 0xff800000}.
jaroslav@67
   745
     *
jaroslav@67
   746
     * <p>If the argument is NaN, the result is the integer representing
jaroslav@67
   747
     * the actual NaN value.  Unlike the {@code floatToIntBits}
jaroslav@67
   748
     * method, {@code floatToRawIntBits} does not collapse all the
jaroslav@67
   749
     * bit patterns encoding a NaN to a single "canonical"
jaroslav@67
   750
     * NaN value.
jaroslav@67
   751
     *
jaroslav@67
   752
     * <p>In all cases, the result is an integer that, when given to the
jaroslav@67
   753
     * {@link #intBitsToFloat(int)} method, will produce a
jaroslav@67
   754
     * floating-point value the same as the argument to
jaroslav@67
   755
     * {@code floatToRawIntBits}.
jaroslav@67
   756
     *
jaroslav@67
   757
     * @param   value   a floating-point number.
jaroslav@67
   758
     * @return the bits that represent the floating-point number.
jaroslav@67
   759
     * @since 1.3
jaroslav@67
   760
     */
jaroslav@67
   761
    public static native int floatToRawIntBits(float value);
jaroslav@67
   762
jaroslav@67
   763
    /**
jaroslav@67
   764
     * Returns the {@code float} value corresponding to a given
jaroslav@67
   765
     * bit representation.
jaroslav@67
   766
     * The argument is considered to be a representation of a
jaroslav@67
   767
     * floating-point value according to the IEEE 754 floating-point
jaroslav@67
   768
     * "single format" bit layout.
jaroslav@67
   769
     *
jaroslav@67
   770
     * <p>If the argument is {@code 0x7f800000}, the result is positive
jaroslav@67
   771
     * infinity.
jaroslav@67
   772
     *
jaroslav@67
   773
     * <p>If the argument is {@code 0xff800000}, the result is negative
jaroslav@67
   774
     * infinity.
jaroslav@67
   775
     *
jaroslav@67
   776
     * <p>If the argument is any value in the range
jaroslav@67
   777
     * {@code 0x7f800001} through {@code 0x7fffffff} or in
jaroslav@67
   778
     * the range {@code 0xff800001} through
jaroslav@67
   779
     * {@code 0xffffffff}, the result is a NaN.  No IEEE 754
jaroslav@67
   780
     * floating-point operation provided by Java can distinguish
jaroslav@67
   781
     * between two NaN values of the same type with different bit
jaroslav@67
   782
     * patterns.  Distinct values of NaN are only distinguishable by
jaroslav@67
   783
     * use of the {@code Float.floatToRawIntBits} method.
jaroslav@67
   784
     *
jaroslav@67
   785
     * <p>In all other cases, let <i>s</i>, <i>e</i>, and <i>m</i> be three
jaroslav@67
   786
     * values that can be computed from the argument:
jaroslav@67
   787
     *
jaroslav@67
   788
     * <blockquote><pre>
jaroslav@67
   789
     * int s = ((bits &gt;&gt; 31) == 0) ? 1 : -1;
jaroslav@67
   790
     * int e = ((bits &gt;&gt; 23) & 0xff);
jaroslav@67
   791
     * int m = (e == 0) ?
jaroslav@67
   792
     *                 (bits & 0x7fffff) &lt;&lt; 1 :
jaroslav@67
   793
     *                 (bits & 0x7fffff) | 0x800000;
jaroslav@67
   794
     * </pre></blockquote>
jaroslav@67
   795
     *
jaroslav@67
   796
     * Then the floating-point result equals the value of the mathematical
jaroslav@67
   797
     * expression <i>s</i>&middot;<i>m</i>&middot;2<sup><i>e</i>-150</sup>.
jaroslav@67
   798
     *
jaroslav@67
   799
     * <p>Note that this method may not be able to return a
jaroslav@67
   800
     * {@code float} NaN with exactly same bit pattern as the
jaroslav@67
   801
     * {@code int} argument.  IEEE 754 distinguishes between two
jaroslav@67
   802
     * kinds of NaNs, quiet NaNs and <i>signaling NaNs</i>.  The
jaroslav@67
   803
     * differences between the two kinds of NaN are generally not
jaroslav@67
   804
     * visible in Java.  Arithmetic operations on signaling NaNs turn
jaroslav@67
   805
     * them into quiet NaNs with a different, but often similar, bit
jaroslav@67
   806
     * pattern.  However, on some processors merely copying a
jaroslav@67
   807
     * signaling NaN also performs that conversion.  In particular,
jaroslav@67
   808
     * copying a signaling NaN to return it to the calling method may
jaroslav@67
   809
     * perform this conversion.  So {@code intBitsToFloat} may
jaroslav@67
   810
     * not be able to return a {@code float} with a signaling NaN
jaroslav@67
   811
     * bit pattern.  Consequently, for some {@code int} values,
jaroslav@67
   812
     * {@code floatToRawIntBits(intBitsToFloat(start))} may
jaroslav@67
   813
     * <i>not</i> equal {@code start}.  Moreover, which
jaroslav@67
   814
     * particular bit patterns represent signaling NaNs is platform
jaroslav@67
   815
     * dependent; although all NaN bit patterns, quiet or signaling,
jaroslav@67
   816
     * must be in the NaN range identified above.
jaroslav@67
   817
     *
jaroslav@67
   818
     * @param   bits   an integer.
jaroslav@67
   819
     * @return  the {@code float} floating-point value with the same bit
jaroslav@67
   820
     *          pattern.
jaroslav@67
   821
     */
jaroslav@181
   822
    @JavaScriptBody(args = "bits",
jaroslav@181
   823
        body = 
jaroslav@181
   824
          "if (bits === 0x7f800000) return Number.POSITIVE_INFINITY;\n"
jaroslav@181
   825
        + "if (bits === 0xff800000) return Number.NEGATIVE_INFINITY;\n"
jaroslav@181
   826
        + "if (bits >= 0x7f800001 && bits <= 0xffffffff) return Number.NaN;\n"
jaroslav@181
   827
        + "var s = ((bits >> 31) == 0) ? 1 : -1;\n"
jaroslav@181
   828
        + "var e = ((bits >> 23) & 0xff);\n"
jaroslav@181
   829
        + "var m = (e == 0) ?\n"
jaroslav@181
   830
        + "  (bits & 0x7fffff) << 1 :\n"
jaroslav@181
   831
        + "  (bits & 0x7fffff) | 0x800000;\n"
jaroslav@181
   832
        + "return s * m * Math.pow(2.0, e - 150);\n"
jaroslav@181
   833
    )
jaroslav@67
   834
    public static native float intBitsToFloat(int bits);
jaroslav@67
   835
jaroslav@67
   836
    /**
jaroslav@67
   837
     * Compares two {@code Float} objects numerically.  There are
jaroslav@67
   838
     * two ways in which comparisons performed by this method differ
jaroslav@67
   839
     * from those performed by the Java language numerical comparison
jaroslav@67
   840
     * operators ({@code <, <=, ==, >=, >}) when
jaroslav@67
   841
     * applied to primitive {@code float} values:
jaroslav@67
   842
     *
jaroslav@67
   843
     * <ul><li>
jaroslav@67
   844
     *          {@code Float.NaN} is considered by this method to
jaroslav@67
   845
     *          be equal to itself and greater than all other
jaroslav@67
   846
     *          {@code float} values
jaroslav@67
   847
     *          (including {@code Float.POSITIVE_INFINITY}).
jaroslav@67
   848
     * <li>
jaroslav@67
   849
     *          {@code 0.0f} is considered by this method to be greater
jaroslav@67
   850
     *          than {@code -0.0f}.
jaroslav@67
   851
     * </ul>
jaroslav@67
   852
     *
jaroslav@67
   853
     * This ensures that the <i>natural ordering</i> of {@code Float}
jaroslav@67
   854
     * objects imposed by this method is <i>consistent with equals</i>.
jaroslav@67
   855
     *
jaroslav@67
   856
     * @param   anotherFloat   the {@code Float} to be compared.
jaroslav@67
   857
     * @return  the value {@code 0} if {@code anotherFloat} is
jaroslav@67
   858
     *          numerically equal to this {@code Float}; a value
jaroslav@67
   859
     *          less than {@code 0} if this {@code Float}
jaroslav@67
   860
     *          is numerically less than {@code anotherFloat};
jaroslav@67
   861
     *          and a value greater than {@code 0} if this
jaroslav@67
   862
     *          {@code Float} is numerically greater than
jaroslav@67
   863
     *          {@code anotherFloat}.
jaroslav@67
   864
     *
jaroslav@67
   865
     * @since   1.2
jaroslav@67
   866
     * @see Comparable#compareTo(Object)
jaroslav@67
   867
     */
jaroslav@67
   868
    public int compareTo(Float anotherFloat) {
jaroslav@67
   869
        return Float.compare(value, anotherFloat.value);
jaroslav@67
   870
    }
jaroslav@67
   871
jaroslav@67
   872
    /**
jaroslav@67
   873
     * Compares the two specified {@code float} values. The sign
jaroslav@67
   874
     * of the integer value returned is the same as that of the
jaroslav@67
   875
     * integer that would be returned by the call:
jaroslav@67
   876
     * <pre>
jaroslav@67
   877
     *    new Float(f1).compareTo(new Float(f2))
jaroslav@67
   878
     * </pre>
jaroslav@67
   879
     *
jaroslav@67
   880
     * @param   f1        the first {@code float} to compare.
jaroslav@67
   881
     * @param   f2        the second {@code float} to compare.
jaroslav@67
   882
     * @return  the value {@code 0} if {@code f1} is
jaroslav@67
   883
     *          numerically equal to {@code f2}; a value less than
jaroslav@67
   884
     *          {@code 0} if {@code f1} is numerically less than
jaroslav@67
   885
     *          {@code f2}; and a value greater than {@code 0}
jaroslav@67
   886
     *          if {@code f1} is numerically greater than
jaroslav@67
   887
     *          {@code f2}.
jaroslav@67
   888
     * @since 1.4
jaroslav@67
   889
     */
jaroslav@67
   890
    public static int compare(float f1, float f2) {
jaroslav@67
   891
        if (f1 < f2)
jaroslav@67
   892
            return -1;           // Neither val is NaN, thisVal is smaller
jaroslav@67
   893
        if (f1 > f2)
jaroslav@67
   894
            return 1;            // Neither val is NaN, thisVal is larger
jaroslav@67
   895
jaroslav@67
   896
        // Cannot use floatToRawIntBits because of possibility of NaNs.
jaroslav@67
   897
        int thisBits    = Float.floatToIntBits(f1);
jaroslav@67
   898
        int anotherBits = Float.floatToIntBits(f2);
jaroslav@67
   899
jaroslav@67
   900
        return (thisBits == anotherBits ?  0 : // Values are equal
jaroslav@67
   901
                (thisBits < anotherBits ? -1 : // (-0.0, 0.0) or (!NaN, NaN)
jaroslav@67
   902
                 1));                          // (0.0, -0.0) or (NaN, !NaN)
jaroslav@67
   903
    }
jaroslav@67
   904
jaroslav@67
   905
    /** use serialVersionUID from JDK 1.0.2 for interoperability */
jaroslav@67
   906
    private static final long serialVersionUID = -2671257302660747028L;
jaroslav@67
   907
}