|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Double
public final class Double
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
.
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 |
---|
public static final double POSITIVE_INFINITY
double
. It is equal to the value returned by
Double.longBitsToDouble(0x7ff0000000000000L)
.
public static final double NEGATIVE_INFINITY
double
. It is equal to the value returned by
Double.longBitsToDouble(0xfff0000000000000L)
.
public static final double NaN
double
. It is equivalent to the value returned by
Double.longBitsToDouble(0x7ff8000000000000L)
.
public static final double MAX_VALUE
double
, (2-2-52)·21023.
It is equal to the value returned by:
Double.longBitsToDouble(0x7fefffffffffffffL)
.
public static final double MIN_VALUE
double
, 2-1074. It is equal to the
value returned by Double.longBitsToDouble(0x1L)
.
Constructor Detail |
---|
public Double()
Method Detail |
---|
public static String toString(double d)
double
argument. All characters mentioned below are ASCII characters.
NaN
".
-
'
('\u002D'
); if the sign is positive, no sign character
appears in the result. As for the magnitude m:
"Infinity"
; thus, positive infinity produces the result
"Infinity"
and negative infinity produces the result
"-Infinity"
.
"0.0"
; thus, negative zero produces the result
"-0.0"
and positive zero produces the result
"0.0"
.
.
' ('\u002E'
), followed by one or
more decimal digits representing the fractional part of m.
.
'
('\u002E'
), followed by decimal digits
representing the fractional part of a, followed by the
letter 'E
' ('\u0045'
), followed
by a representation of n as a decimal integer, as
produced by the method Integer.toString(int)
.
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
.
d
- the double
to be converted.
public static double parseDouble(String s) throws NumberFormatException
double
initialized to the value
represented by the specified String
.
s
- the string to be parsed.
double
value represented by the string
argument.
NumberFormatException
- if the string does not contain
a parsable double
.public static boolean isNaN(double v)
true
if the specified number is a
Not-a-Number (NaN) value, false
otherwise.
v
- the value to be tested.
true
if the value of the argument is NaN;
false
otherwise.public static boolean isInfinite(double v)
true
if the specified number is infinitely
large in magnitude, false
otherwise.
v
- the value to be tested.
true
if the value of the argument is positive
infinity or negative infinity; false
otherwise.public static long doubleToLongBits(double value)
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).
value
- a double
precision floating-point number.
public static double longBitsToDouble(long bits)
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:
Then the floating-point result equals the value of the mathematical expression s·m·2e-1075.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
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.
bits
- any long
integer.
double
floating-point value with the same
bit pattern.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |