java.lang
Class Double

java.lang.Object
  extended by java.lang.Double

public final class Double
extends Object

The Double class wraps a value of the primitive type double in an object. An object of type Double contains a single field whose type is double.

In addition, this class provides several methods for converting a double to a String and a String to a double, as well as other constants and methods useful when dealing with a double.

Since:
JDK1.0

Field Summary
static double MAX_VALUE
          A constant holding the largest positive finite value of type double, (2-2-52)·21023.
static double MIN_VALUE
          A constant holding the smallest positive nonzero value of type double, 2-1074.
static double NaN
          A constant holding a Not-a-Number (NaN) value of type double.
static double NEGATIVE_INFINITY
          A constant holding the negative infinity of type double.
static double POSITIVE_INFINITY
          A constant holding the positive infinity of type double.
 
Constructor Summary
Double()
           
 
Method Summary
static long doubleToLongBits(double value)
          Returns a representation of the specified floating-point value according to the IEEE 754 floating-point "double format" bit layout.
static boolean isInfinite(double v)
          Returns true if the specified number is infinitely large in magnitude, false otherwise.
static boolean isNaN(double v)
          Returns true if the specified number is a Not-a-Number (NaN) value, false otherwise.
static double longBitsToDouble(long bits)
          Returns the double value corresponding to a given bit representation.
static double parseDouble(String s)
          Returns a new double initialized to the value represented by the specified String.
static String toString(double d)
          Returns a string representation of the double argument.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, notifyAll, toString, wait
 

Field Detail

POSITIVE_INFINITY

public static final double POSITIVE_INFINITY
A constant holding the positive infinity of type double. It is equal to the value returned by Double.longBitsToDouble(0x7ff0000000000000L).

See Also:
Constant Field Values

NEGATIVE_INFINITY

public static final double NEGATIVE_INFINITY
A constant holding the negative infinity of type double. It is equal to the value returned by Double.longBitsToDouble(0xfff0000000000000L).

See Also:
Constant Field Values

NaN

public static final double NaN
A constant holding a Not-a-Number (NaN) value of type double. It is equivalent to the value returned by Double.longBitsToDouble(0x7ff8000000000000L).

See Also:
Constant Field Values

MAX_VALUE

public static final double MAX_VALUE
A constant holding the largest positive finite value of type double, (2-2-52)·21023. It is equal to the value returned by: Double.longBitsToDouble(0x7fefffffffffffffL).

See Also:
Constant Field Values

MIN_VALUE

public static final double MIN_VALUE
A constant holding the smallest positive nonzero value of type double, 2-1074. It is equal to the value returned by Double.longBitsToDouble(0x1L).

See Also:
Constant Field Values
Constructor Detail

Double

public Double()
Method Detail

toString

public static String toString(double d)
Returns a string representation of the double argument. All characters mentioned below are ASCII characters. How many digits must be printed for the fractional part of m or a? There must be at least one digit to represent the fractional part, and beyond that as many, but only as many, more digits as are needed to uniquely distinguish the argument value from adjacent values of type double. That is, suppose that x is the exact mathematical value represented by the decimal representation produced by this method for a finite nonzero argument d. Then d must be the double value nearest to x; or if two double values are equally close to x, then d must be one of them and the least significant bit of the significand of d must be 0.

Parameters:
d - the double to be converted.
Returns:
a string representation of the argument.

parseDouble

public static double parseDouble(String s)
                          throws NumberFormatException
Returns a new double initialized to the value represented by the specified String.

Parameters:
s - the string to be parsed.
Returns:
the double value represented by the string argument.
Throws:
NumberFormatException - if the string does not contain a parsable double.
Since:
1.2

isNaN

public static boolean isNaN(double v)
Returns true if the specified number is a Not-a-Number (NaN) value, false otherwise.

Parameters:
v - the value to be tested.
Returns:
true if the value of the argument is NaN; false otherwise.

isInfinite

public static boolean isInfinite(double v)
Returns true if the specified number is infinitely large in magnitude, false otherwise.

Parameters:
v - the value to be tested.
Returns:
true if the value of the argument is positive infinity or negative infinity; false otherwise.

doubleToLongBits

public static long doubleToLongBits(double value)
Returns a representation of the specified floating-point value according to the IEEE 754 floating-point "double format" bit layout.

Bit 63 (the bit that is selected by the mask 0x8000000000000000L) represents the sign of the floating-point number. Bits 62-52 (the bits that are selected by the mask 0x7ff0000000000000L) represent the exponent. Bits 51-0 (the bits that are selected by the mask 0x000fffffffffffffL) represent the significand (sometimes called the mantissa) of the floating-point number.

If the argument is positive infinity, the result is 0x7ff0000000000000L.

If the argument is negative infinity, the result is 0xfff0000000000000L.

If the argument is NaN, the result is 0x7ff8000000000000L.

In all cases, the result is a long integer that, when given to the longBitsToDouble(long) method, will produce a floating-point value the same as the argument to doubleToLongBits (except all NaN values are collapsed to a single "canonical" NaN value).

Parameters:
value - a double precision floating-point number.
Returns:
the bits that represent the floating-point number.

longBitsToDouble

public static double longBitsToDouble(long bits)
Returns the double value corresponding to a given bit representation. The argument is considered to be a representation of a floating-point value according to the IEEE 754 floating-point "double format" bit layout.

If the argument is 0x7ff0000000000000L, the result is positive infinity.

If the argument is 0xfff0000000000000L, the result is negative infinity.

If the argument is any value in the range 0x7ff0000000000001L through 0x7fffffffffffffffL or in the range 0xfff0000000000001L through 0xffffffffffffffffL, the result is a NaN. No IEEE 754 floating-point 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 Double.doubleToRawLongBits method.

In all other cases, let s, e, and m be three values that can be computed from the argument:

 int s = ((bits >> 63) == 0) ? 1 : -1;
 int e = (int)((bits >> 52) & 0x7ffL);
 long m = (e == 0) ?
                 (bits & 0xfffffffffffffL) << 1 :
                 (bits & 0xfffffffffffffL) | 0x10000000000000L;
 
Then the floating-point result equals the value of the mathematical expression s·m·2e-1075.

Note that this method may not be able to return a double NaN with exactly same bit pattern as the 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 longBitsToDouble may not be able to return a double with a signaling NaN bit pattern.

Parameters:
bits - any long integer.
Returns:
the double floating-point value with the same bit pattern.