擅长:python、mysql、java
<p>Python似乎错了,尽管我不确定这是一个疏忽,或者它有更深的含义。21点的解释似乎合理,但我不明白,为什么他们会给出错误的数字。在</p>
<p>您可以使用<a href="https://en.wikipedia.org/wiki/Logarithm#Power_series" rel="nofollow noreferrer">More efficient series</a>下的公式自己检查。在Mathematica中,你可以用</p>
<pre><code>log2 = 2*Sum[1/i*(1/3)^i, {i, 1, 70, 2}]
(*
79535292197135923776615186805136682215642574454974413288086/
114745171628462663795273979107442710223059517312975273318225
*)
</code></pre>
<p>使用<code>N[log2,30]</code>可以得到正确的数字</p>
^{pr2}$
<p>它支持Wikipedia和W | A的正确性。如果您愿意,您可以对机器精度数字进行相同的计算。在Mathematica中,这通常意味着<code>double</code>。在</p>
<pre><code>logC = Compile[{{z, _Real, 0}},
2.0*Sum[1/i*((z - 1)/(z + 1))^i, {i, 1, 100, 2}]
]
</code></pre>
<p>请注意,这段代码完全编译为普通的迭代,并且不使用一些减少错误的求和方案。所以没有神奇的编译<code>Sum</code>函数。在我的机器上显示:</p>
<pre><code>logC[2]//FullForm
(* 0.6931471805599451` *)
</code></pre>
<p>在你指出的数字范围内都是正确的。这有21点建议的精度</p>
<pre><code>$MachinePrecision
(* 15.9546 *)
</code></pre>
<h2>编辑</h2>
<p>正如在注释和答案中指出的,您在<code>_math.c</code>中看到的值可能是53位表示</p>
<pre><code>digits = RealDigits[log2, 2, 53];
N[FromDigits[digits, 2], 21]
(* 0.693147180559945286227 *)
</code></pre>