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 double
INF_EXPONENT
static double
MAX_VALUE
A constant holding the largest positive finite value of typedouble
, (2-2-52)·21023.static double
MIN_VALUE
A constant holding the smallest positive nonzero value of typedouble
, 2-1074.static double
MIN_VALUE_NORM
A constant holding the smallest positive normalized value of typedouble
, 2-1074.static double
NaN
A constant holding a Not-a-Number (NaN) value of typedouble
.static double
NEGATIVE_INFINITY
A constant holding the negative infinity of typedouble
.static double
POSITIVE_INFINITY
A constant holding the positive infinity of typedouble
.static int
SIZE
The number of bits used to represent aDouble
value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 int
doubleToChars(double val, int nofFractDigits, char[] chars)
double
doubleValue()
Returns thedouble
value of thisDouble
object.boolean
equals(Object object)
Tests this double for equality withobject
.float
floatValue()
Returns this object's value as a float.static int
getExponent(double arg)
Returns the exponent of a double precisionvalue
to the base of 2.int
hashCode()
Returns an integer hash code for this object.static int
highPartToIntBits(double arg)
Returns an integer corresponding to the upper 32 bits of the given IEEE 754 double precisionvalue
.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.long
longValue()
Returns this object's value as a long.static int
lowPartToIntBits(double arg)
Returns an integer corresponding to the lower 32 bits of the given IEEE 754 double precisionvalue
.static double
parseDouble(String s)
Returns the closest double value to the real number in the string.static double
powOf10(int e)
Calculates power to the base of 10static double
setExponent(double d, int newExp)
Sets the exponent of a double precisionvalue
to the base of 2 and returns the new value.short
shortValue()
Returns this object's value as a short.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 aDouble
instance for the specified double value.static Double
valueOf(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+1023
and 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-1022
and 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 aDouble
value.- 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 allocatedDouble
object that represents the primitivedouble
argument.- Parameters:
value
- the value to be represented by theDouble
.
-
Double
public Double(String string) throws NumberFormatException
Constructs a newDouble
from the specified string.- Parameters:
string
- the string representation of a double value.- Throws:
NumberFormatException
- ifstring
cannot 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 precisionvalue
to 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 precisionvalue
to 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 aDouble
instance for the specified double value.- Parameters:
d
- the double value to store in the instance.- Returns:
- a
Double
instance 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
Double
instance containing the double value represented bystring
. - Throws:
NumberFormatException
- ifstring
cannot 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 thedouble
value of thisDouble
object.- Specified by:
doubleValue
in classNumber
- Returns:
- the
double
value represented by this object
-
byteValue
public byte byteValue()
Description copied from class:Number
Returns 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:Number
Returns this object's value as a float. Might involve rounding.- Specified by:
floatValue
in classNumber
- Returns:
- the primitive float value of this object.
-
intValue
public int intValue()
Description copied from class:Number
Returns 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:Number
Returns 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:Number
Returns this object's value as a short. Might involve rounding and/or truncating the value, so it fits into a short.- Overrides:
shortValue
in classNumber
- Returns:
- the primitive short value of this object.
-
hashCode
public int hashCode()
Description copied from class:Object
Returns an integer hash code for this object. By contract, any two objects for whichObject.equals(java.lang.Object)
returnstrue
must return the same hash code value. This means that subclasses ofObject
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 ownhashCode
method.- Overrides:
hashCode
in classObject
- Returns:
- this object's hash code.
- See Also:
Object.equals(java.lang.Object)
-
toString
public String toString()
Description copied from class:Object
Returns 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.NaN
is equal toDouble.NaN
and it is greater than any other double value, includingDouble.POSITIVE_INFINITY
;- +0.0d is greater than -0.0d
- Specified by:
compareTo
in 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 ofobject
are equal; a positive value if the value of this double is greater than the value ofobject
. - Throws:
NullPointerException
- ifobject
isnull
.- 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.NaN
is equal toDouble.NaN
and 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
double1
is less thandouble2
; 0 ifdouble1
anddouble2
are equal; a positive value ifdouble1
is greater thandouble2
.
-
equals
public boolean equals(Object object)
Tests this double for equality withobject
. To be equal,object
must be an instance ofDouble
anddoubleToLongBits
must give the same value for both objects.Note that, unlike
==
,-0.0
and+0.0
compare unequal, andNaN
s compare equal by this method.- Overrides:
equals
in classObject
- Parameters:
object
- the object to compare this double with.- Returns:
true
if the specified object is equal to thisDouble
;false
otherwise.- See Also:
Object.hashCode()
-
isInfinite
public boolean isInfinite()
Indicates whether this object represents an infinite value.- Returns:
true
if the value of this double is positive or negative infinity;false
otherwise.
-
isInfinite
public static boolean isInfinite(double d)
Indicates whether the specified double represents an infinite value.- Parameters:
d
- the double to check.- Returns:
true
if the value ofd
is positive or negative infinity;false
otherwise.
-
isNaN
public boolean isNaN()
Indicates whether this object is a Not-a-Number (NaN) value.- Returns:
true
if this double is Not-a-Number;false
if 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:
true
ifd
is Not-a-Number;false
if it is a (potentially infinite) double number.
-
-