java.lang.Object java.lang.Number java.lang.Double
All Implemented Interfaces:
Comparable, Serializable
In addition, this class provides several methods for converting a {@code double} to a {@code String} and a {@code String} to a {@code double}, as well as other constants and methods useful when dealing with a {@code double}.
Lee
 BoyntonArthur
 van HoffJoseph
 D. DarcyJDK1.0
 Field Summary  

public static final double  POSITIVE_INFINITY  A constant holding the positive infinity of type {@code double}. It is equal to the value returned by {@code Double.longBitsToDouble(0x7ff0000000000000L)}. 
public static final double  NEGATIVE_INFINITY  A constant holding the negative infinity of type {@code double}. It is equal to the value returned by {@code Double.longBitsToDouble(0xfff0000000000000L)}. 
public static final double  NaN  A constant holding a NotaNumber (NaN) value of type {@code double}. It is equivalent to the value returned by {@code Double.longBitsToDouble(0x7ff8000000000000L)}. 
public static final double  MAX_VALUE  A constant holding the largest positive finite value of type {@code double}, (22^{52})·2^{1023}. It is equal to the hexadecimal floatingpoint literal {@code 0x1.fffffffffffffP+1023} and also equal to {@code Double.longBitsToDouble(0x7fefffffffffffffL)}. 
public static final double  MIN_NORMAL  A constant holding the smallest positive normal value of type
{@code double}, 2^{1022}. It is equal to the
hexadecimal floatingpoint literal {@code 0x1.0p1022} and also
equal to {@code Double.longBitsToDouble(0x0010000000000000L)}.

public static final double  MIN_VALUE  A constant holding the smallest positive nonzero value of type {@code double}, 2^{1074}. It is equal to the hexadecimal floatingpoint literal {@code 0x0.0000000000001P1022} and also equal to {@code Double.longBitsToDouble(0x1L)}. 
public static final int  MAX_EXPONENT  Maximum exponent a finite {@code double} variable may have.
It is equal to the value returned by
{@code Math.getExponent(Double.MAX_VALUE)}.

public static final int  MIN_EXPONENT  Minimum exponent a normalized {@code double} variable may
have. It is equal to the value returned by
{@code Math.getExponent(Double.MIN_NORMAL)}.

public static final int  SIZE  The number of bits used to represent a {@code double} value.

public static final Class<Double>  TYPE  The {@code Class} instance representing the primitive type
{@code double}.

Constructor: 

