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

Print this page




   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;


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






 979     }
 980 
 981     /** use serialVersionUID from JDK 1.0.2 for interoperability */
 982     private static final long serialVersionUID = -2671257302660747028L;
 983 }


   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.Constable;
  29 import java.lang.invoke.MethodHandles;
  30 
  31 import jdk.internal.math.FloatingDecimal;
  32 import jdk.internal.HotSpotIntrinsicCandidate;
  33 
  34 /**
  35  * The {@code Float} class wraps a value of primitive type
  36  * {@code float} in an object. An object of type
  37  * {@code Float} contains a single field whose type is
  38  * {@code float}.
  39  *
  40  * <p>In addition, this class provides several methods for converting a
  41  * {@code float} to a {@code String} and a
  42  * {@code String} to a {@code float}, as well as other
  43  * constants and methods useful when dealing with a
  44  * {@code float}.
  45  *
  46  * @author  Lee Boynton
  47  * @author  Arthur van Hoff
  48  * @author  Joseph D. Darcy
  49  * @since 1.0
  50  */
  51 public final class Float extends Number implements Comparable<Float>, Constable<Float> {
  52     /**
  53      * A constant holding the positive infinity of type
  54      * {@code float}. It is equal to the value returned by
  55      * {@code Float.intBitsToFloat(0x7f800000)}.
  56      */
  57     public static final float POSITIVE_INFINITY = 1.0f / 0.0f;
  58 
  59     /**
  60      * A constant holding the negative infinity of type
  61      * {@code float}. It is equal to the value returned by
  62      * {@code Float.intBitsToFloat(0xff800000)}.
  63      */
  64     public static final float NEGATIVE_INFINITY = -1.0f / 0.0f;
  65 
  66     /**
  67      * A constant holding a Not-a-Number (NaN) value of type
  68      * {@code float}.  It is equivalent to the value returned by
  69      * {@code Float.intBitsToFloat(0x7fc00000)}.
  70      */
  71     public static final float NaN = 0.0f / 0.0f;


 962      * @return the greater of {@code a} and {@code b}
 963      * @see java.util.function.BinaryOperator
 964      * @since 1.8
 965      */
 966     public static float max(float a, float b) {
 967         return Math.max(a, b);
 968     }
 969 
 970     /**
 971      * Returns the smaller of two {@code float} values
 972      * as if by calling {@link Math#min(float, float) Math.min}.
 973      *
 974      * @param a the first operand
 975      * @param b the second operand
 976      * @return the smaller of {@code a} and {@code b}
 977      * @see java.util.function.BinaryOperator
 978      * @since 1.8
 979      */
 980     public static float min(float a, float b) {
 981         return Math.min(a, b);
 982     }
 983 
 984 
 985     @Override
 986     public Float resolveConstant(MethodHandles.Lookup lookup) {
 987         return this;
 988     }
 989 
 990     /** use serialVersionUID from JDK 1.0.2 for interoperability */
 991     private static final long serialVersionUID = -2671257302660747028L;
 992 }