JavaScript/双精度浮点数:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
无编辑摘要
 
(未显示同一用户的9个中间版本)
第215行: 第215行:
<math>
<math>
\begin{align}
\begin{align}
V_{\text{max}} = (-1)^0 \times 2^{254 - 127} \times (1.11111111111111111111111)_2 \\
V_{\text{+max}} = (-1)^0 \times 2^{254 - 127} \times (1.11111111111111111111111)_2 \\
= 2^{127} \times \Bigg( 2^0 + \sum_{0}^{23 - 1} 2^{n - 23} \Bigg) \\
= 2^{127} \times \Bigg( 2^0 + \sum_{0}^{23 - 1} 2^{n - 23} \Bigg) \\
= 2^{127} \times (2^0 + (1 - \frac{1}{2^{23}}) )_{10} \\
= 2^{127} \times (2^0 + (1 - \frac{1}{2^{23}}) )_{10} \\
第223行: 第223行:
= 3.4028236692093846346337460743177e+38 \\
= 3.4028236692093846346337460743177e+38 \\
\approx 3.40282E+38 \\
\approx 3.40282E+38 \\
\Rightarrow V_{\text{min}} = (-1)^{1} \times 2^{254 - 127} \times (1.11111111111111111111111)_2 \\
\Rightarrow V_{\text{-min}} = (-1)^{1} \times 2^{254 - 127} \times (1.11111111111111111111111)_2 \\
\approx -3.40282E+38
\approx -3.40282E+38
\end{align}
\end{align}
第276行: 第276行:
\begin{array}{l}
\begin{array}{l}
V = (-1)^S \times M \times b^E \\
V = (-1)^S \times M \times b^E \\
= (-1)^S \times \bigg(\sum_{i = 1}^m d_{m - i} \times b^{-i} \bigg) \times b^{e - (b^{n - 1} - 1)} \\
= (-1)^S \times \bigg({\color{Red}0 \times 2^{0} +} \sum_{i = 1}^m d_{m - i} \times b^{-i} \bigg) \times b^{e - (b^{n - 1} - 1)} \\
\because b = 2 \\
\because b = 2 \\
\therefore V = (-1)^S \times \bigg(\sum_{i = 1}^m d_{m - i} \times 2^{-i} \bigg) \times 2^{e - (2^{n - 1} - 1) {\color{Red} + 1}} \\
\therefore V = (-1)^S \times \bigg(\sum_{i = 1}^m d_{m - i} \times 2^{-i} \bigg) \times 2^{e - (2^{n - 1} - 1) {\color{Red} + 1}} \\
第416行: 第416行:
0.5 \times 2 = 1 & \quad\cdots\quad\text{取整 1 } & \downarrow \end{aligned}</math>
0.5 \times 2 = 1 & \quad\cdots\quad\text{取整 1 } & \downarrow \end{aligned}</math>


精度损失,比如 <math>(0.3)_{10} = (0.0\overline{1}\overline{0}\overline{0}\overline{1})_2</math>。
精度损失,比如 <math>(0.3)_{10} = (0.0\overline{1001})_2</math>。


<math>\begin{align}
<math>\begin{align}
(0.3)_{10} = 0.010011001100110011001 \cdots \\
(0.3)_{10} = 0.010011001100110011001 \cdots \\
= 0.0\overline{1}\overline{0}\overline{0}\overline{1}
= 0.0\overline{1001}
\end{align}</math>
\end{align}</math>


第457行: 第457行:
<math>
<math>
\begin{array}{l}  
\begin{array}{l}  
0.1 = (-1)^0 \times 1.1\overline{0}\overline{0}\overline{1}\overline{1} \times 2^-4 \\
0.1 = (-1)^0 \times 1.1\overline{0011} \times 2^-4 \\
0.2 = (-1)^0 \times 1.1\overline{0}\overline{0}\overline{1}\overline{1} \times 2^-3
0.2 = (-1)^0 \times 1.1\overline{0011} \times 2^-3
\end{array}
\end{array}
</math>
</math>
第466行: 第466行:
<math>
<math>
\begin{array}{l}  
\begin{array}{l}  
0.1 \Rightarrow S = 0, M= 1.1 \overline{0}\overline{0}\overline{1}\overline{1}, E = -4 \\
0.1 \Rightarrow S = 0, M= 1.1 \overline{0011}, E = -4 \\
e = (-4 + 1023)_{10} = (1019)_{10} = (1111111011)_2 \\
e = (-4 + 1023)_{10} = (1019)_{10} = (1111111011)_2 \\
0.2 \Rightarrow S = 0, M= 1.1 \overline{0}\overline{0}\overline{1}\overline{1}, E = -3 \\
0.2 \Rightarrow S = 0, M= 1.1 \overline{0011}, E = -3 \\
e = (-3 + 1023)_{10} = (1020)_{10} = (1111111100)_2
e = (-3 + 1023)_{10} = (1020)_{10} = (1111111100)_2
\end{array}
\end{array}
第490行: 第490行:
<math>
<math>
\begin{array}{r}  
\begin{array}{r}  
0.1 = 1.1\overline{0}\overline{0}\overline{1}\overline{1} * 2^{-4} \\
0.1 = 1.1\overline{0011} * 2^{-4} \\
     = 0.11\overline{0}\overline{0}\overline{1}\overline{1} * 2^{-3} \\
     = 0.11\overline{0011} * 2^{-3} \\
0.2 = 1.1\overline{0}\overline{0}\overline{1}\overline{1} \times 2^{-3}
0.2 = 1.1\overline{0011} \times 2^{-3}
\end{array}
\end{array}
</math>
</math>
第559行: 第559行:
# [https://docs.oracle.com/cd/E19422-01/819-4817/819-4817.pdf oracle 数值计算指南]
# [https://docs.oracle.com/cd/E19422-01/819-4817/819-4817.pdf oracle 数值计算指南]
# [https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html 每位计算机科学家都应该了解的浮点运算]
# [https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html 每位计算机科学家都应该了解的浮点运算]
# [https://devtool.tech/double-type 双精度浮点数内部表示法]
# [https://github.com/evanw/float-toy Float Toy]
# [https://github.com/bartaz/ieee754-visualization ieee754 visualization]