Java Reference
InDepth Information
1. A decimal number with a decimal point in it.
Example
s:
1.34
and
3.
and
0.23333
.
Due to the way literals are implemented, the value of a
double
literal may
be only an approximation to the corresponding real value.
2. A number in scientific notation: a decimal number (the period
.
is option
al), followed by
e
or
E
, followed by a (possibly signed) integer.
Examples
:
1.32e20
and
2.1E0
and
1E5
and
3.14e62
.
The value of a double literal
mEi
is the value of
m
with its decimal point
moved i places to the right (if
i
is positive) or left (if
i
is negative). For
example,
5.0e5
is equivalent to .00005.
3. An
int
literal or a
double
literal, as in points 1 and 2 above, followed by
d
or
D
. Examples:
1D
and
1.2d
and
1.3e30d
and
24E20D
.
Scientific notation, used in many scientific fields, helps to express numbers
that would otherwise be infeasible to express. For example the
googol
, a name
coined by Milton Sirotta, a nineyear old, in 1955 is the number consisting of 1
followed by 100 zeroes,
1e100
. Mathematicians would write this as
10
100
. The
width of a human hair is approximately
750,000
angstroms or
7.5e7
meters.
Each
double
literal must be in the range of the type. If you type a literal that
is outside its range, your program is syntactically incorrect and will not compile.
Two constants give the largest and smallest positive
double
values:
Double.MAX_VALUE: 1.7976931348623157E308
Double.MIN_VALUE: 4.9E324
In addition, three other constants represent other “values” of type
double
:
1.
Double.NaN
, meaning “not a number”. Division by 0 produces this value.
2.
Double.POSITIVE_INFINITY
is produced when the exponent of a posi
tive number gets too big.
3.
Double.NEGATIVE_INFINITY
is produced when the exponent of a nega
tive number gets too big.
The range of the exponent is
324..308
.
Operations of type double
The basic arithmetic operators on type
double
work as expected:
•

:
Negation
. e.g.
3D
evaluates to
3.0
.
•
+
:
Addition
. e.g.
420. + 2D
evaluates to
422.0
.
•

:
Subtraction
. e.g.
42E1  .2E1
evaluates to
418.0
.
•
*
:
Multiplication
. e.g.
42E1 * .2E1
evaluates to
840.0
.
•
/
:
Division
. e.g.
1D / 3D
evaluates to
0.3333333333333333
.
Division
0D/0D
produces the value
Double.NaN
, meaning “Not a
Search WWH ::
Custom Search