< prev index next >

src/java.base/share/classes/java/lang/Float.java

Print this page
rev 52865 : [mq]: 8210031


   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang;
  27 





  28 import jdk.internal.math.FloatingDecimal;
  29 import jdk.internal.HotSpotIntrinsicCandidate;
  30 
  31 /**
  32  * The {@code Float} class wraps a value of primitive type
  33  * {@code float} in an object. An object of type
  34  * {@code Float} contains a single field whose type is
  35  * {@code float}.
  36  *
  37  * <p>In addition, this class provides several methods for converting a
  38  * {@code float} to a {@code String} and a
  39  * {@code String} to a {@code float}, as well as other
  40  * constants and methods useful when dealing with a
  41  * {@code float}.
  42  *
  43  * @author  Lee Boynton
  44  * @author  Arthur van Hoff
  45  * @author  Joseph D. Darcy
  46  * @since 1.0
  47  */
  48 public final class Float extends Number implements Comparable<Float> {

  49     /**
  50      * A constant holding the positive infinity of type
  51      * {@code float}. It is equal to the value returned by
  52      * {@code Float.intBitsToFloat(0x7f800000)}.
  53      */
  54     public static final float POSITIVE_INFINITY = 1.0f / 0.0f;
  55 
  56     /**
  57      * A constant holding the negative infinity of type
  58      * {@code float}. It is equal to the value returned by
  59      * {@code Float.intBitsToFloat(0xff800000)}.
  60      */
  61     public static final float NEGATIVE_INFINITY = -1.0f / 0.0f;
  62 
  63     /**
  64      * A constant holding a Not-a-Number (NaN) value of type
  65      * {@code float}.  It is equivalent to the value returned by
  66      * {@code Float.intBitsToFloat(0x7fc00000)}.
  67      */
  68     public static final float NaN = 0.0f / 0.0f;


 963      * @return the greater of {@code a} and {@code b}
 964      * @see java.util.function.BinaryOperator
 965      * @since 1.8
 966      */
 967     public static float max(float a, float b) {
 968         return Math.max(a, b);
 969     }
 970 
 971     /**
 972      * Returns the smaller of two {@code float} values
 973      * as if by calling {@link Math#min(float, float) Math.min}.
 974      *
 975      * @param a the first operand
 976      * @param b the second operand
 977      * @return the smaller of {@code a} and {@code b}
 978      * @see java.util.function.BinaryOperator
 979      * @since 1.8
 980      */
 981     public static float min(float a, float b) {
 982         return Math.min(a, b);

























 983     }
 984 
 985     /** use serialVersionUID from JDK 1.0.2 for interoperability */
 986     private static final long serialVersionUID = -2671257302660747028L;
 987 }


   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang;
  27 
  28 import java.lang.invoke.MethodHandles;
  29 import java.lang.constant.Constable;
  30 import java.lang.constant.ConstantDesc;
  31 import java.util.Optional;
  32 
  33 import jdk.internal.math.FloatingDecimal;
  34 import jdk.internal.HotSpotIntrinsicCandidate;
  35 
  36 /**
  37  * The {@code Float} class wraps a value of primitive type
  38  * {@code float} in an object. An object of type
  39  * {@code Float} contains a single field whose type is
  40  * {@code float}.
  41  *
  42  * <p>In addition, this class provides several methods for converting a
  43  * {@code float} to a {@code String} and a
  44  * {@code String} to a {@code float}, as well as other
  45  * constants and methods useful when dealing with a
  46  * {@code float}.
  47  *
  48  * @author  Lee Boynton
  49  * @author  Arthur van Hoff
  50  * @author  Joseph D. Darcy
  51  * @since 1.0
  52  */
  53 public final class Float extends Number
  54         implements Comparable<Float>, ConstantDesc, Constable {
  55     /**
  56      * A constant holding the positive infinity of type
  57      * {@code float}. It is equal to the value returned by
  58      * {@code Float.intBitsToFloat(0x7f800000)}.
  59      */
  60     public static final float POSITIVE_INFINITY = 1.0f / 0.0f;
  61 
  62     /**
  63      * A constant holding the negative infinity of type
  64      * {@code float}. It is equal to the value returned by
  65      * {@code Float.intBitsToFloat(0xff800000)}.
  66      */
  67     public static final float NEGATIVE_INFINITY = -1.0f / 0.0f;
  68 
  69     /**
  70      * A constant holding a Not-a-Number (NaN) value of type
  71      * {@code float}.  It is equivalent to the value returned by
  72      * {@code Float.intBitsToFloat(0x7fc00000)}.
  73      */
  74     public static final float NaN = 0.0f / 0.0f;


 969      * @return the greater of {@code a} and {@code b}
 970      * @see java.util.function.BinaryOperator
 971      * @since 1.8
 972      */
 973     public static float max(float a, float b) {
 974         return Math.max(a, b);
 975     }
 976 
 977     /**
 978      * Returns the smaller of two {@code float} values
 979      * as if by calling {@link Math#min(float, float) Math.min}.
 980      *
 981      * @param a the first operand
 982      * @param b the second operand
 983      * @return the smaller of {@code a} and {@code b}
 984      * @see java.util.function.BinaryOperator
 985      * @since 1.8
 986      */
 987     public static float min(float a, float b) {
 988         return Math.min(a, b);
 989     }
 990 
 991     /**
 992      * Returns a nominal descriptor for this instance, which is the instance
 993      * itself.
 994      *
 995      * @return an {@link Optional} describing the {@linkplain Float} instance
 996      * @since 12
 997      */
 998     @Override
 999     public Optional<Float> describeConstable() {
1000         return Optional.of(this);
1001     }
1002 
1003     /**
1004      * Resolves this instance as a {@link ConstantDesc}, the result of which is
1005      * the instance itself.
1006      *
1007      * @param lookup ignored
1008      * @return the {@linkplain Float} instance
1009      * @since 12
1010      */
1011     @Override
1012     public Float resolveConstantDesc(MethodHandles.Lookup lookup) {
1013         return this;
1014     }
1015 
1016     /** use serialVersionUID from JDK 1.0.2 for interoperability */
1017     private static final long serialVersionUID = -2671257302660747028L;
1018 }
< prev index next >