public final class Float extends Number implements Comparable<Float>
float
.Number
,
Serialized FormModifier and Type | Field and Description |
---|---|
static int |
MAX_EXPONENT
Maximum base-2 exponent that a finite value of the
float type may have. |
static float |
MAX_VALUE
Constant for the maximum
float value, (2 - 2-23) * 2127. |
static int |
MIN_EXPONENT
Minimum base-2 exponent that a normal value of the
float type may have. |
static float |
MIN_NORMAL
Constant for the smallest positive normal value of the
float type. |
static float |
MIN_VALUE
Constant for the minimum
float value, 2-149. |
static float |
NaN
Constant for the Not-a-Number (NaN) value of the
float type. |
static float |
NEGATIVE_INFINITY
Constant for the negative infinity value of the
float type. |
static float |
POSITIVE_INFINITY
Constant for the positive infinity value of the
float type. |
static int |
SIZE
Constant for the number of bits needed to represent a
float in
two's complement form. |
static Class<Float> |
TYPE
The
Class object that represents the primitive type float . |
Constructor and Description |
---|
Float(double value)
Constructs a new
Float with the specified primitive double value. |
Float(float value)
Constructs a new
Float with the specified primitive float value. |
Float(String string)
Constructs a new
Float from the specified string. |
Modifier and Type | Method and Description |
---|---|
byte |
byteValue()
Returns this object's value as a byte.
|
static int |
compare(float float1,
float float2)
Compares the two specified float values.
|
int |
compareTo(Float object)
Compares this object to the specified float object to determine their
relative order.
|
double |
doubleValue()
Returns this object's value as a double.
|
boolean |
equals(Object object)
Tests this double for equality with
object . |
static int |
floatToIntBits(float value)
Returns an integer corresponding to the bits of the given
IEEE 754 single precision
float
value . |
static int |
floatToRawIntBits(float value)
Returns an integer corresponding to the bits of the given
IEEE 754 single precision
float
value . |
float |
floatValue()
Gets the primitive value of this float.
|
int |
hashCode()
Returns an integer hash code for this object.
|
static float |
intBitsToFloat(int bits)
Returns the IEEE 754
single precision float corresponding to the given
bits . |
int |
intValue()
Returns this object's value as an int.
|
boolean |
isInfinite()
Indicates whether this object represents an infinite value.
|
static boolean |
isInfinite(float f)
Indicates whether the specified float represents an infinite value.
|
boolean |
isNaN()
Indicates whether this object is a Not-a-Number (NaN) value.
|
static boolean |
isNaN(float f)
Indicates whether the specified float is a Not-a-Number (NaN)
value.
|
long |
longValue()
Returns this object's value as a long.
|
static float |
parseFloat(String string)
Parses the specified string as a float value.
|
short |
shortValue()
Returns this object's value as a short.
|
static String |
toHexString(float f)
Converts the specified float into its hexadecimal string representation.
|
String |
toString()
Returns a string containing a concise, human-readable description of this
object.
|
static String |
toString(float f)
Returns a string containing a concise, human-readable description of the
specified float value.
|
static Float |
valueOf(float f)
Returns a
Float instance for the specified float value. |
static Float |
valueOf(String string)
Parses the specified string as a float value.
|
public static final float MAX_VALUE
float
value, (2 - 2-23) * 2127.public static final float MIN_VALUE
float
value, 2-149.public static final float NaN
float
type.public static final float POSITIVE_INFINITY
float
type.public static final float NEGATIVE_INFINITY
float
type.public static final float MIN_NORMAL
float
type.public static final int MAX_EXPONENT
float
type may have.
Equal to Math.getExponent(Float.MAX_VALUE)
.public static final int MIN_EXPONENT
float
type may have.
Equal to Math.getExponent(Float.MIN_NORMAL)
.public static final Class<Float> TYPE
Class
object that represents the primitive type float
.public static final int SIZE
float
in
two's complement form.public Float(float value)
Float
with the specified primitive float value.value
- the primitive float value to store in the new instance.public Float(double value)
Float
with the specified primitive double value.value
- the primitive double value to store in the new instance.public Float(String string) throws NumberFormatException
Float
from the specified string.string
- the string representation of a float value.NumberFormatException
- if string
can not be parsed as a float value.parseFloat(String)
public int compareTo(Float object)
Float.NaN
is equal to Float.NaN
and it is greater
than any other float value, including Float.POSITIVE_INFINITY
;compareTo
in interface Comparable<Float>
object
- the float object to compare this object to.object
; 0 if the value of this float and the
value of object
are equal; a positive value if the value
of this float is greater than the value of object
.Comparable
public byte byteValue()
Number
public double doubleValue()
Number
doubleValue
in class Number
public boolean equals(Object object)
object
.
To be equal, object
must be an instance of Float
and
floatToIntBits
must give the same value for both objects.
Note that, unlike ==
, -0.0
and +0.0
compare
unequal, and NaN
s compare equal by this method.
equals
in class Object
object
- the object to compare this float with.true
if the specified object is equal to this
Float
; false
otherwise.Object.hashCode()
public static int floatToIntBits(float value)
value
. All Not-a-Number (NaN) values are converted to a single NaN
representation (0x7fc00000
) (compare to floatToRawIntBits(float)
).public static int floatToRawIntBits(float value)
value
. Not-a-Number (NaN) values are preserved (compare
to floatToIntBits(float)
).public float floatValue()
floatValue
in class Number
public int hashCode()
Object
Object.equals(java.lang.Object)
returns true
must return
the same hash code value. This means that subclasses of Object
usually override both methods or neither method.
Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct
hashCode
method
if you intend implementing your own hashCode
method.
hashCode
in class Object
Object.equals(java.lang.Object)
public static float intBitsToFloat(int bits)
bits
.public int intValue()
Number
public boolean isInfinite()
true
if the value of this float is positive or negative
infinity; false
otherwise.public static boolean isInfinite(float f)
f
- the float to check.true
if the value of f
is positive or negative
infinity; false
otherwise.public boolean isNaN()
true
if this float is Not-a-Number;
false
if it is a (potentially infinite) float number.public static boolean isNaN(float f)
f
- the float value to check.true
if f
is Not-a-Number;
false
if it is a (potentially infinite) float number.public long longValue()
Number
public static float parseFloat(String string) throws NumberFormatException
string
- the string representation of a float value.string
.NumberFormatException
- if string
can not be parsed as a float value.valueOf(String)
public short shortValue()
Number
shortValue
in class Number
public String toString()
Object
getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toString
method
if you intend implementing your own toString
method.
public static String toString(float f)
f
- the float to convert to a string.f
.public static Float valueOf(String string) throws NumberFormatException
string
- the string representation of a float value.Float
instance containing the float value represented
by string
.NumberFormatException
- if string
can not be parsed as a float value.parseFloat(String)
public static int compare(float float1, float float2)
Float.NaN
is equal to Float.NaN
and it is greater
than any other float value, including Float.POSITIVE_INFINITY
;float1
- the first value to compare.float2
- the second value to compare.float1
is less than float2
;
0 if float1
and float2
are equal; a positive
value if float1
is greater than float2
.public static Float valueOf(float f)
Float
instance for the specified float value.f
- the float value to store in the instance.Float
instance containing f
.public static String toHexString(float f)
f
- the float to convert.f
.