📄 javalang.doc9.html
字号:
<p>
<a name="4609"></a>
The <code>double</code> value represented by this <code>Double</code> object is converted <a href="5.doc.html#175672">(§5.1.3)</a> to type
<code>float</code> and the result of the conversion is returned.
<p><a name="4345"></a>
Overrides the <code>floatValue</code> method of <code>Number</code> <a href="javalang.doc5.html#3384">(§20.6.3)</a>.<p>
<a name="1523"></a>
<p><font size=+1><strong>20.10.14 </strong> <code>public double <code><b>doubleValue</b></code>()</code></font>
<p>
<a name="4495"></a>
The <code>double</code> value represented by this <code>Double</code> object is returned.
<p><a name="4327"></a>
Overrides the <code>doubleValue</code> method of <code>Number</code> <a href="javalang.doc5.html#3412">(§20.6.4)</a>.<p>
<a name="5899"></a>
<p><font size=+1><strong>20.10.15 </strong> <code>public static String <code><b>toString</b></code>(double d)</code></font>
<p>
<a name="24962"></a>
The argument is converted to a readable string format as follows. All characters
mentioned below are ASCII characters.
<p><ul><a name="7264"></a>
<li>If the argument is NaN, the result is the string <code>"NaN"</code>.
<a name="7265"></a>
<li>Otherwise, the result is a string that represents the sign and magnitude (absolute value) of the argument. If the sign is negative, the first character of the result is <code>'-'</code> (<code>'\u002d'</code>); if the sign is positive, no sign character appears in the result. As for the magnitude <i>m</i>:
<ul>
<a name="7266"></a>
<li>If <i>m</i> is infinity, it is represented by the characters <code>"Infinity"</code>; thus, positive infinity produces the result <code>"Infinity"</code> and negative infinity produces the result <code>"-Infinity"</code>.
<a name="7267"></a>
<li>If <i>m</i> is zero, it is represented by the characters <code>"0.0"</code>; thus, negative zero produces the result <code>"-0.0"</code> and positive zero produces the result <code>"0.0"</code>.
<a name="7274"></a>
<li>If <i>m</i> is greater than or equal to <img src="javalang.doc.anc23.gif"> but less than <img src="javalang.doc.anc24.gif">, then it is represented as the integer part of <i>m</i>, in decimal form with no leading zeroes, followed by <code>'.'</code> (<code>\u002E</code>), followed by one or more decimal digits representing the fractional part of <i>m</i>.
<a name="7281"></a>
<li>If <i>m</i> is less than <img src="javalang.doc.anc25.gif"> or not less than <img src="javalang.doc.anc26.gif">, then it is represented in so-called "computerized scientific notation." Let <i>n</i> be the unique integer such that <img src="javalang.doc.anc27.gif">; then let <i>a</i> be the mathematically exact quotient of <i>m</i> and <img src="javalang.doc.anc28.gif"> so that <img src="javalang.doc.anc29.gif">. The magnitude is then represented as the integer part of <i>a</i>, as a single decimal digit, followed by <code>'.'</code> (<code>\u002E</code>), followed by decimal digits representing the fractional part of <i>a</i>, followed by the letter <code>'E'</code> (<code>\u0045</code>), followed by a representation of <i>n</i> as a decimal integer, as produced by the method <code>Integer.toString</code> of one argument <a href="javalang.doc6.html#1459">(§20.7.12)</a>.
</ul>
</ul><a name="7297"></a>
How many digits must be printed for the fractional part of <i>m</i> or <i>a</i>? 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 <code>double</code>. That is, suppose that <i>x</i> is the exact mathematical value represented by the decimal representation produced by this method for a finite nonzero argument <i>d</i>. Then <i>d </i>must be the <code>double</code> value nearest to <i>x</i>; or if two <code>double</code> values are equally close to <i>x</i>, then <i>d </i>must be one of them and the least significant bit of the significand of <i>d </i>must be <code>0</code>.<p>
<a name="28580"></a>
[This specification for the method <code>toString</code> is scheduled for introduction in Java version 1.1. In previous versions of Java, this method produces <code>Inf</code> instead of <code>Infinity</code> for infinite values. Also, it rendered finite values in the same form as the <code>%g</code> format of the <code>printf</code> function in the C programming language, which can lose information because it produces at most six digits after the decimal point.]<p>
<a name="1541"></a>
<p><font size=+1><strong>20.10.16 </strong> <code>public static Double <code><b>valueOf</b></code>(String s)<br>throws NullPointerException, NumberFormatException</code></font>
<p>
<a name="28707"></a>
The string <code>s</code> is interpreted as the representation of a floating-point value and a
<code>Double</code> object representing that value is created and returned.
<p><a name="28708"></a>
If <code>s</code> is <code>null</code>, then a <code>NullPointerException</code> is thrown.<p>
<a name="28712"></a>
Leading and trailing whitespace <a href="javalang.doc10.html#36320">(§20.5.19)</a> characters in <code>s</code> are ignored. The rest of <code>s</code> should constitute a <i>FloatValue</i> as described by the lexical syntax rule:<p>
<ul><pre>
<i>FloatValue:<br>
Sign</i><sub><i>opt</i></sub><i> Digits</i><code> . </code><i>Digits</i><sub><i>opt</i></sub><code> </code><i>ExponentPart</i><sub><i>opt<br>
</i></sub> <i>Sign</i><sub><i>opt</i></sub><i> </i><code>. </code><i>Digits</i><code> </code><i>ExponentPart</i><sub><i>opt
</i></sub></pre></ul><a name="28718"></a>
where <i>Sign</i>, <i>Digits</i>, and <i>ExponentPart</i> are as defined in <a href="3.doc.html#230798">§3.10.2</a>. If it does not have
the form of a <i>FloatValue</i>, then a <code>NumberFormatException</code> is thrown. Otherwise,
it is regarded as representing an exact decimal value in the usual "computerized
scientific notation"; this exact decimal value is then conceptually converted to an
"infinitely precise" binary value that is then rounded to type <code>double</code> by the usual
round-to-nearest rule of IEEE 754 floating-point arithmetic. Finally, a new object
of class <code>Double</code> is created to represent the <code>double</code> value.
<p><a name="28719"></a>
Note that neither <code>D</code> nor <code>d</code> is permitted to appear in <code>s</code> as a type indicator, as would be permitted in Java source code <a href="3.doc.html#48282">(§3.10.1)</a>.<p>
<a name="13852"></a>
<p><font size=+1><strong>20.10.17 </strong> <code>public boolean <code><b>isNaN</b></code>()</code></font>
<p>
<a name="4797"></a>
The result is <code>true</code> if and only if the value represented by this <code>Double</code> object is
NaN.
<p><a name="1529"></a>
<p><font size=+1><strong>20.10.18 </strong> <code>public static boolean <code><b>isNaN</b></code>(double v)</code></font>
<p>
<a name="4802"></a>
The result is <code>true</code> if and only if the value of the argument is NaN.
<p><a name="13853"></a>
<p><font size=+1><strong>20.10.19 </strong> <code>public boolean <code><b>isInfinite</b></code>()</code></font>
<p>
<a name="4808"></a>
The result is <code>true</code> if and only if the value represented by this <code>Double</code> object is
positive infinity or negative infinity.
<p><a name="1535"></a>
<p><font size=+1><strong>20.10.20 </strong> <code>public static boolean <code><b>isInfinite</b></code>(double v)</code></font>
<p>
<a name="4814"></a>
The result is <code>true</code> if and only if the value of the argument is positive infinity or
negative infinity.
<p><a name="13863"></a>
<p><font size=+1><strong>20.10.21 </strong> <code>public static long <code><b>doubleToLongBits</b></code>(double value)</code></font>
<p>
<a name="5855"></a>
The result is a representation of the floating-point argument according to the IEEE
754 floating-point "double format" bit layout:
<p><ul><a name="5856"></a>
<li>Bit 63 (the bit that is selected by the mask <code>0x8000000000000000L</code>) represents the sign of the floating-point number.
<a name="5857"></a>
<li>Bits 62-52 (the bits that are selected by the mask <code>0x7ff0000000000000L</code>) represent the exponent.
<a name="5858"></a>
<li>Bits 51-0 (the bits that are selected by the mask <code>0x000fffffffffffffL</code>) represent the significand (sometimes called the mantissa) of the floating-point number.
<a name="5859"></a>
<li>If the argument is positive infinity, the result will be <code>0x7ff0000000000000L</code>.
<a name="5860"></a>
<li>If the argument is negative infinity, the result will be <code>0xfff0000000000000L</code>.
<a name="5861"></a>
<li>If the argument is NaN, the result will be <code>0x7ff8000000000000L</code>.
</ul><a name="5862"></a>
In all cases, the result is a <code>long</code> integer that, when given to the <code>longBitsToDouble</code>  method <a href="javalang.doc9.html#13864">(§20.10.22)</a>, will produce a floating-point value equal to the argument to <code>doubleToLongBits</code>.<p>
<a name="13864"></a>
<p><font size=+1><strong>20.10.22 </strong> <code>public static double <code><b>longBitsToDouble</b></code>(long bits)</code></font>
<p>
<a name="5869"></a>
The argument is considered to be a representation of a floating-point value according
to the IEEE 754 floating-point "double format" bit layout. That floating-point
value is returned as the result.
<p><ul><a name="5870"></a>
<li>If the argument is <code>0x7f80000000000000L</code>, the result will be positive infinity.
<a name="5871"></a>
<li>If the argument is <code>0xff80000000000000L</code>, the result will be negative infinity.
<a name="5872"></a>
<li>If the argument is any value in the range <code>0x7ff0000000000001L</code> through <code>0x7fffffffffffffffL</code> or in the range <code>0xfff0000000000001L</code> through <code>0xffffffffffffffffL</code>, the result will be NaN. (All IEEE 754 NaN values are, in effect, lumped together by the Java language into a single value called NaN.)
<a name="5873"></a>
<li>In all other cases, let <i>s</i>, <i>e</i>, and <i>m</i> be three values that can be computed from the argument:
</ul><pre><a name="5913"></a>
int s = ((bits >> 63) == 0) ? 1 : -1;
<a name="5930"></a>int e = (int)((bits >> 52) & 0x7ffL);
<a name="5915"></a>long m = (e == 0) ?
<a name="5916"></a> (bits & 0xfffffffffffffL) << 1 :
<a name="5879"></a> (bits & 0xfffffffffffffL) | 0x10000000000000L;
</pre><a name="47532"></a>
Then the floating-point result equals the value of the mathematical expression
<img src="javalang.doc.anc1.gif">.<img src="javalang.doc.anc49.gif">
<p>
<hr>
<!-- This inserts footnotes--><p>
<a href="index.html">Contents</a> | <a href="javalang.doc8.html">Prev</a> | <a href="javalang.doc10.html">Next</a> | <a href="j.index.doc1.html">Index</a>
<p>
<font size=-1>Java Language Specification (HTML generated by Suzette Pelouch on February 24, 1998)<br>
<i><a href="jcopyright.doc.html">Copyright © 1996 Sun Microsystems, Inc.</a>
All rights reserved</i>
<br>
Please send any comments or corrections to <a href="mailto:doug.kramer@sun.com">doug.kramer@sun.com</a>
</font>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -