src/java.base/share/classes/java/lang/Float.java
author vromero
Thu, 13 Dec 2018 10:35:09 -0500
changeset 53019 4ddd3c410a85
parent 52914 4fa75d8ad418
child 54952 a978d86ac389
permissions -rw-r--r--
8215300: additional changes to constants API Reviewed-by: goetz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
52914
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
     2
 * Copyright (c) 1994, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3964
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3964
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3964
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3964
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3964
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.lang;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
52914
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
    28
import java.lang.invoke.MethodHandles;
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
    29
import java.lang.constant.Constable;
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
    30
import java.lang.constant.ConstantDesc;
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
    31
import java.util.Optional;
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
    32
34781
479b1724ab80 8145990: Move sun.misc math support classes to jdk.internal.math
chegar
parents: 31671
diff changeset
    33
import jdk.internal.math.FloatingDecimal;
31671
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
    34
import jdk.internal.HotSpotIntrinsicCandidate;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * The {@code Float} class wraps a value of primitive type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * {@code float} in an object. An object of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * {@code Float} contains a single field whose type is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * {@code float}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <p>In addition, this class provides several methods for converting a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * {@code float} to a {@code String} and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * {@code String} to a {@code float}, as well as other
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * constants and methods useful when dealing with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * {@code float}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @author  Lee Boynton
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @author  Arthur van Hoff
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @author  Joseph D. Darcy
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 22290
diff changeset
    51
 * @since 1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
52914
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
    53
