Package java.lang
Class Double
java.lang.Object
java.lang.Number
java.lang.Double
- All Implemented Interfaces:
Serializable,Comparable<Double>
public final class Double extends Number implements Comparable<Double>
The wrapper for the primitive type
double.- Since:
- 1.0
- See Also:
Number, Serialized Form
-
Field Summary
Fields Modifier and Type Field Description static intMAX_EXPONENTMaximum base-2 exponent that a finite value of thedoubletype may have.static doubleMAX_VALUEConstant for the maximumdoublevalue, (2 - 2-52) * 21023.static intMIN_EXPONENTMinimum base-2 exponent that a normal value of thedoubletype may have.static doubleMIN_NORMALConstant for the smallest positive normal value of thedoubletype.static doubleMIN_VALUEConstant for the minimumdoublevalue, 2-1074.static doubleNaNConstant for the Not-a-Number (NaN) value of thedoubletype.static doubleNEGATIVE_INFINITYConstant for the negative infinity value of thedoubletype.static doublePOSITIVE_INFINITYConstant for the positive infinity value of thedoubletype.static intSIZEConstant for the number of bits needed to represent adoublein two's complement form.static Class<Double>TYPETheClassobject that represents the primitive typedouble. -
Constructor Summary
-
Method Summary
Modifier and Type Method Description bytebyteValue()Returns this object's value as a byte.static intcompare(double double1, double double2)Compares the two specified double values.intcompareTo(Double object)Compares this object to the specified double object to determine their relative order.static longdoubleToLongBits(double value)Returns an integer corresponding to the bits of the given IEEE 754 double precisionvalue.static longdoubleToRawLongBits(double value)Returns an integer corresponding to the bits of the given IEEE 754 double precisionvalue.doubledoubleValue()Gets the primitive value of this double.booleanequals(Object object)Tests this double for equality withobject.floatfloatValue()Returns this object's value as a float.inthashCode()Returns an integer hash code for this object.intintValue()Returns this object's value as an int.booleanisInfinite()Indicates whether this object represents an infinite value.static booleanisInfinite(double d)Indicates whether the specified double represents an infinite value.booleanisNaN()Indicates whether this object is a Not-a-Number (NaN) value.static booleanisNaN(double d)Indicates whether the specified double is a Not-a-Number (NaN) value.static doublelongBitsToDouble(long bits)Returns the IEEE 754 double precision float corresponding to the givenbits.longlongValue()Returns this object's value as a long.static doubleparseDouble(String string)Parses the specified string as a double value.shortshortValue()Returns this object's value as a short.static StringtoHexString(double d)Converts the specified double into its hexadecimal string representation.StringtoString()Returns a string containing a concise, human-readable description of this object.static StringtoString(double d)Returns a string containing a concise, human-readable description of the specified double value.static DoublevalueOf(double d)Returns aDoubleinstance for the specified double value.static DoublevalueOf(String string)Parses the specified string as a double value.
-
Field Details
-
MAX_VALUE
public static final double MAX_VALUEConstant for the maximumdoublevalue, (2 - 2-52) * 21023.- See Also:
- Constant Field Values
-
MIN_VALUE
public static final double MIN_VALUEConstant for the minimumdoublevalue, 2-1074.- See Also:
- Constant Field Values
-
NaN
public static final double NaNConstant for the Not-a-Number (NaN) value of thedoubletype.- See Also:
- Constant Field Values
-
POSITIVE_INFINITY
public static final double POSITIVE_INFINITYConstant for the positive infinity value of thedoubletype.- See Also:
- Constant Field Values
-
NEGATIVE_INFINITY
public static final double NEGATIVE_INFINITYConstant for the negative infinity value of thedoubletype.- See Also:
- Constant Field Values
-
MIN_NORMAL
public static final double MIN_NORMALConstant for the smallest positive normal value of thedoubletype.- Since:
- 1.6
- See Also:
- Constant Field Values
-
MAX_EXPONENT
public static final int MAX_EXPONENTMaximum base-2 exponent that a finite value of thedoubletype may have. Equal toMath.getExponent(Double.MAX_VALUE).- Since:
- 1.6
- See Also:
- Constant Field Values
-
MIN_EXPONENT
public static final int MIN_EXPONENTMinimum base-2 exponent that a normal value of thedoubletype may have. Equal toMath.getExponent(Double.MIN_NORMAL).- Since:
- 1.6
- See Also:
- Constant Field Values
-
TYPE
TheClassobject that represents the primitive typedouble.- Since:
- 1.1
-
SIZE
public static final int SIZEConstant for the number of bits needed to represent adoublein two's complement form.- Since:
- 1.5
- See Also:
- Constant Field Values
-
-
Constructor Details
-
Double
public Double(double value)Constructs a newDoublewith the specified primitive double value.- Parameters:
value- the primitive double value to store in the new instance.
-
Double
Constructs a newDoublefrom the specified string.- Parameters:
string- the string representation of a double value.- Throws:
NumberFormatException- ifstringcannot be parsed as a double value.- See Also:
parseDouble(String)
-
-
Method Details
-
compareTo
Compares this object to the specified double object to determine their relative order. There are two special cases:Double.NaNis equal toDouble.NaNand it is greater than any other double value, includingDouble.POSITIVE_INFINITY;- +0.0d is greater than -0.0d
- Specified by:
compareToin interfaceComparable<Double>- Parameters:
object- the double object to compare this object to.- Returns:
- a negative value if the value of this double is less than the
value of
object; 0 if the value of this double and the value ofobjectare equal; a positive value if the value of this double is greater than the value ofobject. - Throws:
NullPointerException- ifobjectisnull.- Since:
- 1.2
- See Also:
Comparable
-
byteValue
public byte byteValue()Description copied from class:NumberReturns this object's value as a byte. Might involve rounding and/or truncating the value, so it fits into a byte. -
doubleToLongBits
public static long doubleToLongBits(double value)Returns an integer corresponding to the bits of the given IEEE 754 double precisionvalue. All Not-a-Number (NaN) values are converted to a single NaN representation (0x7ff8000000000000L) (compare todoubleToRawLongBits(double)). -
doubleToRawLongBits
public static long doubleToRawLongBits(double value)Returns an integer corresponding to the bits of the given IEEE 754 double precisionvalue. Not-a-Number (NaN) values are preserved (compare todoubleToLongBits(double)). -
doubleValue
public double doubleValue()Gets the primitive value of this double.- Specified by:
doubleValuein classNumber- Returns:
- this object's primitive value.
-
equals
Tests this double for equality withobject. To be equal,objectmust be an instance ofDoubleanddoubleToLongBitsmust give the same value for both objects.Note that, unlike
==,-0.0and+0.0compare unequal, andNaNs compare equal by this method.- Overrides:
equalsin classObject- Parameters:
object- the object to compare this double with.- Returns:
trueif the specified object is equal to thisDouble;falseotherwise.- See Also:
Object.hashCode()
-
floatValue
public float floatValue()Description copied from class:NumberReturns this object's value as a float. Might involve rounding.- Specified by:
floatValuein classNumber- Returns:
- the primitive float value of this object.
-
hashCode
public int hashCode()Description copied from class:ObjectReturns an integer hash code for this object. By contract, any two objects for whichObject.equals(java.lang.Object)returnstruemust return the same hash code value. This means that subclasses ofObjectusually 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
hashCodemethod if you intend implementing your ownhashCodemethod.- Overrides:
hashCodein classObject- Returns:
- this object's hash code.
- See Also:
Object.equals(java.lang.Object)
-
intValue
public int intValue()Description copied from class:NumberReturns this object's value as an int. Might involve rounding and/or truncating the value, so it fits into an int. -
isInfinite
public boolean isInfinite()Indicates whether this object represents an infinite value.- Returns:
trueif the value of this double is positive or negative infinity;falseotherwise.
-
isInfinite
public static boolean isInfinite(double d)Indicates whether the specified double represents an infinite value.- Parameters:
d- the double to check.- Returns:
trueif the value ofdis positive or negative infinity;falseotherwise.
-
isNaN
public boolean isNaN()Indicates whether this object is a Not-a-Number (NaN) value.- Returns:
trueif this double is Not-a-Number;falseif it is a (potentially infinite) double number.
-
isNaN
public static boolean isNaN(double d)Indicates whether the specified double is a Not-a-Number (NaN) value.- Parameters:
d- the double value to check.- Returns:
trueifdis Not-a-Number;falseif it is a (potentially infinite) double number.
-
longBitsToDouble
public static double longBitsToDouble(long bits)Returns the IEEE 754 double precision float corresponding to the givenbits. -
longValue
public long longValue()Description copied from class:NumberReturns this object's value as a long. Might involve rounding and/or truncating the value, so it fits into a long. -
parseDouble
Parses the specified string as a double value.- Parameters:
string- the string representation of a double value.- Returns:
- the primitive double value represented by
string. - Throws:
NumberFormatException- ifstringcannot be parsed as a double value.
-
shortValue
public short shortValue()Description copied from class:NumberReturns this object's value as a short. Might involve rounding and/or truncating the value, so it fits into a short.- Overrides:
shortValuein classNumber- Returns:
- the primitive short value of this object.
-
toString
Description copied from class:ObjectReturns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toStringmethod if you intend implementing your owntoStringmethod. -
toString
Returns a string containing a concise, human-readable description of the specified double value.- Parameters:
d- the double to convert to a string.- Returns:
- a printable representation of
d.
-
valueOf
Parses the specified string as a double value.- Parameters:
string- the string representation of a double value.- Returns:
- a
Doubleinstance containing the double value represented bystring. - Throws:
NumberFormatException- ifstringcannot be parsed as a double value.- See Also:
parseDouble(String)
-
compare
public static int compare(double double1, double double2)Compares the two specified double values. There are two special cases:Double.NaNis equal toDouble.NaNand it is greater than any other double value, includingDouble.POSITIVE_INFINITY;- +0.0d is greater than -0.0d
- Parameters:
double1- the first value to compare.double2- the second value to compare.- Returns:
- a negative value if
double1is less thandouble2; 0 ifdouble1anddouble2are equal; a positive value ifdouble1is greater thandouble2.
-
valueOf
Returns aDoubleinstance for the specified double value.- Parameters:
d- the double value to store in the instance.- Returns:
- a
Doubleinstance containingd. - Since:
- 1.5
-
toHexString
Converts the specified double into its hexadecimal string representation.- Parameters:
d- the double to convert.- Returns:
- the hexadecimal string representation of
d. - Since:
- 1.5
-