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

Print this page
rev 4568 : 7088952: Add "BYTES" constant to primitive wrapper classes
7088913: Add compatible static hashCode(primitive) to primitive wrapper classes
Reviewed-by: smarks


 104      */
 105     public static final int MAX_EXPONENT = 127;
 106 
 107     /**
 108      * Minimum exponent a normalized {@code float} variable may have.
 109      * It is equal to the value returned by {@code
 110      * Math.getExponent(Float.MIN_NORMAL)}.
 111      *
 112      * @since 1.6
 113      */
 114     public static final int MIN_EXPONENT = -126;
 115 
 116     /**
 117      * The number of bits used to represent a {@code float} value.
 118      *
 119      * @since 1.5
 120      */
 121     public static final int SIZE = 32;
 122 
 123     /**







 124      * The {@code Class} instance representing the primitive type
 125      * {@code float}.
 126      *
 127      * @since JDK1.1
 128      */
 129     public static final Class<Float> TYPE = Class.getPrimitiveClass("float");
 130 
 131     /**
 132      * Returns a string representation of the {@code float}
 133      * argument. All characters mentioned below are ASCII characters.
 134      * <ul>
 135      * <li>If the argument is NaN, the result is the string
 136      * "{@code NaN}".
 137      * <li>Otherwise, the result is a string that represents the sign and
 138      *     magnitude (absolute value) of the argument. If the sign is
 139      *     negative, the first character of the result is
 140      *     '{@code -}' (<code>'&#92;u002D'</code>); if the sign is
 141      *     positive, no sign character appears in the result. As for
 142      *     the magnitude <i>m</i>:
 143      * <ul>


 617      * after a widening primitive conversion.
 618      *
 619      * @return the {@code float} value represented by this
 620      *         object converted to type {@code double}
 621      * @jls 5.1.2 Widening Primitive Conversions
 622      */
 623     public double doubleValue() {
 624         return (double)value;
 625     }
 626 
 627     /**
 628      * Returns a hash code for this {@code Float} object. The
 629      * result is the integer bit representation, exactly as produced
 630      * by the method {@link #floatToIntBits(float)}, of the primitive
 631      * {@code float} value represented by this {@code Float}
 632      * object.
 633      *
 634      * @return a hash code value for this object.
 635      */
 636     public int hashCode() {












 637         return floatToIntBits(value);
 638     }
 639 
 640     /**
 641 
 642      * Compares this object against the specified object.  The result
 643      * is {@code true} if and only if the argument is not
 644      * {@code null} and is a {@code Float} object that
 645      * represents a {@code float} with the same value as the
 646      * {@code float} represented by this object. For this
 647      * purpose, two {@code float} values are considered to be the
 648      * same if and only if the method {@link #floatToIntBits(float)}
 649      * returns the identical {@code int} value when applied to
 650      * each.
 651      *
 652      * <p>Note that in most cases, for two instances of class
 653      * {@code Float}, {@code f1} and {@code f2}, the value
 654      * of {@code f1.equals(f2)} is {@code true} if and only if
 655      *
 656      * <blockquote><pre>




 104      */
 105     public static final int MAX_EXPONENT = 127;
 106 
 107     /**
 108      * Minimum exponent a normalized {@code float} variable may have.
 109      * It is equal to the value returned by {@code
 110      * Math.getExponent(Float.MIN_NORMAL)}.
 111      *
 112      * @since 1.6
 113      */
 114     public static final int MIN_EXPONENT = -126;
 115 
 116     /**
 117      * The number of bits used to represent a {@code float} value.
 118      *
 119      * @since 1.5
 120      */
 121     public static final int SIZE = 32;
 122 
 123     /**
 124      * The number of bytes used to represent a {@code float} value.
 125      *
 126      * @since 1.8
 127      */
 128     public static final int BYTES = SIZE / Byte.SIZE;
 129 
 130     /**
 131      * The {@code Class} instance representing the primitive type
 132      * {@code float}.
 133      *
 134      * @since JDK1.1
 135      */
 136     public static final Class<Float> TYPE = Class.getPrimitiveClass("float");
 137 
 138     /**
 139      * Returns a string representation of the {@code float}
 140      * argument. All characters mentioned below are ASCII characters.
 141      * <ul>
 142      * <li>If the argument is NaN, the result is the string
 143      * "{@code NaN}".
 144      * <li>Otherwise, the result is a string that represents the sign and
 145      *     magnitude (absolute value) of the argument. If the sign is
 146      *     negative, the first character of the result is
 147      *     '{@code -}' (<code>'&#92;u002D'</code>); if the sign is
 148      *     positive, no sign character appears in the result. As for
 149      *     the magnitude <i>m</i>:
 150      * <ul>


 624      * after a widening primitive conversion.
 625      *
 626      * @return the {@code float} value represented by this
 627      *         object converted to type {@code double}
 628      * @jls 5.1.2 Widening Primitive Conversions
 629      */
 630     public double doubleValue() {
 631         return (double)value;
 632     }
 633 
 634     /**
 635      * Returns a hash code for this {@code Float} object. The
 636      * result is the integer bit representation, exactly as produced
 637      * by the method {@link #floatToIntBits(float)}, of the primitive
 638      * {@code float} value represented by this {@code Float}
 639      * object.
 640      *
 641      * @return a hash code value for this object.
 642      */
 643     public int hashCode() {
 644         return floatToIntBits(value);
 645     }
 646 
 647     /**
 648      * Returns a hash code for a {@code float} value; compatible with
 649      * {@code Float.hashCode()}.
 650      *
 651      * @since 1.8
 652      *
 653      * @return a hash code value for a {@code float} value.
 654      */
 655     public static int hashCode(float value) {
 656         return floatToIntBits(value);
 657     }
 658 
 659     /**
 660 
 661      * Compares this object against the specified object.  The result
 662      * is {@code true} if and only if the argument is not
 663      * {@code null} and is a {@code Float} object that
 664      * represents a {@code float} with the same value as the
 665      * {@code float} represented by this object. For this
 666      * purpose, two {@code float} values are considered to be the
 667      * same if and only if the method {@link #floatToIntBits(float)}
 668      * returns the identical {@code int} value when applied to
 669      * each.
 670      *
 671      * <p>Note that in most cases, for two instances of class
 672      * {@code Float}, {@code f1} and {@code f2}, the value
 673      * of {@code f1.equals(f2)} is {@code true} if and only if
 674      *
 675      * <blockquote><pre>