Float
class wraps a value of primitive type
float
in an object. An object of type
Float
contains a single field whose type is
float
.
In addition, this class provides several methods for converting a
float
to a String
and a
String
to a float
, as well as other
constants and methods useful when dealing with a
float
.
This is a value-based class; programmers should treat instances that are equal as interchangeable and should not use instances for synchronization, or unpredictable behavior may occur. For example, in a future release, synchronization may fail.
java.lang.Double
has a discussion of equality,
equivalence, and comparison of floating-point values that is
equally applicable to float
values.
java.lang.Double
is also
applicable to float
values.
Modifier and Type | Field and Description |
---|---|
public static final int | BYTES
The number of bytes used to represent a |
public static final int | MAX_EXPONENT
Maximum exponent a finite |
public static final float | MAX_VALUE
A constant holding the largest positive finite value of type
|
public static final int | MIN_EXPONENT
Minimum exponent a normalized |
public static final float | MIN_NORMAL
A constant holding the smallest positive normal value of type
|
public static final float | MIN_VALUE
A constant holding the smallest positive nonzero value of type
|
public static final float | NaN
A constant holding a Not-a-Number (NaN) value of type
|
public static final float | NEGATIVE_INFINITY
A constant holding the negative infinity of type
|
public static final float | POSITIVE_INFINITY
A constant holding the positive infinity of type
|
public static final int | PRECISION
The number of bits in the significand of a |
private static final long | serialVersionUID
use serialVersionUID from JDK 1.0.2 for interoperability
|
public static final int | SIZE
The number of bits used to represent a |
public static final Class | TYPE
The |
private final float | value
The value of the Float. |
Access | Constructor and Description |
---|---|
public | Float(float
the value to be represented by the value)Float .
Deprecated
for removal since 9. It is rarely appropriate to use this constructor.
Constructs a newly allocated |
public | Float(double
the value to be represented by the value)Float .
Deprecated
for removal since 9. It is rarely appropriate to use this constructor.
Constructs a newly allocated |
public |
Modifier and Type | Method and Description |
---|---|
public byte | Returns: thefloat value represented by this object
converted to type byte Overrides java. Returns the value of this |
public static int | Returns: the value0 if f1 is
numerically equal to f2 ; a value less than
0 if f1 is numerically less than
f2 ; and a value greater than 0
if f1 is numerically greater than
f2 .the first f1, float float to compare.the second f2)float to compare.Compares the two specified |
public int | Returns: the value0 if anotherFloat is
numerically equal to this Float ; a value
less than 0 if this Float
is numerically less than anotherFloat ;
and a value greater than 0 if this
Float is numerically greater than
anotherFloat .the anotherFloat)Float to be compared.Implements java. Compares two |
public Optional | describeConstable()
Implements java. Returns an |
public double | Returns: thefloat value represented by this
object converted to type double Implements abstract java. Returns the value of this |
public boolean | Returns: true if the objects are the same;
false otherwise.the object to be compared obj)Overrides java. Compares this object against the specified object. |
public static float | Returns: thefloat value closest to the numerical value
of the argument, a floating-point binary16 value encoded in a
short the binary16 value to convert to floatBinary16)float Returns the |
public static short | Returns: the floating-point binary16 value, encoded in ashort , closest in value to the argumentthe f)float value to convert to binary16Returns the floating-point binary16 value, encoded in a |
public static int | Returns: the bits that represent the floating-point number.a floating-point number. value)Returns a representation of the specified floating-point value according to the IEEE 754 floating-point "single format" bit layout. |
public static native int | Returns: the bits that represent the floating-point number.a floating-point number. value)Returns a representation of the specified floating-point value according to the IEEE 754 floating-point "single format" bit layout, preserving Not-a-Number (NaN) values. |
public float | Returns: thefloat value represented by this objectImplements abstract java. Returns the |
public int | Returns: a hash code value for this object.Overrides java. Returns a hash code for this |
public static int | Returns: a hash code value for afloat value.the value to hash value)Returns a hash code for a |
public static native float | Returns: thefloat floating-point value with the same bit
pattern.an integer. bits)Returns the |
public int | Returns: thefloat value represented by this object
converted to type int Implements abstract java. Returns the value of this |
public static boolean | Returns: true if the argument is a finite
floating-point value, false otherwise.the f)float value to be testedReturns |
public static boolean | Returns: true if the argument is positive infinity or
negative infinity; false otherwise.the value to be tested. v)Returns |
public boolean | Returns: true if the value represented by this object is
positive infinity or negative infinity;
false otherwise.Returns |
public static boolean | Returns: true if the argument is NaN;
false otherwise.the value to be tested. v)Returns |
public boolean | Returns: true if the value represented by this object is
NaN; false otherwise.Returns |
public long | Returns: thefloat value represented by this object
converted to type long Implements abstract java. Returns value of this |
public static float | |
public static float | |
public static float | Returns: thefloat value represented by the string
argument.the string to be parsed. s)Returns a new |
public Float | Returns: the Float instanceignored lookupImplements java. Resolves this instance as a |
public short | Returns: thefloat value represented by this object
converted to type short Overrides java. Returns the value of this |
public static float | Returns: the sum ofa and b the first operand a, float the second operand b)Adds two |
public static String | Returns: a hex string representation of the argument.the f)float to be converted.Returns a hexadecimal string representation of the
|
public static String | Returns: a string representation of the argument.the f)float to be converted.Returns a string representation of the |
public String | Returns: aString representation of this object.Overrides java. Returns a string representation of this |
public static Float | |
public static Float | Returns: aFloat instance representing f .a float value. f)Returns a |
BYTES | back to summary |
---|---|
public static final int BYTES The number of bytes used to represent a
|
MAX_EXPONENT | back to summary |
---|---|
public static final int MAX_EXPONENT Maximum exponent a finite
|
MAX_VALUE | back to summary |
---|---|
public static final float MAX_VALUE A constant holding the largest positive finite value of type
|
MIN_EXPONENT | back to summary |
---|---|
public static final int MIN_EXPONENT Minimum exponent a normalized
|
MIN_NORMAL | back to summary |
---|---|
public static final float MIN_NORMAL A constant holding the smallest positive normal value of type
|
MIN_VALUE | back to summary |
---|---|
public static final float MIN_VALUE A constant holding the smallest positive nonzero value of type
|
NaN | back to summary |
---|---|
public static final float NaN A constant holding a Not-a-Number (NaN) value of type
|
NEGATIVE_INFINITY | back to summary |
---|---|
public static final float NEGATIVE_INFINITY A constant holding the negative infinity of type
|
POSITIVE_INFINITY | back to summary |
---|---|
public static final float POSITIVE_INFINITY A constant holding the positive infinity of type
|
PRECISION | back to summary |
---|---|
public static final int PRECISION The number of bits in the significand of a
|
serialVersionUID | back to summary |
---|---|
private static final long serialVersionUID Hides java. use serialVersionUID from JDK 1.0.2 for interoperability |
SIZE | back to summary |
---|---|
public static final int SIZE The number of bits used to represent a
|
TYPE | back to summary |
---|---|
public static final Class<Float> TYPE The
|
value | back to summary |
---|---|
private final float value The value of the Float. |
Float | back to summary |
---|---|
public Float(float value)
Deprecated for removal since 9. It is rarely appropriate to use this constructor. The static factory
Constructs a newly allocated
|
Float | back to summary |
---|---|
public Float(double value)
Deprecated for removal since 9. It is rarely appropriate to use this constructor. Instead, use the
static factory method Constructs a newly allocated
|
Float | back to summary |
---|---|
public Float(String s) throws NumberFormatException
Deprecated for removal since 9. It is rarely appropriate to use this constructor.
Use Constructs a newly allocated
|
byteValue | back to summary |
---|---|
public byte byteValue() Overrides java. Returns the value of this
|
compare | back to summary |
---|---|
public static int compare(float f1, float f2) Compares the two specified Float.valueOf(f1).compareTo(Float.valueOf(f2))
|
compareTo | back to summary |
---|---|
public int compareTo(Float anotherFloat) Implements java. Compares two
Float
objects imposed by this method is consistent with
equals; see this
discussion for details of floating-point comparison and
ordering.
|
describeConstable | back to summary |
---|---|
public Optional Implements java. Returns an |
doubleValue | back to summary |
---|---|
public double doubleValue() Implements abstract java. Returns the value of this API Note This method corresponds to the convertFormat operation defined in IEEE 754.
|
equals | back to summary |
---|---|
public boolean equals(Object obj) Overrides java. Compares this object against the specified object. The result
is API Note This method is defined in terms of
|
float16ToFloat | back to summary |
---|---|
public static float float16ToFloat(short floatBinary16) Returns the
IEEE 754 binary16 formatThe IEEE 754 standard defines binary16 as a 16-bit format, along with the 32-bit binary32 format (corresponding to thefloat type) and the 64-bit binary64 format (corresponding to
the double type). The binary16 format is similar to the
other IEEE 754 formats, except smaller, having all the usual
IEEE 754 values such as NaN, signed infinities, signed zeros,
and subnormals. The parameters (JLS 4.2.3) for the
binary16 format are N = 11 precision bits, K = 5 exponent bits,
Emax = 15, and
Emin = -14.
API Note This method corresponds to the convertFormat operation defined in IEEE 754 from the binary16 format to the binary32 format. The operation of this method is analogous to a primitive widening conversion (JLS 5.1.2).
|
floatToFloat16 | back to summary |
---|---|
public static short floatToFloat16(float f) Returns the floating-point binary16 value, encoded in a
float16ToFloat method.
API Note This method corresponds to the convertFormat operation defined in IEEE 754 from the binary32 format to the binary16 format. The operation of this method is analogous to a primitive narrowing conversion (JLS 5.1.3).
|
floatToIntBits | back to summary |
---|---|
public static int floatToIntBits(float value) Returns a representation of the specified floating-point value according to the IEEE 754 floating-point "single format" bit layout. Bit 31 (the bit that is selected by the mask
If the argument is positive infinity, the result is
If the argument is negative infinity, the result is
If the argument is NaN, the result is In all cases, the result is an integer that, when given to the
|
floatToRawIntBits | back to summary |
---|---|
public static native int floatToRawIntBits(float value) Returns a representation of the specified floating-point value according to the IEEE 754 floating-point "single format" bit layout, preserving Not-a-Number (NaN) values. Bit 31 (the bit that is selected by the mask
If the argument is positive infinity, the result is
If the argument is negative infinity, the result is
If the argument is NaN, the result is the integer representing
the actual NaN value. Unlike the In all cases, the result is an integer that, when given to the
|
floatValue | back to summary |
---|---|
public float floatValue() Implements abstract java. Returns the
|
hashCode | back to summary |
---|---|
public int hashCode() Overrides java. Returns a hash code for this
|
hashCode | back to summary |
---|---|
public static int hashCode(float value) Returns a hash code for a
|
intBitsToFloat | back to summary |
---|---|
public static native float intBitsToFloat(int bits) Returns the If the argument is If the argument is If the argument is any value in the range
In all other cases, let s, e, and m be three values that can be computed from the argument: 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
|
intValue | back to summary |
---|---|
public int intValue() Implements abstract java. Returns the value of this
|
isFinite | back to summary |
---|---|
public static boolean isFinite(float f) Returns API Note This method corresponds to the isFinite operation defined in IEEE 754.
|
isInfinite | back to summary |
---|---|
public static boolean isInfinite(float v) Returns API Note This method corresponds to the isInfinite operation defined in IEEE 754.
|
isInfinite | back to summary |
---|---|
public boolean isInfinite() Returns
|
isNaN | back to summary |
---|---|
public static boolean isNaN(float v) Returns API Note This method corresponds to the isNaN operation defined in IEEE 754.
|
isNaN | back to summary |
---|---|
public boolean isNaN() Returns
|
longValue | back to summary |
---|---|
public long longValue() Implements abstract java. Returns value of this
|
max | back to summary |
---|---|
public static float max(float a, float b) Returns the greater of two API Note This method corresponds to the maximum operation defined in IEEE 754.
|
min | back to summary |
---|---|
public static float min(float a, float b) Returns the smaller of two API Note This method corresponds to the minimum operation defined in IEEE 754.
|
parseFloat | back to summary |
---|---|
public static float parseFloat(String s) throws NumberFormatException Returns a new
|
resolveConstantDesc | back to summary |
---|---|
public Float resolveConstantDesc(MethodHandles. Implements java. Resolves this instance as a
|
shortValue | back to summary |
---|---|
public short shortValue() Overrides java. Returns the value of this
|
sum | back to summary |
---|---|
public static float sum(float a, float b) Adds two API Note This method corresponds to the addition operation defined in IEEE 754.
|
toHexString | back to summary | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
public static String toHexString(float f) Returns a hexadecimal string representation of the
|
toString | back to summary |
---|---|
public static String toString(float f) Returns a string representation of the
A decimal is a number of the form s×10i for some (unique) integers s > 0 and i such that s is not a multiple of 10. These integers are the significand and the exponent, respectively, of the decimal. The length of the decimal is the (unique) positive integer n meeting 10n-1 ≤ s < 10n. The decimal dm for a finite positive m is defined as follows:
The (uniquely) selected decimal dm
is then formatted.
Let s, i and n be the significand, exponent and
length of dm, respectively.
Further, let e = n + i - 1 and let
s1…sn
be the usual decimal expansion of s.
Note that s1 ≠ 0
and sn ≠ 0.
Below, the decimal point
To create localized string representations of a floating-point
value, use subclasses of
|
toString | back to summary |
---|---|
public String toString() Overrides java. Returns a string representation of this
|
valueOf | back to summary |
---|---|
public static Float valueOf(String s) throws NumberFormatException Returns a If Leading and trailing whitespace characters in 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 s does not have the form of
a FloatValue, then a NumberFormatException
is thrown. Otherwise, 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 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 s is large
enough in magnitude (greater than or equal to (MAX_VALUE + ulp(MAX_VALUE) /2),
rounding to float will result in an infinity and if the
exact value of 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 Float object representing
this float value is returned.
Note that trailing format specifiers, specifiers that
determine the type of a floating-point literal
( To avoid calling this method on an invalid string and having
a API Note To interpret localized string representations of a
floating-point value, or string representations that have
non-ASCII digits, use NumberFormat.getInstance(l).parse(s).floatValue(); l is the desired locale, or
java. if locale insensitive.
|
valueOf | back to summary |
---|---|
public static Float valueOf(float f) Returns a
|