⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chap14.html

📁 Inside the java virtualMachine,深入研究java虚拟机
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<TR><TD VALIGN="TOP">Pi</TD><TD VALIGN="TOP">0 10000000 10010010000111111011011</TD><TD VALIGN="TOP">2</TD></TR>
</TABLE>
<P>An exponent of all zeros indicates the mantissa is denormalized, which means the unstated leading bit is a zero instead of a one. The power of two in this case is the same as the lowest power of two available to a normalized mantissa. For the <FONT FACE="Courier New">float</FONT>, this is -125. This means that normalized mantissas multiplied by two raised to the power of -125 have an exponent field of 00000001, while denormalized mantissas multiplied by two raised to the power of -125 have an exponent field of 00000000.</P>
<P>The allowance for denormalized numbers at the bottom end of the range of exponents supports gradual underflow. If the lowest exponent was instead used to represent a normalized number, underflow to zero would occur for larger numbers. In other words, leaving the lowest exponent for denormalized numbers allows smaller numbers to be represented. The smaller denormalized numbers have fewer bits of precision than normalized numbers, but this is preferable to underflowing to zero as soon as the exponent reaches its minimum normalized value. Table 14-4 shows several denormalized floating-point values.</P>
<P>Table 14-4. <STRONG>Denormalized <FONT FACE="Courier New">float</FONT> values</STRONG></P>
<TABLE WIDTH="500">
<TR><TD VALIGN="TOP"><STRONG>Value</STRONG></TD><TD VALIGN="TOP"><STRONG><FONT FACE="Courier New">float</FONT> bits (sign exponent mantissa)</STRONG></TD></TR>
<TR><TD VALIGN="TOP">Smallest positive (non-zero) <FONT FACE="Courier New">float</FONT></TD><TD VALIGN="TOP">0 00000000 00000000000000000000001</TD></TR>
<TR><TD VALIGN="TOP">Smallest negative (non-zero) <FONT FACE="Courier New">float</FONT></TD><TD VALIGN="TOP">1 00000000 00000000000000000000001</TD></TR>
<TR><TD VALIGN="TOP">Largest denormalized <FONT FACE="Courier New">float</FONT></TD><TD VALIGN="TOP">1 00000000 11111111111111111111111</TD></TR>
<TR><TD VALIGN="TOP">Positive zero</TD><TD VALIGN="TOP">0 00000000 00000000000000000000000</TD></TR>
<TR><TD VALIGN="TOP">Negative zero</TD><TD VALIGN="TOP">1 00000000 00000000000000000000000</TD></TR>
</TABLE>
<I><STRONG><P>Inner Float: A Java float Reveals its Inner Nature</P>
</I><P></STRONG>The applet shown in Figure 14-1 lets you play around with the floating-point format. The value of a <FONT FACE="Courier New">float</FONT> is displayed in several formats. The radix two scientific notation format shows the mantissa and exponent in base ten. Before being displayed, the actual mantissa is multiplied by 2 <SUP>24</SUP>, which yields an integral number, and the unbiased exponent is decremented by 24. Both the integral mantissa and exponent are then easily converted to base ten and displayed. The applet is embedded in a web page on the CD-ROM in file <FONT FACE="Courier New">applets/InnerFloat.html</FONT>. The text of the web page includes several button-press sequences that demonstrate various properties of floating point numbers.</P>
<P><IMG SRC="fig14-1.gif" tppabs="http://www.pbg.mcgraw-hill.com/betabooks/venners/images/fig14-1.gif" ALT="Figure 14-1"></P>

