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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Weird compiler bug – Same code, different results

73 点作者 zaitanz超过 4 年前

5 条评论

brucehoult超过 4 年前
If you read the article you find that this is a bug in MinGW64 libraries.<p>It&#x27;s not a compiler bug, it&#x27;s not a problem in C&#x2F;C++, or even in IEEE-754 floating point math. The MinGW64 thread library simply forgot to initialize the FPU correctly.<p>He&#x27;d have had the same problem if he wrote his code in assembly language and then ran it in a MinGW64 thread.
评论 #25964105 未加载
gus_massa超过 4 年前
&gt; <i>This means that floating point arithmetic is non-associative. In that A + B != B + A.</i><p>The equation is the commutative property, not associative. IIRC addition in IEEE-754 is commutative.<p>The property that fails is (A+B)+C = A+(B+C).
评论 #25964071 未加载
lysium超过 4 年前
I would have never thought that the output of some floating point operations depend on the „reset of the floating point package“. What gives?
评论 #25963271 未加载
评论 #25963330 未加载
评论 #25963144 未加载
评论 #25963257 未加载
评论 #25964159 未加载
评论 #25963163 未加载
peter_d_sherman超过 4 年前
&gt;&quot;Compiler bug? But how… Looking at the code, the only things that could create the bug were the operators and pow() call. These are part of the C++ standard offering so it’s highly unlikely that either of these would have an error. What next? Off to GodBolt to try some other compilers to see if I get wonky results on them. MSVC++… nope, Clang… nope, GCC-Trunk on Linux… nope. I am only getting this weird behaviour in TDM-GCC. Time to try some other MingW64 compilers. Nuwen… Yes, Mingw64.. yes, TDM-GCC… yes.<p>Confirmed: It’s a bug in MinGW64.<p>When I create a new thread and run floating point operations in that thread, I get slightly different answers.&quot;<p>Interesting!
titzer超过 4 年前
Do <i>not</i> use C&#x2F;C++ for numerical code where accuracy is needed. These languages are not specified to conform to IEEE 754 and you are absolutely asking for trouble.
评论 #25963206 未加载
评论 #25964154 未加载
评论 #25963676 未加载
评论 #25964094 未加载
评论 #25963300 未加载