java.lang.Objectjava.lang.Number
java.lang.Float
All Implemented Interfaces:
Comparable, Serializable
In addition, this class provides several methods for converting a {@code float} to a {@code String} and a {@code String} to a {@code float}, as well as other constants and methods useful when dealing with a {@code float}.
Lee
- BoyntonArthur
- van HoffJoseph
- D. DarcyJDK1.0
- Field Summary | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
public static final float | POSITIVE_INFINITY | A constant holding the positive infinity of type {@code float}. It is equal to the value returned by {@code Float.intBitsToFloat(0x7f800000)}. | ||||||||||||||||||||
public static final float | NEGATIVE_INFINITY | A constant holding the negative infinity of type {@code float}. It is equal to the value returned by {@code Float.intBitsToFloat(0xff800000)}. | ||||||||||||||||||||
public static final float | NaN | A constant holding a Not-a-Number (NaN) value of type {@code float}. It is equivalent to the value returned by {@code Float.intBitsToFloat(0x7fc00000)}. | ||||||||||||||||||||
public static final float | MAX_VALUE | A constant holding the largest positive finite value of type {@code float}, (2-2-23)·2127. It is equal to the hexadecimal floating-point literal {@code 0x1.fffffeP+127f} and also equal to {@code Float.intBitsToFloat(0x7f7fffff)}. | ||||||||||||||||||||
public static final float | MIN_NORMAL | A constant holding the smallest positive normal value of type
{@code float}, 2-126. It is equal to the
hexadecimal floating-point literal {@code 0x1.0p-126f} and also
equal to {@code Float.intBitsToFloat(0x00800000)}.
| ||||||||||||||||||||
public static final float | MIN_VALUE | A constant holding the smallest positive nonzero value of type {@code float}, 2-149. It is equal to the hexadecimal floating-point literal {@code 0x0.000002P-126f} and also equal to {@code Float.intBitsToFloat(0x1)}. | ||||||||||||||||||||
public static final int | MAX_EXPONENT | Maximum exponent a finite {@code float} variable may have. It
is equal to the value returned by {@code
Math.getExponent(Float.MAX_VALUE)}.
| ||||||||||||||||||||
public static final int | MIN_EXPONENT | Minimum exponent a normalized {@code float} variable may have.
It is equal to the value returned by {@code
Math.getExponent(Float.MIN_NORMAL)}.
| ||||||||||||||||||||
public static final int | SIZE | The number of bits used to represent a {@code float} value.
| ||||||||||||||||||||
public static final Class<Float> | TYPE | The {@code Class} instance representing the primitive type
{@code float}.
|
Constructor: |
---|
|
|
|
Method from java.lang.Float Summary: |
---|
byteValue, compare, compareTo, doubleValue, equals, floatToIntBits, floatToRawIntBits, floatValue, hashCode, intBitsToFloat, intValue, isInfinite, isInfinite, isNaN, isNaN, longValue, parseFloat, shortValue, toHexString, toString, toString, valueOf, valueOf |
Methods from java.lang.Number: |
---|
byteValue, doubleValue, floatValue, intValue, longValue, shortValue |
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from java.lang.Float Detail: | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||
new Float(f1).compareTo(new Float(f2)) | ||||||||||||||||||||||
| ||||||||||||||||||||||
| ||||||||||||||||||||||
Note that in most cases, for two instances of class {@code Float}, {@code f1} and {@code f2}, the value of {@code f1.equals(f2)} is {@code true} if and only if f1.floatValue() == f2.floatValue() also has the value {@code true}. However, there are two exceptions: | ||||||||||||||||||||||
Bit 31 (the bit that is selected by the mask {@code 0x80000000}) represents the sign of the floating-point number. Bits 30-23 (the bits that are selected by the mask {@code 0x7f800000}) represent the exponent. Bits 22-0 (the bits that are selected by the mask {@code 0x007fffff}) represent the significand (sometimes called the mantissa) of the floating-point number. If the argument is positive infinity, the result is {@code 0x7f800000}. If the argument is negative infinity, the result is {@code 0xff800000}. If the argument is NaN, the result is {@code 0x7fc00000}. In all cases, the result is an integer that, when given to the #intBitsToFloat(int) method, will produce a floating-point value the same as the argument to {@code floatToIntBits} (except all NaN values are collapsed to a single "canonical" NaN value). | ||||||||||||||||||||||
Bit 31 (the bit that is selected by the mask {@code 0x80000000}) represents the sign of the floating-point number. Bits 30-23 (the bits that are selected by the mask {@code 0x7f800000}) represent the exponent. Bits 22-0 (the bits that are selected by the mask {@code 0x007fffff}) represent the significand (sometimes called the mantissa) of the floating-point number. If the argument is positive infinity, the result is {@code 0x7f800000}. If the argument is negative infinity, the result is {@code 0xff800000}. If the argument is NaN, the result is the integer representing the actual NaN value. Unlike the {@code floatToIntBits} method, {@code floatToRawIntBits} does not collapse all the bit patterns encoding a NaN to a single "canonical" NaN value. In all cases, the result is an integer that, when given to the #intBitsToFloat(int) method, will produce a floating-point value the same as the argument to {@code floatToRawIntBits}. | ||||||||||||||||||||||
| ||||||||||||||||||||||
| ||||||||||||||||||||||
If the argument is {@code 0x7f800000}, the result is positive infinity. If the argument is {@code 0xff800000}, the result is negative infinity. If the argument is any value in the range {@code 0x7f800001} through {@code 0x7fffffff} or in the range {@code 0xff800001} through {@code 0xffffffff}, the result is a NaN. No IEEE 754 floating-point operation provided by Java can distinguish between two NaN values of the same type with different bit patterns. Distinct values of NaN are only distinguishable by use of the {@code Float.floatToRawIntBits} method. In all other cases, let s, e, and m be three values that can be computed from the argument: Then the floating-point result equals the value of the mathematical expression s·m·2e-150.int s = ((bits >> 31) == 0) ? 1 : -1; int e = ((bits >> 23) & 0xff); int m = (e == 0) ? (bits & 0x7fffff) << 1 : (bits & 0x7fffff) | 0x800000; Note that this method may not be able to return a {@code float} NaN with exactly same bit pattern as the {@code int} argument. IEEE 754 distinguishes between two kinds of NaNs, quiet NaNs and signaling NaNs. The differences between the two kinds of NaN are generally not visible in Java. Arithmetic operations on signaling NaNs turn them into quiet NaNs with a different, but often similar, bit pattern. However, on some processors merely copying a signaling NaN also performs that conversion. In particular, copying a signaling NaN to return it to the calling method may perform this conversion. So {@code intBitsToFloat} may not be able to return a {@code float} with a signaling NaN bit pattern. Consequently, for some {@code int} values, {@code floatToRawIntBits(intBitsToFloat(start))} may not equal {@code start}. Moreover, which particular bit patterns represent signaling NaNs is platform dependent; although all NaN bit patterns, quiet or signaling, must be in the NaN range identified above. | ||||||||||||||||||||||
| ||||||||||||||||||||||
| ||||||||||||||||||||||
| ||||||||||||||||||||||
| ||||||||||||||||||||||
| ||||||||||||||||||||||
| ||||||||||||||||||||||
| ||||||||||||||||||||||
| ||||||||||||||||||||||
| ||||||||||||||||||||||
| ||||||||||||||||||||||
To create localized string representations of a floating-point value, use subclasses of java.text.NumberFormat . | ||||||||||||||||||||||
If {@code s} is {@code null}, then a {@code NullPointerException} is thrown. Leading and trailing whitespace characters in {@code s} are ignored. Whitespace is removed as if by the String#trim method; that is, both ASCII space and control characters are removed. The rest of {@code s} should constitute a FloatValue as described by the lexical syntax rules: where Sign, FloatingPointLiteral, HexNumeral, HexDigits, SignedInteger and FloatTypeSuffix are as defined in the lexical structure sections of The Java™ Language Specification, except that underscores are not accepted between digits. If {@code s} does not have the form of a FloatValue, then a {@code NumberFormatException} is thrown. Otherwise, {@code s} is regarded as representing an exact decimal value in the usual "computerized scientific notation" or as an exact hexadecimal value; this exact numerical value is then conceptually converted to an "infinitely precise" binary value that is then rounded to type {@code float} by the usual round-to-nearest rule of IEEE 754 floating-point arithmetic, which includes preserving the sign of a zero value. Note that the round-to-nearest rule also implies overflow and underflow behaviour; if the exact value of {@code s} is large enough in magnitude (greater than or equal to (#MAX_VALUE + ulp(MAX_VALUE) /2), rounding to {@code float} will result in an infinity and if the exact value of {@code s} is small enough in magnitude (less than or equal to #MIN_VALUE /2), rounding to float will result in a zero. Finally, after rounding a {@code Float} object representing this {@code float} value is returned. To interpret localized string representations of a floating-point value, use subclasses of java.text.NumberFormat . Note that trailing format specifiers, specifiers that
determine the type of a floating-point literal
({@code 1.0f} is a {@code float} value;
{@code 1.0d} is a {@code double} value), do
not influence the results of this method. In other
words, the numerical value of the input string is converted
directly to the target floating-point type. In general, the
two-step sequence of conversions, string to {@code double}
followed by {@code double} to {@code float}, is
not equivalent to converting a string directly to
{@code float}. For example, if first converted to an
intermediate {@code double} and then to
{@code float}, the string To avoid calling this method on an invalid string and having a {@code NumberFormatException} be thrown, the documentation for Double.valueOf lists a regular expression which can be used to screen the input. | ||||||||||||||||||||||
|