<I><STRONG><P>The Floating Point Opcodes</P>
</I></STRONG><H3><P></H3>Table 14-5 shows the opcodes that pop two floating-point values from the top of the stack, add them, and push the result. The type of the values is indicated by the opcode itself, and the result always has the same type as the numbers being added. No exceptions are thrown by these opcodes. Overflow results in a positive or negative infinity, and underflow results in a positive or negative zero. </P>
<P>Table 14-5. <STRONG>Floating-point addition</P>
</STRONG><TABLE WIDTH="500">
<TR><TD VALIGN="TOP"><STRONG>Opcode</STRONG></TD><TD VALIGN="TOP"><STRONG>Operand(s)</STRONG></TD><TD VALIGN="TOP"><STRONG>Description</STRONG></TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">fadd</FONT></TD><TD VALIGN="TOP">(none)</TD><TD VALIGN="TOP">pops two <FONT FACE="Courier New">float</FONT>s, adds them, and pushes the <FONT FACE="Courier New">float</FONT> result</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">dadd</FONT></TD><TD VALIGN="TOP">(none)</TD><TD VALIGN="TOP">pops two <FONT FACE="Courier New">double</FONT>s, adds them, and pushes the <FONT FACE="Courier New">double</FONT> result</TD></TR>
</TABLE>
<P>Subtraction is performed on <FONT FACE="Courier New">float</FONT>s and <FONT FACE="Courier New">double</FONT>s via the opcodes shown in Table 14-6. Each opcode causes the top two values of the appropriate type to be popped off the stack. The topmost value is subtracted from the value just beneath the topmost value. The result is pushed back onto the stack. No exceptions are thrown by either of these opcodes. </P>
<P>Table 14-6. <STRONG>Floating-point subtraction</P>
</STRONG><TABLE WIDTH="500">
<TR><TD VALIGN="TOP"><STRONG>Opcode</STRONG></TD><TD VALIGN="TOP"><STRONG>Operand(s)</STRONG></TD><TD VALIGN="TOP"><STRONG>Description</STRONG></TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">fsub</FONT></TD><TD VALIGN="TOP">(none)</TD><TD VALIGN="TOP">pops two <FONT FACE="Courier New">float</FONT>s, subtracts them, and pushes the <FONT FACE="Courier New">float</FONT> result</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">dsub</FONT></TD><TD VALIGN="TOP">(none)</TD><TD VALIGN="TOP">pops two <FONT FACE="Courier New">double</FONT>s, subtracts them, and pushes the <FONT FACE="Courier New">double</FONT> result</TD></TR>
</TABLE>
<P>Multiplication of <FONT FACE="Courier New">float</FONT>s and <FONT FACE="Courier New">double</FONT>s is accomplished via the opcodes shown in Table 14-7. Each opcode causes two values of the same type to be popped off the stack and multiplied. The result, of the same type as the numbers being multiplied, is pushed back onto the stack. No exceptions are thrown. </P>
<P>Table 14-7. <STRONG>Floating-point multiplication</P>
</STRONG><TABLE WIDTH="500">
<TR><TD VALIGN="TOP"><STRONG>Opcode</STRONG></TD><TD VALIGN="TOP"><STRONG>Operand(s)</STRONG></TD><TD VALIGN="TOP"><STRONG>Description</STRONG></TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">fmul</FONT></TD><TD VALIGN="TOP">(none)</TD><TD VALIGN="TOP">pops two <FONT FACE="Courier New">float</FONT>s, multiplies them, and pushes the <FONT FACE="Courier New">float</FONT> result</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">dmul</FONT></TD><TD VALIGN="TOP">(none)</TD><TD VALIGN="TOP">pops two <FONT FACE="Courier New">double</FONT>s, multiplies them, and pushes the <FONT FACE="Courier New">double</FONT> result</TD></TR>
</TABLE>
<P>The division is performed on <FONT FACE="Courier New">float</FONT>s and <FONT FACE="Courier New">double</FONT>s by the opcodes shown in Table 14-8. The division opcodes cause the top two values of the appropriate type to be popped off the stack. The value immediately beneath the topmost value is divided by the topmost value. (In other words, the value pushed first is the dividend or numerator. The value pushed second--the top of the stack--is the divisor or denominator.) The result of the division is pushed back onto the stack. </P>
<P>Table 14-8. <STRONG>Floating-point division</P>
</STRONG><TABLE WIDTH="500">
<TR><TD VALIGN="TOP"><STRONG>Opcode</STRONG></TD><TD VALIGN="TOP"><STRONG>Operand(s)</STRONG></TD><TD VALIGN="TOP"><STRONG>Description</STRONG></TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">fdiv</FONT></TD><TD VALIGN="TOP">(none)</TD><TD VALIGN="TOP">pops two <FONT FACE="Courier New">float</FONT>s, divides them, and pushes the <FONT FACE="Courier New">float</FONT> result</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">ddiv</FONT></TD><TD VALIGN="TOP">(none)</TD><TD VALIGN="TOP">pops two <FONT FACE="Courier New">double</FONT>s, divides them, and pushes the <FONT FACE="Courier New">double</FONT> result</TD></TR>
</TABLE>
<P>No exception is thrown as a result of any floating-point division. Floating-point division of a finite value by zero yields a positive or negative infinity. Floating-point division of zero by zero yields NaN. A summary of the result of dividing various combinations of infinity, zero, NaN, and finite values is given in Table 14-10.</P>
<P>The remainder operation is performed on <FONT FACE="Courier New">float</FONT>s and <FONT FACE="Courier New">double</FONT>s via the opcodes shown in Table 14-9. The following opcodes cause the top two values to be popped from the stack. The value just beneath the topmost value is divided by the topmost value, and the remainder of that division is pushed back onto the stack. </P>
<P>Table 14-9. <STRONG>Floating-point remainder</P>
</STRONG><TABLE WIDTH="500">
<TR><TD VALIGN="TOP"><STRONG>Opcode</STRONG></TD><TD VALIGN="TOP"><STRONG>Operand(s)</STRONG></TD><TD VALIGN="TOP"><STRONG>Description</STRONG></TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">frem</FONT></TD><TD VALIGN="TOP">(none)</TD><TD VALIGN="TOP">pops two <FONT FACE="Courier New">float</FONT>s, divides them, and pushes the <FONT FACE="Courier New">float</FONT> remainder</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">drem</FONT></TD><TD VALIGN="TOP">(none)</TD><TD VALIGN="TOP">pops two <FONT FACE="Courier New">double</FONT>s, divides them, and pushes the <FONT FACE="Courier New">double</FONT> remainder</TD></TR>
</TABLE>
<P>No exception is thrown as a result of any floating-point remainder operation. Floating-point remainder of any value divided by zero yields a NaN result. A summary of the result of computing the remainder various combinations of infinity, zero, NaN, and finite values is given in Table 14-10.</P>
<P>Table 14-10. Results of various <STRONG>floating-point divisions</P>
</STRONG><TABLE WIDTH="500">
<TR><TD VALIGN="TOP"><STRONG><FONT FACE="Courier New">a</FONT></STRONG></TD><TD VALIGN="TOP"><STRONG><FONT FACE="Courier New">b</FONT></STRONG></TD><TD VALIGN="TOP"><STRONG><FONT FACE="Courier New">a/b</FONT></STRONG></TD><TD VALIGN="TOP"><STRONG><FONT FACE="Courier New">a%b</FONT></STRONG></TD></TR>
<TR><TD VALIGN="TOP">Finite</TD><TD VALIGN="TOP">+-0.0</TD><TD VALIGN="TOP">+-Infinity</TD><TD VALIGN="TOP">NaN</TD></TR>
<TR><TD VALIGN="TOP">Finite</TD><TD VALIGN="TOP">+-Infinity</TD><TD VALIGN="TOP">+-0.0</TD><TD VALIGN="TOP">a</TD></TR>
<TR><TD VALIGN="TOP">+-0.0</TD><TD VALIGN="TOP">+-0.0</TD><TD VALIGN="TOP">NaN</TD><TD VALIGN="TOP">NaN</TD></TR>
<TR><TD VALIGN="TOP">+-Infinity</TD><TD VALIGN="TOP">Finite</TD><TD VALIGN="TOP">+-Infinity</TD><TD VALIGN="TOP">NaN</TD></TR>
<TR><TD VALIGN="TOP">+-Infinity</TD><TD VALIGN="TOP">+Infinity</TD><TD VALIGN="TOP">NaN</TD><TD VALIGN="TOP">NaN</TD></TR>
</TABLE>
<P>The remainder operation provided by <FONT FACE="Courier New">frem</FONT> and <FONT FACE="Courier New">drem</FONT> follows the same rule as the integer remainder operation provided by <FONT FACE="Courier New">irem</FONT> and <FONT FACE="Courier New">lrem</FONT>:</P>
<PRE><P><FONT FACE="Courier New">begin</FONT></P>
<FONT FACE="Courier New"><P>(a/b)*b + a%b == a</P>
</FONT><P><FONT FACE="Courier New">end</FONT></P></PRE>
<P>In the floating point case, the division <FONT FACE="Courier New">(a/b)</FONT> must be converted to an <FONT FACE="Courier New">int</FONT> or <FONT FACE="Courier New">long</FONT> to remove the fraction, as in:</P>
<PRE><P><FONT FACE="Courier New">begin</FONT></P>
<FONT FACE="Courier New"><P>((long)(a/b))*b + a%b == a</P>
</FONT><P><FONT FACE="Courier New">end</FONT></P></PRE>
<P>This remainder does not follow to the IEEE 754 standard. To obtain a floating point remainder as defined by IEEE 754, use the <FONT FACE="Courier New">IEEEremainder()</FONT> method of <FONT FACE="Courier New">java.lang.Math</FONT>.</P>
<P>The opcodes shown in Table 14-11 perform arithmetic negation on <FONT FACE="Courier New">float</FONT>s and <FONT FACE="Courier New">double</FONT>s. Negation opcodes pop the top value from the stack, negates it, and pushes the result. </P>
<P>Table 14-11. <STRONG>Floating-point negation</P>
</STRONG><TABLE WIDTH="500">

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -