public final class Double extends Number implements Comparable<Double>
double
.Number
,
Serialized FormModifier and Type | Field and Description |
---|---|
static int |
MAX_EXPONENT
Maximum base-2 exponent that a finite value of the
double type may have. |
static double |
MAX_VALUE
Constant for the maximum
double value, (2 - 2-52) *
21023. |
static int |
MIN_EXPONENT
Minimum base-2 exponent that a normal value of the
double type may have. |
static double |
MIN_NORMAL
Constant for the smallest positive normal value of the
double type. |
static double |
MIN_VALUE
Constant for the minimum
double value, 2-1074. |
static double |
NaN
Constant for the Not-a-Number (NaN) value of the
double type. |
static double |
NEGATIVE_INFINITY
Constant for the negative infinity value of the
double type. |
static double |
POSITIVE_INFINITY
Constant for the positive infinity value of the
double type. |
static int |
SIZE
Constant for the number of bits needed to represent a
double in
two's complement form. |
static Class<Double> |
TYPE
The
Class object that represents the primitive type double . |
Constructor and Description |
---|
Double(double value)
Constructs a new
Double with the specified primitive double
value. |
Double(String string)
Constructs a new
Double from the specified string. |
Modifier and Type | Method and Description |
---|---|
byte |
byteValue()
Returns this object's value as a byte.
|
static int |
compare(double double1,
double double2)
Compares the two specified double values.
|
int |
compareTo(Double object)
Compares this object to the specified double object to determine their
relative order.
|
static long |
doubleToLongBits(double value)
Returns an integer corresponding to the bits of the given
IEEE 754 double precision
value . |
static long |
doubleToRawLongBits(double value)
Returns an integer corresponding to the bits of the given
IEEE 754 double precision
value . |
double |
doubleValue()
Gets the primitive value of this double.
|
boolean |
equals(Object object)
Tests this double for equality with
object . |
float |
floatValue()
Returns this object's value as a float.
|
int |
hashCode()
Returns an integer hash code for this object.
|
int |
intValue()
Returns this object's value as an int.
|
boolean |
isInfinite()
Indicates whether this object represents an infinite value.
|
static boolean |
isInfinite(double d)
Indicates whether the specified double represents an infinite value.
|
boolean |
isNaN()
Indicates whether this object is a Not-a-Number (NaN) value.
|
static boolean |
isNaN(double d)
Indicates whether the specified double is a Not-a-Number (NaN)
value.
|
static double |
longBitsToDouble(long bits)
Returns the IEEE 754
double precision float corresponding to the given
bits . |
long |
longValue()
Returns this object's value as a long.
|
static double |
parseDouble(String string)
Parses the specified string as a double value.
|
short |
shortValue()
Returns this object's value as a short.
|
static String |
toHexString(double d)
Converts the specified double into its hexadecimal string representation.
|
String |
toString()
Returns a string containing a concise, human-readable description of this
object.
|
static String |
toString(double d)
Returns a string containing a concise, human-readable description of the
specified double value.
|
static Double |
valueOf(double d)
Returns a
Double instance for the specified double value. |
static Double |
valueOf(String string)
Parses the specified string as a double value.
|
public static final double MAX_VALUE
double
value, (2 - 2-52) *
21023.public static final double MIN_VALUE
double
value, 2-1074.public static final double NaN
double
type.public static final double POSITIVE_INFINITY
double
type.public static final double NEGATIVE_INFINITY
double
type.public static final double MIN_NORMAL
double
type.public static final int MAX_EXPONENT
double
type may have.
Equal to Math.getExponent(Double.MAX_VALUE)
.public static final int MIN_EXPONENT
double
type may have.
Equal to Math.getExponent(Double.MIN_NORMAL)
.public static final Class<Double> TYPE
Class
object that represents the primitive type double
.public static final int SIZE
double
in
two's complement form.public Double(double value)
Double
with the specified primitive double
value.value
- the primitive double value to store in the new instance.public Double(String string) throws NumberFormatException
Double
from the specified string.string
- the string representation of a double value.NumberFormatException
- if string
cannot be parsed as a double value.parseDouble(String)
public int compareTo(Double object)
Double.NaN
is equal to Double.NaN
and it is greater
than any other double value, including Double.POSITIVE_INFINITY
;compareTo
in interface Comparable<Double>
object
- the double object to compare this object to.object
; 0 if the value of this double and the
value of object
are equal; a positive value if the value
of this double is greater than the value of object
.NullPointerException
- if object
is null
.Comparable
public byte byteValue()
Number
public static long doubleToLongBits(double value)
value
. All Not-a-Number (NaN) values are converted to a single NaN
representation (0x7ff8000000000000L
) (compare to doubleToRawLongBits(double)
).public static long doubleToRawLongBits(double value)
value
. Not-a-Number (NaN) values are preserved (compare
to doubleToLongBits(double)
).public double doubleValue()
doubleValue
in class Number
public boolean equals(Object object)
object
.
To be equal, object
must be an instance of Double
and
doubleToLongBits
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 double with.true
if the specified object is equal to this
Double
; false
otherwise.Object.hashCode()
public float floatValue()
Number
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 int intValue()
Number
public boolean isInfinite()
true
if the value of this double is positive or negative
infinity; false
otherwise.public static boolean isInfinite(double d)
d
- the double to check.true
if the value of d
is positive or negative
infinity; false
otherwise.public boolean isNaN()
true
if this double is Not-a-Number;
false
if it is a (potentially infinite) double number.public static boolean isNaN(double d)
d
- the double value to check.true
if d
is Not-a-Number;
false
if it is a (potentially infinite) double number.public static double longBitsToDouble(long bits)
bits
.public long longValue()
Number
public static double parseDouble(String string) throws NumberFormatException
string
- the string representation of a double value.string
.NumberFormatException
- if string
cannot be parsed as a double value.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(double d)
d
- the double to convert to a string.d
.public static Double valueOf(String string) throws NumberFormatException
string
- the string representation of a double value.Double
instance containing the double value represented
by string
.NumberFormatException
- if string
cannot be parsed as a double value.parseDouble(String)
public static int compare(double double1, double double2)
Double.NaN
is equal to Double.NaN
and it is greater
than any other double value, including Double.POSITIVE_INFINITY
;double1
- the first value to compare.double2
- the second value to compare.double1
is less than double2
;
0 if double1
and double2
are equal; a positive
value if double1
is greater than double2
.public static Double valueOf(double d)
Double
instance for the specified double value.d
- the double value to store in the instance.Double
instance containing d
.public static String toHexString(double d)
d
- the double to convert.d
.