public Double(double value){ this.value = value; } 
public Double(String s) throws NumberFormatException{ // REMIND: this is inefficient this(valueOf(s).doubleValue()); }

Method from java.lang.Double Summary: 

byteValue, compare, compareTo, doubleToLongBits, doubleToRawLongBits, doubleValue, equals, floatValue, hashCode, intValue, isInfinite, isInfinite, isNaN, isNaN, longBitsToDouble, longValue, parseDouble, shortValue, toHexString, toString, toString, valueOf, valueOf 
Methods from java.lang.Number: 

byteValue, doubleValue, floatValue, intValue, longValue, shortValue 
Methods from java.lang.Object: 

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait 
Method from java.lang.Double Detail:  

public byte byteValue(){ return (byte)value; }
 
public static int compare(double d1, double d2){ if (d1 < d2) return 1; // Neither val is NaN, thisVal is smaller if (d1 > d2) return 1; // Neither val is NaN, thisVal is larger // Cannot use doubleToRawLongBits because of possibility of NaNs. long thisBits = Double.doubleToLongBits(d1); long anotherBits = Double.doubleToLongBits(d2); return (thisBits == anotherBits ? 0 : // Values are equal (thisBits < anotherBits ? 1 : // (0.0, 0.0) or (!NaN, NaN) 1)); // (0.0, 0.0) or (NaN, !NaN) }
new Double(d1).compareTo(new Double(d2))  
public int compareTo(Double anotherDouble){ return Double.compare(value, anotherDouble.value); }
 
public static long doubleToLongBits(double value){ long result = doubleToRawLongBits(value); // Check for NaN based on values of bit fields, maximum // exponent and nonzero significand. if ( ((result & DoubleConsts.EXP_BIT_MASK) == DoubleConsts.EXP_BIT_MASK) && (result & DoubleConsts.SIGNIF_BIT_MASK) != 0L) result = 0x7ff8000000000000L; return result; }
Bit 63 (the bit that is selected by the mask {@code 0x8000000000000000L}) represents the sign of the floatingpoint number. Bits 6252 (the bits that are selected by the mask {@code 0x7ff0000000000000L}) represent the exponent. Bits 510 (the bits that are selected by the mask {@code 0x000fffffffffffffL}) represent the significand (sometimes called the mantissa) of the floatingpoint number. If the argument is positive infinity, the result is {@code 0x7ff0000000000000L}. If the argument is negative infinity, the result is {@code 0xfff0000000000000L}. If the argument is NaN, the result is {@code 0x7ff8000000000000L}. In all cases, the result is a {@code long} integer that, when given to the #longBitsToDouble(long) method, will produce a floatingpoint value the same as the argument to {@code doubleToLongBits} (except all NaN values are collapsed to a single "canonical" NaN value).  
public static native long doubleToRawLongBits(double value)
Bit 63 (the bit that is selected by the mask {@code 0x8000000000000000L}) represents the sign of the floatingpoint number. Bits 6252 (the bits that are selected by the mask {@code 0x7ff0000000000000L}) represent the exponent. Bits 510 (the bits that are selected by the mask {@code 0x000fffffffffffffL}) represent the significand (sometimes called the mantissa) of the floatingpoint number. If the argument is positive infinity, the result is {@code 0x7ff0000000000000L}. If the argument is negative infinity, the result is {@code 0xfff0000000000000L}. If the argument is NaN, the result is the {@code long} integer representing the actual NaN value. Unlike the {@code doubleToLongBits} method, {@code doubleToRawLongBits} does not collapse all the bit patterns encoding a NaN to a single "canonical" NaN value. In all cases, the result is a {@code long} integer that, when given to the #longBitsToDouble(long) method, will produce a floatingpoint value the same as the argument to {@code doubleToRawLongBits}.  
public double doubleValue(){ return (double)value; }
 
public boolean equals(Object obj){ return (obj instanceof Double) && (doubleToLongBits(((Double)obj).value) == doubleToLongBits(value)); }
Note that in most cases, for two instances of class {@code Double}, {@code d1} and {@code d2}, the value of {@code d1.equals(d2)} is {@code true} if and only if {@code d1.doubleValue() == d2.doubleValue()} also has the value {@code true}. However, there are two exceptions:  
public float floatValue(){ return (float)value; }
 
public int hashCode(){ long bits = doubleToLongBits(value); return (int)(bits ^ (bits > > > 32)); }
{@code (int)(v^(v>>>32))}where {@code v} is defined by: {@code long v = Double.doubleToLongBits(this.doubleValue());}  
public int intValue(){ return (int)value; }
 
public boolean isInfinite(){ return isInfinite(value); }
 
public static boolean isInfinite(double v){ return (v == POSITIVE_INFINITY)  (v == NEGATIVE_INFINITY); }
 
public boolean isNaN(){ return isNaN(value); }
 
public static boolean isNaN(double v){ return (v != v); }
 
public static native double longBitsToDouble(long bits)
If the argument is {@code 0x7ff0000000000000L}, the result is positive infinity. If the argument is {@code 0xfff0000000000000L}, the result is negative infinity. If the argument is any value in the range {@code 0x7ff0000000000001L} through {@code 0x7fffffffffffffffL} or in the range {@code 0xfff0000000000001L} through {@code 0xffffffffffffffffL}, the result is a NaN. No IEEE 754 floatingpoint operation provided by Java can distinguish between two NaN values of the same type with different bit patterns. Distinct values of NaN are only distinguishable by use of the {@code Double.doubleToRawLongBits} method. In all other cases, let s, e, and m be three values that can be computed from the argument: Then the floatingpoint result equals the value of the mathematical expression s·m·2^{e1075}.int s = ((bits >> 63) == 0) ? 1 : 1; int e = (int)((bits >> 52) & 0x7ffL); long m = (e == 0) ? (bits & 0xfffffffffffffL) << 1 : (bits & 0xfffffffffffffL)  0x10000000000000L; Note that this method may not be able to return a {@code double} NaN with exactly same bit pattern as the {@code long} argument. IEEE 754 distinguishes between two kinds of NaNs, quiet NaNs and signaling NaNs. The differences between the two kinds of NaN are generally not visible in Java. Arithmetic operations on signaling NaNs turn them into quiet NaNs with a different, but often similar, bit pattern. However, on some processors merely copying a signaling NaN also performs that conversion. In particular, copying a signaling NaN to return it to the calling method may perform this conversion. So {@code longBitsToDouble} may not be able to return a {@code double} with a signaling NaN bit pattern. Consequently, for some {@code long} values, {@code doubleToRawLongBits(longBitsToDouble(start))} may not equal {@code start}. Moreover, which particular bit patterns represent signaling NaNs is platform dependent; although all NaN bit patterns, quiet or signaling, must be in the NaN range identified above.  
public long longValue(){ return (long)value; }
 
public static double parseDouble(String s) throws NumberFormatException{ return FloatingDecimal.readJavaFormatString(s).doubleValue(); }
 
public short shortValue(){ return (short)value; }
 
public static String toHexString(double d){ /* * Modeled after the "a" conversion specifier in C99, section * 7.19.6.1; however, the output of this method is more * tightly specified. */ if (!FpUtils.isFinite(d) ) // For infinity and NaN, use the decimal output. return Double.toString(d); else { // Initialized to maximum size of output. StringBuffer answer = new StringBuffer(24); if (FpUtils.rawCopySign(1.0, d) == 1.0) // value is negative, answer.append(""); // so append sign info answer.append("0x"); d = Math.abs(d); if(d == 0.0) { answer.append("0.0p0"); } else { boolean subnormal = (d < DoubleConsts.MIN_NORMAL); // Isolate significand bits and OR in a highorder bit // so that the string representation has a known // length. long signifBits = (Double.doubleToLongBits(d) & DoubleConsts.SIGNIF_BIT_MASK)  0x1000000000000000L; // Subnormal values have a 0 implicit bit; normal // values have a 1 implicit bit. answer.append(subnormal ? "0." : "1."); // Isolate the loworder 13 digits of the hex // representation. If all the digits are zero, // replace with a single 0; otherwise, remove all // trailing zeros. String signif = Long.toHexString(signifBits).substring(3,16); answer.append(signif.equals("0000000000000") ? // 13 zeros "0": signif.replaceFirst("0{1,12}$", "")); // If the value is subnormal, use the E_min exponent // value for double; otherwise, extract and report d's // exponent (the representation of a subnormal uses // E_min 1). answer.append("p" + (subnormal ? DoubleConsts.MIN_EXPONENT: FpUtils.getExponent(d) )); } return answer.toString(); } }
 
public String toString(){ return toString(value); }
 
public static String toString(double d){ return new FloatingDecimal(d).toJavaFormatString(); }
To create localized string representations of a floatingpoint value, use subclasses of java.text.NumberFormat .  
public static Double valueOf(String s) throws NumberFormatException{ return new Double(FloatingDecimal.readJavaFormatString(s).doubleValue()); }
If {@code s} is {@code null}, then a {@code NullPointerException} is thrown. Leading and trailing whitespace characters in {@code s} are ignored. Whitespace is removed as if by the String#trim method; that is, both ASCII space and control characters are removed. The rest of {@code s} should constitute a FloatValue as described by the lexical syntax rules: where Sign, FloatingPointLiteral, HexNumeral, HexDigits, SignedInteger and FloatTypeSuffix are as defined in the lexical structure sections of The Java™ Language Specification, except that underscores are not accepted between digits. If {@code s} does not have the form of a FloatValue, then a {@code NumberFormatException} is thrown. Otherwise, {@code s} is regarded as representing an exact decimal value in the usual "computerized scientific notation" or as an exact hexadecimal value; this exact numerical value is then conceptually converted to an "infinitely precise" binary value that is then rounded to type {@code double} by the usual roundtonearest rule of IEEE 754 floatingpoint arithmetic, which includes preserving the sign of a zero value. Note that the roundtonearest rule also implies overflow and underflow behaviour; if the exact value of {@code s} is large enough in magnitude (greater than or equal to (#MAX_VALUE + ulp(MAX_VALUE) /2), rounding to {@code double} will result in an infinity and if the exact value of {@code s} is small enough in magnitude (less than or equal to #MIN_VALUE /2), rounding to float will result in a zero. Finally, after rounding a {@code Double} object representing this {@code double} value is returned. To interpret localized string representations of a floatingpoint value, use subclasses of java.text.NumberFormat . Note that trailing format specifiers, specifiers that determine the type of a floatingpoint literal ({@code 1.0f} is a {@code float} value; {@code 1.0d} is a {@code double} value), do not influence the results of this method. In other words, the numerical value of the input string is converted directly to the target floatingpoint type. The twostep sequence of conversions, string to {@code float} followed by {@code float} to {@code double}, is not equivalent to converting a string directly to {@code double}. For example, the {@code float} literal {@code 0.1f} is equal to the {@code double} value {@code 0.10000000149011612}; the {@code float} literal {@code 0.1f} represents a different numerical value than the {@code double} literal {@code 0.1}. (The numerical value 0.1 cannot be exactly represented in a binary floatingpoint number.) To avoid calling this method on an invalid string and having
a {@code NumberFormatException} be thrown, the regular
expression below can be used to screen the input string:
 
public static Double valueOf(double d){ return new Double(d); }
