TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Why 0.1 + 0.2 == 0.3 is false?

15 点作者 watermel0n将近 11 年前

4 条评论

JackC将近 11 年前
This headline is backwards -- it&#x27;s the opposite of the actual stackoverflow question. The question is why, in the D language, `0.1 + 0.2 == 0.3` is <i>true</i>, when it should be false given the underlying floating point implementation.<p>(Spoiler alert: the answer is that the addition is done at compile time rather than run time.)
dottrap将近 11 年前
Douglas Crockford (JavaScript: The Good Parts) has talked about this problem with binary floating point to do decimal (human) math, on many occasions.<p>Here is one such instance. <a href="http://www.yuiblog.com/blog/2009/03/10/when-you-cant-count-on-your-numbers/" rel="nofollow">http:&#x2F;&#x2F;www.yuiblog.com&#x2F;blog&#x2F;2009&#x2F;03&#x2F;10&#x2F;when-you-cant-count-o...</a><p>He has been on a crusade to introduce a decimal based floating point standard because he believes it is finally time we revisit this decision to use binary floating point.<p>Edit: spelling
sheetjs将近 11 年前
On a side note, Excel is infuriatingly inconsistent: some operations work in a way that .1 + .2 == .3 (for example, try `=0.1+0.2=0.3`) but others fall apart (displayed as a fraction with one digit, 0.3 -&gt; 2&#x2F;7 but 0.1+0.2 -&gt; 1&#x2F;3)
评论 #7830329 未加载
pmoriarty将近 11 年前
In guile[1]:<p><pre><code> % guile guile&gt; (= (+ 0.1 0.2) 0.3) #f </code></pre> [1] - <a href="https://www.gnu.org/software/guile/" rel="nofollow">https:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;guile&#x2F;</a>
评论 #7830187 未加载