public final class Float extends Number
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
    54
        implements Comparable<Float>, Constable, ConstantDesc {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * A constant holding the positive infinity of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * {@code float}. It is equal to the value returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * {@code Float.intBitsToFloat(0x7f800000)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public static final float POSITIVE_INFINITY = 1.0f / 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * A constant holding the negative infinity of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * {@code float}. It is equal to the value returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * {@code Float.intBitsToFloat(0xff800000)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public static final float NEGATIVE_INFINITY = -1.0f / 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * A constant holding a Not-a-Number (NaN) value of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * {@code float}.  It is equivalent to the value returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * {@code Float.intBitsToFloat(0x7fc00000)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public static final float NaN = 0.0f / 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * A constant holding the largest positive finite value of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * {@code float}, (2-2<sup>-23</sup>)&middot;2<sup>127</sup>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * It is equal to the hexadecimal floating-point literal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * {@code 0x1.fffffeP+127f} and also equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * {@code Float.intBitsToFloat(0x7f7fffff)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public static final float MAX_VALUE = 0x1.fffffeP+127f; // 3.4028235e+38f
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * A constant holding the smallest positive normal value of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * {@code float}, 2<sup>-126</sup>.  It is equal to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * hexadecimal floating-point literal {@code 0x1.0p-126f} and also
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * equal to {@code Float.intBitsToFloat(0x00800000)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public static final float MIN_NORMAL = 0x1.0p-126f; // 1.17549435E-38f
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * A constant holding the smallest positive nonzero value of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * {@code float}, 2<sup>-149</sup>. It is equal to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * hexadecimal floating-point literal {@code 0x0.000002P-126f}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * and also equal to {@code Float.intBitsToFloat(0x1)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public static final float MIN_VALUE = 0x0.000002P-126f; // 1.4e-45f
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Maximum exponent a finite {@code float} variable may have.  It
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * is equal to the value returned by {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Math.getExponent(Float.MAX_VALUE)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public static final int MAX_EXPONENT = 127;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Minimum exponent a normalized {@code float} variable may have.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * It is equal to the value returned by {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Math.getExponent(Float.MIN_NORMAL)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public static final int MIN_EXPONENT = -126;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * The number of bits used to represent a {@code float} value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public static final int SIZE = 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
14507
066419d1e732 7088952: Add size in bytes constant "BYTES" to primitive type wrapper types
mduigou
parents: 14503
diff changeset
   129
     * The number of bytes used to represent a {@code float} value.
066419d1e732 7088952: Add size in bytes constant "BYTES" to primitive type wrapper types
mduigou
parents: 14503
diff changeset
   130
     *
066419d1e732 7088952: Add size in bytes constant "BYTES" to primitive type wrapper types
mduigou
parents: 14503
diff changeset
   131
     * @since 1.8
066419d1e732 7088952: Add size in bytes constant "BYTES" to primitive type wrapper types
mduigou
parents: 14503
diff changeset
   132
     */
066419d1e732 7088952: Add size in bytes constant "BYTES" to primitive type wrapper types
mduigou
parents: 14503
diff changeset
   133
    public static final int BYTES = SIZE / Byte.SIZE;
066419d1e732 7088952: Add size in bytes constant "BYTES" to primitive type wrapper types
mduigou
parents: 14503
diff changeset
   134
066419d1e732 7088952: Add size in bytes constant "BYTES" to primitive type wrapper types
mduigou
parents: 14503
diff changeset
   135
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * The {@code Class} instance representing the primitive type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * {@code float}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 22290
diff changeset
   139
     * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
11275
7cb0861d512f 7117612: Miscellaneous warnings in java.lang
omajid
parents: 11016
diff changeset
   141
    @SuppressWarnings("unchecked")
7cb0861d512f 7117612: Miscellaneous warnings in java.lang
omajid
parents: 11016
diff changeset
   142
    public static final Class<Float> TYPE = (Class<Float>) Class.getPrimitiveClass("float");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * Returns a string representation of the {@code float}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * argument. All characters mentioned below are ASCII characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * <li>If the argument is NaN, the result is the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * "{@code NaN}".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * <li>Otherwise, the result is a string that represents the sign and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *     magnitude (absolute value) of the argument. If the sign is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *     negative, the first character of the result is
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 11275
diff changeset
   153
     *     '{@code -}' ({@code '\u005Cu002D'}); if the sign is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *     positive, no sign character appears in the result. As for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *     the magnitude <i>m</i>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * <li>If <i>m</i> is infinity, it is represented by the characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *     {@code "Infinity"}; thus, positive infinity produces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *     the result {@code "Infinity"} and negative infinity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *     produces the result {@code "-Infinity"}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * <li>If <i>m</i> is zero, it is represented by the characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *     {@code "0.0"}; thus, negative zero produces the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *     {@code "-0.0"} and positive zero produces the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *     {@code "0.0"}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * <li> If <i>m</i> is greater than or equal to 10<sup>-3</sup> but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *      less than 10<sup>7</sup>, then it is represented as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *      integer part of <i>m</i>, in decimal form with no leading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *      zeroes, followed by '{@code .}'
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 11275
diff changeset
   169
     *      ({@code '\u005Cu002E'}), followed by one or more
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *      decimal digits representing the fractional part of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *      <i>m</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * <li> If <i>m</i> is less than 10<sup>-3</sup> or greater than or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *      equal to 10<sup>7</sup>, then it is represented in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *      so-called "computerized scientific notation." Let <i>n</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *      be the unique integer such that 10<sup><i>n</i> </sup>&le;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *      <i>m</i> {@literal <} 10<sup><i>n</i>+1</sup>; then let <i>a</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *      be the mathematically exact quotient of <i>m</i> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *      10<sup><i>n</i></sup> so that 1 &le; <i>a</i> {@literal <} 10.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *      The magnitude is then represented as the integer part of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *      <i>a</i>, as a single decimal digit, followed by
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 11275
diff changeset
   181
     *      '{@code .}' ({@code '\u005Cu002E'}), followed by
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *      decimal digits representing the fractional part of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *      <i>a</i>, followed by the letter '{@code E}'
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 11275
diff changeset
   184
     *      ({@code '\u005Cu0045'}), followed by a representation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *      of <i>n</i> as a decimal integer, as produced by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *      method {@link java.lang.Integer#toString(int)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * How many digits must be printed for the fractional part of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * <i>m</i> or <i>a</i>? There must be at least one digit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * to represent the fractional part, and beyond that as many, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * only as many, more digits as are needed to uniquely distinguish
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * the argument value from adjacent values of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * {@code float}. That is, suppose that <i>x</i> is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * exact mathematical value represented by the decimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * representation produced by this method for a finite nonzero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * argument <i>f</i>. Then <i>f</i> must be the {@code float}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * value nearest to <i>x</i>; or, if two {@code float} values are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * equally close to <i>x</i>, then <i>f</i> must be one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * them and the least significant bit of the significand of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * <i>f</i> must be {@code 0}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * <p>To create localized string representations of a floating-point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * value, use subclasses of {@link java.text.NumberFormat}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @param   f   the float to be converted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @return a string representation of the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public static String toString(float f) {
18143
b6ef7bd945ce 7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents: 15311
diff changeset
   211
        return FloatingDecimal.toJavaFormatString(f);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * Returns a hexadecimal string representation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * {@code float} argument. All characters mentioned below are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * ASCII characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * <li>If the argument is NaN, the result is the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *     "{@code NaN}".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * <li>Otherwise, the result is a string that represents the sign and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * magnitude (absolute value) of the argument. If the sign is negative,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * the first character of the result is '{@code -}'
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 11275
diff changeset
   225
     * ({@code '\u005Cu002D'}); if the sign is positive, no sign character
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * appears in the result. As for the magnitude <i>m</i>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * <li>If <i>m</i> is infinity, it is represented by the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * {@code "Infinity"}; thus, positive infinity produces the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * result {@code "Infinity"} and negative infinity produces
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * the result {@code "-Infinity"}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * <li>If <i>m</i> is zero, it is represented by the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * {@code "0x0.0p0"}; thus, negative zero produces the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * {@code "-0x0.0p0"} and positive zero produces the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * {@code "0x0.0p0"}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * <li>If <i>m</i> is a {@code float} value with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * normalized representation, substrings are used to represent the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * significand and exponent fields.  The significand is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * represented by the characters {@code "0x1."}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * followed by a lowercase hexadecimal representation of the rest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * of the significand as a fraction.  Trailing zeros in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * hexadecimal representation are removed unless all the digits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * are zero, in which case a single zero is used. Next, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * exponent is represented by {@code "p"} followed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * by a decimal string of the unbiased exponent as if produced by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * a call to {@link Integer#toString(int) Integer.toString} on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * exponent value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * <li>If <i>m</i> is a {@code float} value with a subnormal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * representation, the significand is represented by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * characters {@code "0x0."} followed by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * hexadecimal representation of the rest of the significand as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * fraction.  Trailing zeros in the hexadecimal representation are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * removed. Next, the exponent is represented by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * {@code "p-126"}.  Note that there must be at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * least one nonzero digit in a subnormal significand.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *
46148
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 45124
diff changeset
   265
     * <table class="striped">
18776
c17100862d86 8019862: Fix doclint errors in java.lang.*.
bpb
parents: 18546
diff changeset
   266
     * <caption>Examples</caption>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 37521
diff changeset
   267
     * <thead>
46148
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 45124
diff changeset
   268
     * <tr><th scope="col">Floating-point Value</th><th scope="col">Hexadecimal String</th>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 37521
diff changeset
   269
     * </thead>
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 37521
diff changeset
   270
     * <tbody>
46148
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 45124
diff changeset
   271
     * <tr><th scope="row">{@code 1.0}</th> <td>{@code 0x1.0p0}</td>
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 45124
diff changeset
   272
     * <tr><th scope="row">{@code -1.0}</th>        <td>{@code -0x1.0p0}</td>
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 45124
diff changeset
   273
     * <tr><th scope="row">{@code 2.0}</th> <td>{@code 0x1.0p1}</td>
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 45124
diff changeset
   274
     * <tr><th scope="row">{@code 3.0}</th> <td>{@code 0x1.8p1}</td>
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 45124
diff changeset
   275
     * <tr><th scope="row">{@code 0.5}</th> <td>{@code 0x1.0p-1}</td>
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 45124
diff changeset
   276
     * <tr><th scope="row">{@code 0.25}</th>        <td>{@code 0x1.0p-2}</td>
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 45124
diff changeset
   277
     * <tr><th scope="row">{@code Float.MAX_VALUE}</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *     <td>{@code 0x1.fffffep127}</td>
46148
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 45124
diff changeset
   279
     * <tr><th scope="row">{@code Minimum Normal Value}</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     *     <td>{@code 0x1.0p-126}</td>
46148
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 45124
diff changeset
   281
     * <tr><th scope="row">{@code Maximum Subnormal Value}</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *     <td>{@code 0x0.fffffep-126}</td>
46148
6d8e27cd2f1e 8186052: Fix a11y and HTML issues in the java.base/java.lang[.*] packages
jjg
parents: 45124
diff changeset
   283
     * <tr><th scope="row">{@code Float.MIN_VALUE}</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *     <td>{@code 0x0.000002p-126}</td>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 37521
diff changeset
   285
     * </tbody>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @param   f   the {@code float} to be converted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @return a hex string representation of the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @author Joseph D. Darcy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    public static String toHexString(float f) {
35979
4462913d471a 8149896: Remove unnecessary values in FloatConsts and DoubleConsts
darcy
parents: 34781
diff changeset
   293
        if (Math.abs(f) < Float.MIN_NORMAL
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            &&  f != 0.0f ) {// float subnormal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            // Adjust exponent to create subnormal double, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            // replace subnormal double exponent with subnormal float
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            // exponent
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 10067
diff changeset
   298
            String s = Double.toHexString(Math.scalb((double)f,
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 10067
diff changeset
   299
                                                     /* -1022+126 */
35979
4462913d471a 8149896: Remove unnecessary values in FloatConsts and DoubleConsts
darcy
parents: 34781
diff changeset
   300
                                                     Double.MIN_EXPONENT-
4462913d471a 8149896: Remove unnecessary values in FloatConsts and DoubleConsts
darcy
parents: 34781
diff changeset
   301
                                                     Float.MIN_EXPONENT));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            return s.replaceFirst("p-1022$", "p-126");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        else // double string will be the same as float string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            return Double.toHexString(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * Returns a {@code Float} object holding the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * {@code float} value represented by the argument string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * {@code s}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * <p>If {@code s} is {@code null}, then a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * {@code NullPointerException} is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * <p>Leading and trailing whitespace characters in {@code s}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * are ignored.  Whitespace is removed as if by the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * String#trim} method; that is, both ASCII space and control
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * characters are removed. The rest of {@code s} should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * constitute a <i>FloatValue</i> as described by the lexical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * syntax rules:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * <dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * <dt><i>FloatValue:</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * <dd><i>Sign<sub>opt</sub></i> {@code NaN}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * <dd><i>Sign<sub>opt</sub></i> {@code Infinity}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * <dd><i>Sign<sub>opt</sub> FloatingPointLiteral</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * <dd><i>Sign<sub>opt</sub> HexFloatingPointLiteral</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * <dd><i>SignedInteger</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * <dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * <dt><i>HexFloatingPointLiteral</i>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * <dd> <i>HexSignificand BinaryExponent FloatTypeSuffix<sub>opt</sub></i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * <dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * <dt><i>HexSignificand:</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * <dd><i>HexNumeral</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * <dd><i>HexNumeral</i> {@code .}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * <dd>{@code 0x} <i>HexDigits<sub>opt</sub>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *     </i>{@code .}<i> HexDigits</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * <dd>{@code 0X}<i> HexDigits<sub>opt</sub>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *     </i>{@code .} <i>HexDigits</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * <dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * <dt><i>BinaryExponent:</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * <dd><i>BinaryExponentIndicator SignedInteger</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * <dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * <dt><i>BinaryExponentIndicator:</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * <dd>{@code p}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * <dd>{@code P}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * where <i>Sign</i>, <i>FloatingPointLiteral</i>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * <i>HexNumeral</i>, <i>HexDigits</i>, <i>SignedInteger</i> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * <i>FloatTypeSuffix</i> are as defined in the lexical structure
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7517
diff changeset
   364
     * sections of
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7517
diff changeset
   365
     * <cite>The Java&trade; Language Specification</cite>,
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7517
diff changeset
   366
     * except that underscores are not accepted between digits.
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7517
diff changeset
   367
     * If {@code s} does not have the form of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * a <i>FloatValue</i>, then a {@code NumberFormatException}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * is thrown. Otherwise, {@code s} is regarded as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * representing an exact decimal value in the usual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * "computerized scientific notation" or as an exact
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * hexadecimal value; this exact numerical value is then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * conceptually converted to an "infinitely precise"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * binary value that is then rounded to type {@code float}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * by the usual round-to-nearest rule of IEEE 754 floating-point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * arithmetic, which includes preserving the sign of a zero
1824
7a685390c6ab 6604864: Double.valueOf(String) does not specify behaviour for overflow and underflow
darcy
parents: 2
diff changeset
   377
     * value.
7a685390c6ab 6604864: Double.valueOf(String) does not specify behaviour for overflow and underflow
darcy
parents: 2
diff changeset
   378
     *
7a685390c6ab 6604864: Double.valueOf(String) does not specify behaviour for overflow and underflow
darcy
parents: 2
diff changeset
   379
     * Note that the round-to-nearest rule also implies overflow and
7a685390c6ab 6604864: Double.valueOf(String) does not specify behaviour for overflow and underflow
darcy
parents: 2
diff changeset
   380
     * underflow behaviour; if the exact value of {@code s} is large
7a685390c6ab 6604864: Double.valueOf(String) does not specify behaviour for overflow and underflow
darcy
parents: 2
diff changeset
   381
     * enough in magnitude (greater than or equal to ({@link
7a685390c6ab 6604864: Double.valueOf(String) does not specify behaviour for overflow and underflow
darcy
parents: 2
diff changeset
   382
     * #MAX_VALUE} + {@link Math#ulp(float) ulp(MAX_VALUE)}/2),
7a685390c6ab 6604864: Double.valueOf(String) does not specify behaviour for overflow and underflow
darcy
parents: 2
diff changeset
   383
     * rounding to {@code float} will result in an infinity and if the
7a685390c6ab 6604864: Double.valueOf(String) does not specify behaviour for overflow and underflow
darcy
parents: 2
diff changeset
   384
     * exact value of {@code s} is small enough in magnitude (less
7a685390c6ab 6604864: Double.valueOf(String) does not specify behaviour for overflow and underflow
darcy
parents: 2
diff changeset
   385
     * than or equal to {@link #MIN_VALUE}/2), rounding to float will
7a685390c6ab 6604864: Double.valueOf(String) does not specify behaviour for overflow and underflow
darcy
parents: 2
diff changeset
   386
     * result in a zero.
7a685390c6ab 6604864: Double.valueOf(String) does not specify behaviour for overflow and underflow
darcy
parents: 2
diff changeset
   387
     *
7a685390c6ab 6604864: Double.valueOf(String) does not specify behaviour for overflow and underflow
darcy
parents: 2
diff changeset
   388
     * Finally, after rounding a {@code Float} object representing
7a685390c6ab 6604864: Double.valueOf(String) does not specify behaviour for overflow and underflow
darcy
parents: 2
diff changeset
   389
     * this {@code float} value is returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * <p>To interpret localized string representations of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * floating-point value, use subclasses of {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * java.text.NumberFormat}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * <p>Note that trailing format specifiers, specifiers that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * determine the type of a floating-point literal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * ({@code 1.0f} is a {@code float} value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * {@code 1.0d} is a {@code double} value), do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * <em>not</em> influence the results of this method.  In other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * words, the numerical value of the input string is converted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * directly to the target floating-point type.  In general, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * two-step sequence of conversions, string to {@code double}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * followed by {@code double} to {@code float}, is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * <em>not</em> equivalent to converting a string directly to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * {@code float}.  For example, if first converted to an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * intermediate {@code double} and then to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * {@code float}, the string<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * {@code "1.00000017881393421514957253748434595763683319091796875001d"}<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * results in the {@code float} value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * {@code 1.0000002f}; if the string is converted directly to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * {@code float}, <code>1.000000<b>1</b>f</code> results.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * <p>To avoid calling this method on an invalid string and having
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * a {@code NumberFormatException} be thrown, the documentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * for {@link Double#valueOf Double.valueOf} lists a regular
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * expression which can be used to screen the input.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @param   s   the string to be parsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @return  a {@code Float} object holding the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *          represented by the {@code String} argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @throws  NumberFormatException  if the string does not contain a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     *          parsable number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    public static Float valueOf(String s) throws NumberFormatException {
18143
b6ef7bd945ce 7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents: 15311
diff changeset
   425
        return new Float(parseFloat(s));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * Returns a {@code Float} instance representing the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * {@code float} value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * If a new {@code Float} instance is not required, this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * should generally be used in preference to the constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * {@link #Float(float)}, as this method is likely to yield
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * significantly better space and time performance by caching
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * frequently requested values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @param  f a float value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @return a {@code Float} instance representing {@code f}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     */
31671
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   441
    @HotSpotIntrinsicCandidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    public static Float valueOf(float f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        return new Float(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * Returns a new {@code float} initialized to the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * represented by the specified {@code String}, as performed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * by the {@code valueOf} method of class {@code Float}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     *
3312
d8cd9665ece8 6463998: Undocumented NullPointerExeption from Float.parseFloat and Double.parseDouble
darcy
parents: 1824
diff changeset
   451
     * @param  s the string to be parsed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * @return the {@code float} value represented by the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     *         argument.
3312
d8cd9665ece8 6463998: Undocumented NullPointerExeption from Float.parseFloat and Double.parseDouble
darcy
parents: 1824
diff changeset
   454
     * @throws NullPointerException  if the string is null
d8cd9665ece8 6463998: Undocumented NullPointerExeption from Float.parseFloat and Double.parseDouble
darcy
parents: 1824
diff changeset
   455
     * @throws NumberFormatException if the string does not contain a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     *               parsable {@code float}.
3312
d8cd9665ece8 6463998: Undocumented NullPointerExeption from Float.parseFloat and Double.parseDouble
darcy
parents: 1824
diff changeset
   457
     * @see    java.lang.Float#valueOf(String)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    public static float parseFloat(String s) throws NumberFormatException {
18143
b6ef7bd945ce 7032154: Performance tuning of sun.misc.FloatingDecimal/FormattedFloatingDecimal
bpb
parents: 15311
diff changeset
   461
        return FloatingDecimal.parseFloat(s);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * Returns {@code true} if the specified number is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * Not-a-Number (NaN) value, {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * @param   v   the value to be tested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * @return  {@code true} if the argument is NaN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     *          {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     */
10608
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   472
    public static boolean isNaN(float v) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        return (v != v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * Returns {@code true} if the specified number is infinitely
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * large in magnitude, {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * @param   v   the value to be tested.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * @return  {@code true} if the argument is positive infinity or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     *          negative infinity; {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     */
10608
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   484
    public static boolean isInfinite(float v) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        return (v == POSITIVE_INFINITY) || (v == NEGATIVE_INFINITY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
10608
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   488
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   489
    /**
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   490
     * Returns {@code true} if the argument is a finite floating-point
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   491
     * value; returns {@code false} otherwise (for NaN and infinity
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   492
     * arguments).
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   493
     *
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   494
     * @param f the {@code float} value to be tested
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   495
     * @return {@code true} if the argument is a finite
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   496
     * floating-point value, {@code false} otherwise.
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   497
     * @since 1.8
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   498
     */
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   499
     public static boolean isFinite(float f) {
35979
4462913d471a 8149896: Remove unnecessary values in FloatConsts and DoubleConsts
darcy
parents: 34781
diff changeset
   500
        return Math.abs(f) <= Float.MAX_VALUE;
10608
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   501
    }
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   502
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * The value of the Float.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    private final float value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * Constructs a newly allocated {@code Float} object that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * represents the primitive {@code float} argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * @param   value   the value to be represented by the {@code Float}.
37521
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 35979
diff changeset
   515
     *
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 35979
diff changeset
   516
     * @deprecated
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 35979
diff changeset
   517
     * It is rarely appropriate to use this constructor. The static factory
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 35979
diff changeset
   518
     * {@link #valueOf(float)} is generally a better choice, as it is
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 35979
diff changeset
   519
     * likely to yield significantly better space and time performance.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     */
37521
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 35979
diff changeset
   521
    @Deprecated(since="9")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    public Float(float value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        this.value = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * Constructs a newly allocated {@code Float} object that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * represents the argument converted to type {@code float}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * @param   value   the value to be represented by the {@code Float}.
37521
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 35979
diff changeset
   531
     *
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 35979
diff changeset
   532
     * @deprecated
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 35979
diff changeset
   533
     * It is rarely appropriate to use this constructor. Instead, use the
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 35979
diff changeset
   534
     * static factory method {@link #valueOf(float)} method as follows:
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 35979
diff changeset
   535
     * {@code Float.valueOf((float)value)}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     */
37521
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 35979
diff changeset
   537
    @Deprecated(since="9")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    public Float(double value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        this.value = (float)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * Constructs a newly allocated {@code Float} object that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * represents the floating-point value of type {@code float}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * represented by the string. The string is converted to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * {@code float} value as if by the {@code valueOf} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     *
37521
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 35979
diff changeset
   548
     * @param   s   a string to be converted to a {@code Float}.
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 35979
diff changeset
   549
     * @throws      NumberFormatException if the string does not contain a
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 35979
diff changeset
   550
     *              parsable number.
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 35979
diff changeset
   551
     *
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 35979
diff changeset
   552
     * @deprecated
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 35979
diff changeset
   553
     * It is rarely appropriate to use this constructor.
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 35979
diff changeset
   554
     * Use {@link #parseFloat(String)} to convert a string to a
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 35979
diff changeset
   555
     * {@code float} primitive, or use {@link #valueOf(String)}
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 35979
diff changeset
   556
     * to convert a string to a {@code Float} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     */
37521
b6e0f285c998 8145468: update java.lang APIs with new deprecations
smarks
parents: 35979
diff changeset
   558
    @Deprecated(since="9")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    public Float(String s) throws NumberFormatException {
11016
e2665f4ac6d2 7110111: Minor Java SE javadoc & Constructor clean up
lancea
parents: 10608
diff changeset
   560
        value = parseFloat(s);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * Returns {@code true} if this {@code Float} value is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * Not-a-Number (NaN), {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * @return  {@code true} if the value represented by this object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     *          NaN; {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    public boolean isNaN() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        return isNaN(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * Returns {@code true} if this {@code Float} value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * infinitely large in magnitude, {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * @return  {@code true} if the value represented by this object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     *          positive infinity or negative infinity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     *          {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    public boolean isInfinite() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        return isInfinite(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * Returns a string representation of this {@code Float} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * The primitive {@code float} value represented by this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * is converted to a {@code String} exactly as if by the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * {@code toString} of one argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * @return  a {@code String} representation of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * @see java.lang.Float#toString(float)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    public String toString() {
3964
cf913644be58 6480728: Byte.valueOf(byte) returns a cached value but Byte.valueOf(String)
darcy
parents: 3312
diff changeset
   596
        return Float.toString(value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    /**
10067
1263ecd22db6 6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents: 9266
diff changeset
   600
     * Returns the value of this {@code Float} as a {@code byte} after
1263ecd22db6 6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents: 9266
diff changeset
   601
     * a narrowing primitive conversion.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * @return  the {@code float} value represented by this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     *          converted to type {@code byte}
10067
1263ecd22db6 6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents: 9266
diff changeset
   605
     * @jls 5.1.3 Narrowing Primitive Conversions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    public byte byteValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        return (byte)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    /**
10067
1263ecd22db6 6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents: 9266
diff changeset
   612
     * Returns the value of this {@code Float} as a {@code short}
1263ecd22db6 6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents: 9266
diff changeset
   613
     * after a narrowing primitive conversion.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * @return  the {@code float} value represented by this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     *          converted to type {@code short}
10067
1263ecd22db6 6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents: 9266
diff changeset
   617
     * @jls 5.1.3 Narrowing Primitive Conversions
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 22290
diff changeset
   618
     * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    public short shortValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        return (short)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    /**
10067
1263ecd22db6 6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents: 9266
diff changeset
   625
     * Returns the value of this {@code Float} as an {@code int} after
1263ecd22db6 6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents: 9266
diff changeset
   626
     * a narrowing primitive conversion.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * @return  the {@code float} value represented by this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     *          converted to type {@code int}
10067
1263ecd22db6 6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents: 9266
diff changeset
   630
     * @jls 5.1.3 Narrowing Primitive Conversions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    public int intValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        return (int)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    /**
10067
1263ecd22db6 6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents: 9266
diff changeset
   637
     * Returns value of this {@code Float} as a {@code long} after a
1263ecd22db6 6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents: 9266
diff changeset
   638
     * narrowing primitive conversion.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * @return  the {@code float} value represented by this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     *          converted to type {@code long}
10067
1263ecd22db6 6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents: 9266
diff changeset
   642
     * @jls 5.1.3 Narrowing Primitive Conversions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    public long longValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        return (long)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * Returns the {@code float} value of this {@code Float} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * @return the {@code float} value represented by this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     */
31671
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   653
    @HotSpotIntrinsicCandidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    public float floatValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    /**
10067
1263ecd22db6 6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents: 9266
diff changeset
   659
     * Returns the value of this {@code Float} as a {@code double}
1263ecd22db6 6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents: 9266
diff changeset
   660
     * after a widening primitive conversion.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * @return the {@code float} value represented by this
10067
1263ecd22db6 6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents: 9266
diff changeset
   663
     *         object converted to type {@code double}
1263ecd22db6 6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents: 9266
diff changeset
   664
     * @jls 5.1.2 Widening Primitive Conversions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    public double doubleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        return (double)value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * Returns a hash code for this {@code Float} object. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * result is the integer bit representation, exactly as produced
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * by the method {@link #floatToIntBits(float)}, of the primitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * {@code float} value represented by this {@code Float}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * @return a hash code value for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     */
14503
0729d9e57ed5 7088913: Add compatible static hashCode(primitive) to primitive wrapper classes
mduigou
parents: 11676
diff changeset
   679
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    public int hashCode() {
14503
0729d9e57ed5 7088913: Add compatible static hashCode(primitive) to primitive wrapper classes
mduigou
parents: 11676
diff changeset
   681
        return Float.hashCode(value);
0729d9e57ed5 7088913: Add compatible static hashCode(primitive) to primitive wrapper classes
mduigou
parents: 11676
diff changeset
   682
    }
0729d9e57ed5 7088913: Add compatible static hashCode(primitive) to primitive wrapper classes
mduigou
parents: 11676
diff changeset
   683
0729d9e57ed5 7088913: Add compatible static hashCode(primitive) to primitive wrapper classes
mduigou
parents: 11676
diff changeset
   684
    /**
0729d9e57ed5 7088913: Add compatible static hashCode(primitive) to primitive wrapper classes
mduigou
parents: 11676
diff changeset
   685
     * Returns a hash code for a {@code float} value; compatible with
0729d9e57ed5 7088913: Add compatible static hashCode(primitive) to primitive wrapper classes
mduigou
parents: 11676
diff changeset
   686
     * {@code Float.hashCode()}.
0729d9e57ed5 7088913: Add compatible static hashCode(primitive) to primitive wrapper classes
mduigou
parents: 11676
diff changeset
   687
     *
18546
862067c6481c 8017550: Fix doclint issues in java.lang and subpackages
darcy
parents: 18156
diff changeset
   688
     * @param value the value to hash
862067c6481c 8017550: Fix doclint issues in java.lang and subpackages
darcy
parents: 18156
diff changeset
   689
     * @return a hash code value for a {@code float} value.
14503
0729d9e57ed5 7088913: Add compatible static hashCode(primitive) to primitive wrapper classes
mduigou
parents: 11676
diff changeset
   690
     * @since 1.8
0729d9e57ed5 7088913: Add compatible static hashCode(primitive) to primitive wrapper classes
mduigou
parents: 11676
diff changeset
   691
     */
0729d9e57ed5 7088913: Add compatible static hashCode(primitive) to primitive wrapper classes
mduigou
parents: 11676
diff changeset
   692
    public static int hashCode(float value) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        return floatToIntBits(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * Compares this object against the specified object.  The result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * is {@code true} if and only if the argument is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * {@code null} and is a {@code Float} object that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * represents a {@code float} with the same value as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * {@code float} represented by this object. For this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * purpose, two {@code float} values are considered to be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * same if and only if the method {@link #floatToIntBits(float)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * returns the identical {@code int} value when applied to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * each.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * <p>Note that in most cases, for two instances of class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * {@code Float}, {@code f1} and {@code f2}, the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * of {@code f1.equals(f2)} is {@code true} if and only if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     *   f1.floatValue() == f2.floatValue()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * <p>also has the value {@code true}. However, there are two exceptions:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * <li>If {@code f1} and {@code f2} both represent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     *     {@code Float.NaN}, then the {@code equals} method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     *     {@code true}, even though {@code Float.NaN==Float.NaN}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     *     has the value {@code false}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * <li>If {@code f1} represents {@code +0.0f} while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     *     {@code f2} represents {@code -0.0f}, or vice
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     *     versa, the {@code equal} test has the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     *     {@code false}, even though {@code 0.0f==-0.0f}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     *     has the value {@code true}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * This definition allows hash tables to operate properly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * @param obj the object to be compared
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * @return  {@code true} if the objects are the same;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     *          {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * @see java.lang.Float#floatToIntBits(float)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        return (obj instanceof Float)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
               && (floatToIntBits(((Float)obj).value) == floatToIntBits(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * Returns a representation of the specified floating-point value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * according to the IEEE 754 floating-point "single format" bit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * <p>Bit 31 (the bit that is selected by the mask
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * {@code 0x80000000}) represents the sign of the floating-point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * Bits 30-23 (the bits that are selected by the mask
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * {@code 0x7f800000}) represent the exponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * Bits 22-0 (the bits that are selected by the mask
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * {@code 0x007fffff}) represent the significand (sometimes called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * the mantissa) of the floating-point number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * <p>If the argument is positive infinity, the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * {@code 0x7f800000}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * <p>If the argument is negative infinity, the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * {@code 0xff800000}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * <p>If the argument is NaN, the result is {@code 0x7fc00000}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * <p>In all cases, the result is an integer that, when given to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * {@link #intBitsToFloat(int)} method, will produce a floating-point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * value the same as the argument to {@code floatToIntBits}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * (except all NaN values are collapsed to a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * "canonical" NaN value).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * @param   value   a floating-point number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * @return the bits that represent the floating-point number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     */
31671
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   772
    @HotSpotIntrinsicCandidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    public static int floatToIntBits(float value) {
22290
6d4551cf4b3e 6667086: Double.doubleToLongBits(final double value) contains inefficient test for NaN
bpb
parents: 21334
diff changeset
   774
        if (!isNaN(value)) {
6d4551cf4b3e 6667086: Double.doubleToLongBits(final double value) contains inefficient test for NaN
bpb
parents: 21334
diff changeset
   775
            return floatToRawIntBits(value);
6d4551cf4b3e 6667086: Double.doubleToLongBits(final double value) contains inefficient test for NaN
bpb
parents: 21334
diff changeset
   776
        }
6d4551cf4b3e 6667086: Double.doubleToLongBits(final double value) contains inefficient test for NaN
bpb
parents: 21334
diff changeset
   777
        return 0x7fc00000;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * Returns a representation of the specified floating-point value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * according to the IEEE 754 floating-point "single format" bit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * layout, preserving Not-a-Number (NaN) values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * <p>Bit 31 (the bit that is selected by the mask
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * {@code 0x80000000}) represents the sign of the floating-point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * Bits 30-23 (the bits that are selected by the mask
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * {@code 0x7f800000}) represent the exponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * Bits 22-0 (the bits that are selected by the mask
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * {@code 0x007fffff}) represent the significand (sometimes called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * the mantissa) of the floating-point number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * <p>If the argument is positive infinity, the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * {@code 0x7f800000}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * <p>If the argument is negative infinity, the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * {@code 0xff800000}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * <p>If the argument is NaN, the result is the integer representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * the actual NaN value.  Unlike the {@code floatToIntBits}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * method, {@code floatToRawIntBits} does not collapse all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * bit patterns encoding a NaN to a single "canonical"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * NaN value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * <p>In all cases, the result is an integer that, when given to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * {@link #intBitsToFloat(int)} method, will produce a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * floating-point value the same as the argument to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * {@code floatToRawIntBits}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * @param   value   a floating-point number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * @return the bits that represent the floating-point number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     */
31671
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   815
    @HotSpotIntrinsicCandidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    public static native int floatToRawIntBits(float value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * Returns the {@code float} value corresponding to a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * bit representation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * The argument is considered to be a representation of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * floating-point value according to the IEEE 754 floating-point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * "single format" bit layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * <p>If the argument is {@code 0x7f800000}, the result is positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * <p>If the argument is {@code 0xff800000}, the result is negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * <p>If the argument is any value in the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * {@code 0x7f800001} through {@code 0x7fffffff} or in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * the range {@code 0xff800001} through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * {@code 0xffffffff}, the result is a NaN.  No IEEE 754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * floating-point operation provided by Java can distinguish
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * between two NaN values of the same type with different bit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * patterns.  Distinct values of NaN are only distinguishable by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * use of the {@code Float.floatToRawIntBits} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * <p>In all other cases, let <i>s</i>, <i>e</i>, and <i>m</i> be three
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * values that can be computed from the argument:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     *
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 18143
diff changeset
   843
     * <blockquote><pre>{@code
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 18143
diff changeset
   844
     * int s = ((bits >> 31) == 0) ? 1 : -1;
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 18143
diff changeset
   845
     * int e = ((bits >> 23) & 0xff);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * int m = (e == 0) ?
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 18143
diff changeset
   847
     *                 (bits & 0x7fffff) << 1 :
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     *                 (bits & 0x7fffff) | 0x800000;
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 18143
diff changeset
   849
     * }</pre></blockquote>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * Then the floating-point result equals the value of the mathematical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * expression <i>s</i>&middot;<i>m</i>&middot;2<sup><i>e</i>-150</sup>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * <p>Note that this method may not be able to return a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * {@code float} NaN with exactly same bit pattern as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * {@code int} argument.  IEEE 754 distinguishes between two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * kinds of NaNs, quiet NaNs and <i>signaling NaNs</i>.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * differences between the two kinds of NaN are generally not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * visible in Java.  Arithmetic operations on signaling NaNs turn
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * them into quiet NaNs with a different, but often similar, bit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * pattern.  However, on some processors merely copying a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * signaling NaN also performs that conversion.  In particular,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * copying a signaling NaN to return it to the calling method may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * perform this conversion.  So {@code intBitsToFloat} may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * not be able to return a {@code float} with a signaling NaN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * bit pattern.  Consequently, for some {@code int} values,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * {@code floatToRawIntBits(intBitsToFloat(start))} may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * <i>not</i> equal {@code start}.  Moreover, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * particular bit patterns represent signaling NaNs is platform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * dependent; although all NaN bit patterns, quiet or signaling,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     * must be in the NaN range identified above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * @param   bits   an integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * @return  the {@code float} floating-point value with the same bit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     *          pattern.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     */
31671
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   877
    @HotSpotIntrinsicCandidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    public static native float intBitsToFloat(int bits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * Compares two {@code Float} objects numerically.  There are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * two ways in which comparisons performed by this method differ
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * from those performed by the Java language numerical comparison
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * operators ({@code <, <=, ==, >=, >}) when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * applied to primitive {@code float} values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * <ul><li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     *          {@code Float.NaN} is considered by this method to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     *          be equal to itself and greater than all other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     *          {@code float} values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     *          (including {@code Float.POSITIVE_INFINITY}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     *          {@code 0.0f} is considered by this method to be greater
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     *          than {@code -0.0f}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * This ensures that the <i>natural ordering</i> of {@code Float}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * objects imposed by this method is <i>consistent with equals</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * @param   anotherFloat   the {@code Float} to be compared.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * @return  the value {@code 0} if {@code anotherFloat} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     *          numerically equal to this {@code Float}; a value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     *          less than {@code 0} if this {@code Float}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     *          is numerically less than {@code anotherFloat};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     *          and a value greater than {@code 0} if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     *          {@code Float} is numerically greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     *          {@code anotherFloat}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     * @since   1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * @see Comparable#compareTo(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    public int compareTo(Float anotherFloat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        return Float.compare(value, anotherFloat.value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     * Compares the two specified {@code float} values. The sign
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * of the integer value returned is the same as that of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * integer that would be returned by the call:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     *    new Float(f1).compareTo(new Float(f2))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * @param   f1        the first {@code float} to compare.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * @param   f2        the second {@code float} to compare.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * @return  the value {@code 0} if {@code f1} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     *          numerically equal to {@code f2}; a value less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     *          {@code 0} if {@code f1} is numerically less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     *          {@code f2}; and a value greater than {@code 0}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     *          if {@code f1} is numerically greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     *          {@code f2}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    public static int compare(float f1, float f2) {
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   935
        if (f1 < f2)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            return -1;           // Neither val is NaN, thisVal is smaller
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        if (f1 > f2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            return 1;            // Neither val is NaN, thisVal is larger
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   940
        // Cannot use floatToRawIntBits because of possibility of NaNs.
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   941
        int thisBits    = Float.floatToIntBits(f1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        int anotherBits = Float.floatToIntBits(f2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        return (thisBits == anotherBits ?  0 : // Values are equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                (thisBits < anotherBits ? -1 : // (-0.0, 0.0) or (!NaN, NaN)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                 1));                          // (0.0, -0.0) or (NaN, !NaN)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
15311
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   949
    /**
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   950
     * Adds two {@code float} values together as per the + operator.
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   951
     *
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   952
     * @param a the first operand
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   953
     * @param b the second operand
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   954
     * @return the sum of {@code a} and {@code b}
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   955
     * @jls 4.2.4 Floating-Point Operations
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   956
     * @see java.util.function.BinaryOperator
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   957
     * @since 1.8
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   958
     */
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   959
    public static float sum(float a, float b) {
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   960
        return a + b;
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   961
    }
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   962
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   963
    /**
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   964
     * Returns the greater of two {@code float} values
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   965
     * as if by calling {@link Math#max(float, float) Math.max}.
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   966
     *
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   967
     * @param a the first operand
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   968
     * @param b the second operand
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   969
     * @return the greater of {@code a} and {@code b}
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   970
     * @see java.util.function.BinaryOperator
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   971
     * @since 1.8
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   972
     */
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   973
    public static float max(float a, float b) {
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   974
        return Math.max(a, b);
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   975
    }
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   976
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   977
    /**
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   978
     * Returns the smaller of two {@code float} values
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   979
     * as if by calling {@link Math#min(float, float) Math.min}.
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   980
     *
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   981
     * @param a the first operand
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   982
     * @param b the second operand
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   983
     * @return the smaller of {@code a} and {@code b}
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   984
     * @see java.util.function.BinaryOperator
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   985
     * @since 1.8
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   986
     */
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   987
    public static float min(float a, float b) {
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   988
        return Math.min(a, b);
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   989
    }
be0ff4a719bf 8004201: Add static utility methods to primitives to be used for redution operations.
mduigou
parents: 14507
diff changeset
   990
52914
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
   991
    /**
53019
4ddd3c410a85 8215300: additional changes to constants API
vromero
parents: 52914
diff changeset
   992
     * Returns an {@link Optional} containing the nominal descriptor for this
4ddd3c410a85 8215300: additional changes to constants API
vromero
parents: 52914
diff changeset
   993
     * instance, which is the instance itself.
52914
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
   994
     *
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
   995
     * @return an {@link Optional} describing the {@linkplain Float} instance
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
   996
     * @since 12
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
   997
     */
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
   998
    @Override
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
   999
    public Optional<Float> describeConstable() {
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
  1000
        return Optional.of(this);
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
  1001
    }
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
  1002
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
  1003
    /**
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
  1004
     * Resolves this instance as a {@link ConstantDesc}, the result of which is
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
  1005
     * the instance itself.
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
  1006
     *
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
  1007
     * @param lookup ignored
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
  1008
     * @return the {@linkplain Float} instance
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
  1009
     * @since 12
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
  1010
     */
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
  1011
    @Override
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
  1012
    public Float resolveConstantDesc(MethodHandles.Lookup lookup) {
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
  1013
        return this;
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
  1014
    }
4fa75d8ad418 8210031: implementation for JVM Constants API
vromero
parents: 47216
diff changeset
  1015
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
    /** use serialVersionUID from JDK 1.0.2 for interoperability */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    private static final long serialVersionUID = -2671257302660747028L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
}