Package java.lang
Class Double
- java.lang.Object
-
- java.lang.Number
-
- java.lang.Double
-
- All Implemented Interfaces:
Serializable,Comparable<Double>,Modified
public final class Double extends Number implements Comparable<Double>, Modified
The wrapper for the primitive typedouble.- Since:
- 1.0
- See Also:
Number, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static doubleINF_EXPONENTstatic doubleMAX_VALUEA constant holding the largest positive finite value of typedouble, (2-2-52)·21023.static doubleMIN_VALUEA constant holding the smallest positive nonzero value of typedouble, 2-1074.static doubleMIN_VALUE_NORMA constant holding the smallest positive normalized value of typedouble, 2-1074.static doubleNaNA constant holding a Not-a-Number (NaN) value of typedouble.static doubleNEGATIVE_INFINITYA constant holding the negative infinity of typedouble.static doublePOSITIVE_INFINITYA constant holding the positive infinity of typedouble.static intSIZEThe number of bits used to represent aDoublevalue.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods 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 intdoubleToChars(double val, int nofFractDigits, char[] chars)doubledoubleValue()Returns thedoublevalue of thisDoubleobject.booleanequals(Object object)Tests this double for equality withobject.floatfloatValue()Returns this object's value as a float.static intgetExponent(double arg)Returns the exponent of a double precisionvalueto the base of 2.inthashCode()Returns an integer hash code for this object.static inthighPartToIntBits(double arg)Returns an integer corresponding to the upper 32 bits of the given IEEE 754 double precisionvalue.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.longlongValue()Returns this object's value as a long.static intlowPartToIntBits(double arg)Returns an integer corresponding to the lower 32 bits of the given IEEE 754 double precisionvalue.static doubleparseDouble(String s)Returns the closest double value to the real number in the string.static doublepowOf10(int e)Calculates power to the base of 10static doublesetExponent(double d, int newExp)Sets the exponent of a double precisionvalueto the base of 2 and returns the new value.shortshortValue()Returns this object's value as a short.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 Detail
-
POSITIVE_INFINITY
public static final double POSITIVE_INFINITY
A constant holding the positive infinity of typedouble. It is equal to the value returned byDouble.longBitsToDouble(0x7ff0000000000000L).- See Also:
- Constant Field Values
-
NEGATIVE_INFINITY
public static final double NEGATIVE_INFINITY
A constant holding the negative infinity of typedouble. It is equal to the value returned byDouble.longBitsToDouble(0xfff0000000000000L).- See Also:
- Constant Field Values
-
NaN
public static final double NaN
A constant holding a Not-a-Number (NaN) value of typedouble. It is equivalent to the value returned byDouble.longBitsToDouble(0x7ff8000000000000L).- See Also:
- Constant Field Values
-
MAX_VALUE
public static final double MAX_VALUE
A constant holding the largest positive finite value of typedouble, (2-2-52)·21023. It is equal to the hexadecimal floating-point literal0x1.fffffffffffffP+1023and also equal toDouble.longBitsToDouble(0x7fefffffffffffffL).- See Also:
- Constant Field Values
-
MIN_VALUE
public static final double MIN_VALUE
A constant holding the smallest positive nonzero value of typedouble, 2-1074. It is equal to the hexadecimal floating-point literal0x0.0000000000001P-1022and also equal toDouble.longBitsToDouble(0x1L).- See Also:
- Constant Field Values
-
MIN_VALUE_NORM
public static final double MIN_VALUE_NORM
A constant holding the smallest positive normalized value of typedouble, 2-1074. It is equal to the hexadecimal floating-point literalDouble.longBitsToDouble(1L << 52).- See Also:
- Constant Field Values
-
SIZE
public static final int SIZE
The number of bits used to represent aDoublevalue.- See Also:
- Constant Field Values
-
INF_EXPONENT
public static final double INF_EXPONENT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Double
public Double(double value)
Constructs a newly allocatedDoubleobject that represents the primitivedoubleargument.- Parameters:
value- the value to be represented by theDouble.
-
Double
public Double(String string) throws NumberFormatException
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 Detail
-
powOf10
public static double powOf10(int e)
Calculates power to the base of 10- Parameters:
e- this is the exponent- Returns:
- power of 10e.
-
highPartToIntBits
public static int highPartToIntBits(double arg)
Returns an integer corresponding to the upper 32 bits of the given IEEE 754 double precisionvalue.- Parameters:
arg- Double argument.- Returns:
- Upper 32 bits.
-
lowPartToIntBits
public static int lowPartToIntBits(double arg)
Returns an integer corresponding to the lower 32 bits of the given IEEE 754 double precisionvalue.- Parameters:
arg- Double argument.- Returns:
- Lower 32 bits.
-
getExponent
public static int getExponent(double arg)
Returns the exponent of a double precisionvalueto the base of 2.- Parameters:
arg- Double argument.- Returns:
- Exponent.
-
setExponent
public static double setExponent(double d, int newExp)Sets the exponent of a double precisionvalueto the base of 2 and returns the new value.- Parameters:
d- DoublenewExp- New exponent.- Returns:
- New double value.
-
doubleToChars
public static int doubleToChars(double val, int nofFractDigits, char[] chars)
-
valueOf
public static Double valueOf(double d)
Returns aDoubleinstance for the specified double value.- Parameters:
d- the double value to store in the instance.- Returns:
- a
Doubleinstance containingd. - Since:
- 1.5
-
valueOf
public static Double valueOf(String string) throws NumberFormatException
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)
-
parseDouble
public static double parseDouble(String s) throws NumberFormatException
Returns the closest double value to the real number in the string.- Parameters:
s- the String that will be parsed to a floating point- Returns:
- the double closest to the real number
- Throws:
NumberFormatException- if the String doesn't represent a double
-
doubleValue
public double doubleValue()
Returns thedoublevalue of thisDoubleobject.- Specified by:
doubleValuein classNumber- Returns:
- the
doublevalue represented by this object
-
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.
-
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.
-
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.
-
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.
-
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.
-
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)
-
toString
public String 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.
-
toString
public static String toString(double d)
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.
-
compareTo
public int compareTo(Double object)
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
-
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.
-
equals
public boolean equals(Object object)
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()
-
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.
-
-